Presentation is loading. Please wait.

Presentation is loading. Please wait.

Homework Assignment #3 J. H. Wang Oct. 29, 2007.

Similar presentations


Presentation on theme: "Homework Assignment #3 J. H. Wang Oct. 29, 2007."— Presentation transcript:

1 Homework Assignment #3 J. H. Wang Oct. 29, 2007

2 Homework Assignment #3 Chap. 3 Chap. 4 Deadline:
Exercise 3.2: 1, Prog. 2 (p.111) Exercise 3.5: Prog. 2 (p.136) Review Questions: 4 (p.140) Programming Projects: Prog. 4, 12 (p.141, 144) Chap. 4 Exercise 4.2: 2, 4 (p.157) Exercise 4.4: Prog. 1 (p.166) Exercise 4.7: 3 (p.189) Programming Projects: Prog. 6, 7 (p.205) Deadline: Two weeks (Due: Nov. 12, 2007)

3 Details 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:

4 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.

5 Review Questions: 4 (p.140) 4. What are the three advantages of using functions?

6 Programming Projects: Prog. 4, 12 (p.141, 144)
4. Write a computer program that computes the duration of a projectile’s flight and its height above the ground when it reaches the target. As part of your solution, write and call a function that displays instructions to the program user. Try your program on the data sets.

7 Prog.12: Write a program that calculates the speed of sound (a) in air of a given temperature T (°F). Use the formula: Be sure your program does not lose the fractional part of the quotient in the formula shown. As part of your solution, write and call a function that displays instructions to the program user.

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.4: Prog. 1 (p.166) 2. Write an if statement that might be used to compute and display the average of a set of n numbers whose sum is stored in variable total. This average should be found only if n is greater than 0; otherwise, an error message should be displayed.

10 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"

11 Programming Projects: 6, 7 (p. 205)
6. Write a program that takes the x-y coordinates of a point in the Cartesian plane and prints a message telling either an axis on which the point lies or the quadrant in which it is found. Sample lines of output: (-1.0, -2.5) is in quadrant III (0.0, 4.8) is on the y axis

12 7. Write a program that determines the day number (1 to 366) in a year for a date that is provided as input data. As an example, January 1, 1994, is day 1. December 31, 1993, is day 365. December 31, 1996, is day 366, since 1996 is a leap year. A year is a leap year if it is divisible by four, except that any year divisible by 100 is a leap year only if it is divisible by 400. Your program should accept the month, day, and year as integers. Include a function leap() that returns 1 if called with a leap year, 0 otherwise.


Download ppt "Homework Assignment #3 J. H. Wang Oct. 29, 2007."

Similar presentations


Ads by Google