Transcript HW#1

Homework #1:
C++ Basics, Flow of Control, and
Function Basics
By J. H. Wang
Mar. 10, 2014
Programming Exercises
1. 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 odd values and the
number of even 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.]
Programming Exercises
2. 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().]
3.
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.
Homework Submission
• Due: 2 weeks (Mar. 24, 2014)
• Submission instructions:
– Homework submission Web site at:
http://mslin.ee.ntut.edu.tw/
– Account: Please use your student ID as the
username and password to login the Web site.
– File names: Please name your file according
to our homework. For example, [id]_HW1.zip
or [id]_quiz2.rar.
Thanks for Your Attention!