Presentation is loading. Please wait.

Presentation is loading. Please wait.

Homework #1: C++ Basics, Flow of Control, and Function Basics

Similar presentations


Presentation on theme: "Homework #1: C++ Basics, Flow of Control, and Function Basics"— Presentation transcript:

1 Homework #1: C++ Basics, Flow of Control, and Function Basics
By J. H. Wang Mar. 13, 2015

2 Programming Exercises
Write a C++ program that allows the user to repeatedly enter integers until she inputs a 0 (zero). Then, your program should do the following: (a) count the number of positive values and the number of negative values in user input; (b) calculate the sum and average of the numbers; [Note: Do not count the ending input 0 in the result.] [Note: Please do not use arrays because you don’t need them in this exercise.]

3 Programming Exercises
A formula for calculating annual compound interest is: F=P(1+r)n where P is the present value, r is the interest rate per year, n is the number of years. Write a C++ program that asks the user to input integers n and P, a double r between 0 and 1, and computes the future value of F. [Note: Please do not use the predefined math functions such as pow().]

4 One way to estimate the height of a child is to use the following formula, which uses the height of the parents: Hmale_child=((Hmother13/12)+Hfather)/2 Hfemale_child=((Hfather12/13)+Hmother)/2 All heights are in inches. Write a function that takes as input parameters the gender of the child, height of the mother in inches, and height of the father in inches, and outputs the estimated height of the child in inches. Embed your function in a C++ program that allows you to test the function over and over again until telling the program to exit. The user should be able to input the heights in feet and inches, and the program should output the estimated height of the child in feet and inches. Use the integer data type to store the heights.

5 Homework Submission Due: 2 weeks (Mar. 27, 2015)
Submission instructions: Homework submission Web site at: Account: At your first login, please use your student ID as the account and password. Remember to change the password as soon as possible for better security. File names: Please name your file according to our homework. For example, [id]_HW1.zip or [id]_quiz2.rar.

6 Thanks for Your Attention!


Download ppt "Homework #1: C++ Basics, Flow of Control, and Function Basics"

Similar presentations


Ads by Google