Download presentation
Published byCecily Hawkins Modified over 9 years ago
1
Homework Assignment #3 J. H. Wang Apr. 19, 2007
2
Homework Assignment #3 Chap. 3 Chap. 4 Deadline:
Exercise 3.1: 1, 3 (p.104) Exercise 3.2: 1, Prog. 2 (p.111) Exercise 3.3: 2 (p.114) Exercise 3.5: Prog. 2 (p.136) Programming Projects: Prog. 10 (p.143) Chap. 4 Exercise 4.2: 2, 4 (p.157) Exercise 4.3: 2 (p.162) Exercise 4.4: Prog. 2 (p.166) Exercise 4.7: 3 (p.189) Exercise 4.8: Prog. 1 (p.195) Deadline: Two weeks
3
Details Exercise 3.1: 1, 3 (p.104) 1. Describe the problem inputs and outputs and write the algorithm for a program that computes an employee’s gross salary given the hours worked and the hourly rate. 3. In computing gross salary, what changes should you make to extend the payroll algorithm in Self-Check Exercise 1 to include overtime hours to be paid at 1.5 times an employee’s normal hourly rate? Assume that overtime hours are entered separately.
4
Exercise 3.2: 1, Prog. 2 (p.111) 1. Rewrite the following mathematical expressions using C functions: a. b. c. d. Prog. 2. Write a complete C program that prompts the user for the Cartesian coordinates of two points (x1, y1) and (x2, y2) and displays the distance between them computed using the formula:
5
Exercise 3.3: 2 (p.114) 2. Draw the structure chart for the problem of drawing the house shown in Fig.3.9.
6
Exercise 3.5: Prog. 2 (p.136) Prog. 2. Write a function that computes the speed (km/h) one must average to reach a certain destination by a designated time. You need to deal only with arrivals occurring later on the same day as the departure. Function inputs include departure and arrival times as integers on a 24-hour clock (8:30P.M. = 2030) and the distance to the destination in kilometers. Also write a driver program to test your function.
7
Programming Projects: Prog. 10 (p.143)
10. Write a program to take a depth (in kilometers) inside the earth as input data; compute and display the temperature at this depth in degrees Celsius and degrees Fahrenheit. The relevant formulas are Celsius = 10 (depth) + 20 (Celsius temperature at depth in km) Fahrenheit = 1.8 (Celsius) + 32 Include two functions in your program. Function celsius_at_depth should compute and return the Celsius temperature at a depth measured in kilometers. Function fahrenheit should convert a Celsius temperature to Fahrenheit.
8
Exercise 4.2: 2, 4 (p.157) 2. Evaluate each of the following expressions if a is 5, b is 10, c is 15, and flag is 1. Which parts of these expressions are not evaluated due to short-circuit evaluation? a. c == a+b || !flag b. a != 7 && flag || c>=6 c. !(b<=12) && a%2 ==0 d. !(a>5 || c<a+b) 4. Complement each expression in Exercise 2. Use DeMorgan’s theorem if applicable.
9
Exercise 4.3: 2 (p.162) 2. What value is assigned to x when y is 15.0?
a. x = 25.0; if (y != (x-10.0)) x = x-10.0; else x = x/2.0; b. if (y<15.0) if (y>=0.0) x = 5*y; else x = 2*y; else x = 3*y; c. if (y<15.0 && y>=0.0) x = 5*y;
10
Exercise 4.4: Prog. 2 (p.166) 2. Write an interactive program that contains an if statement that may be used to compute the area of a square (area=side2) or a triangle (area=1/2*base*height) after prompting the user to type the first character of the figure name (S or T).
11
Exercise 4.7: 3 (p.189) 3. Write as nested if statement for the decision diagrammed in the accompanying flowchart. Use a multiple-alternative if for intermediate decisions where possible. false true pH>7 true true pH is 7 pH<12 false “Neutral" false pH>2 “Alkaline" true false “Very alkaline" “Acidic" “Very acidic"
12
Exercise 4.8: Prog. 1 (p.195) Write a switch statement that assigns to the variable lumens the expected brightness of a standard light bulb whose wattage has been stored in watts. Use this table: (Assign -1 to lumens if the value of watts is not in the table.) Watts Brightness (in Lumens) 15 125 25 215 40 500 60 880 75 1000 100 1675
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.