O'Reilly logo

C++ Primer Plus, Fourth Edition by Stephen Prata

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Programming Exercises

1:Write a program that repeatedly asks you to enter pairs of numbers until at least one of the pair is zero. For each pair, the program should use a function to calculate the harmonic mean of the numbers. The function should return the answer to main(), which reports the result. The harmonic mean of the numbers is the inverse of the average of the inverses and can be calculated as follows:

harmonic mean = 2.0 * x * y / (x + y)

2:Write a program that asks you to enter up to ten golf scores, which are to be stored in an array. You should provide a means for the user to terminate input prior to entering ten scores. The program should display all the scores on one line and report the average score. Handle input, display, and ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required