C++:Write a complete program that repeatedly asks the user to enter pairs of double-type numbers until at least one of the pair is 0. For each pair, the program should use a function to calculate the harmonic mean of the numbers. This function should use both calling-by-value and calling-by reference methods when passing parameters (i.e. some parameters called by value and others called by reference), and the type of this function should be void. All the input and output processes should be in main() function. The harmonic mean of the numbers is the inverse of the average of the inverses and can be calculated as follows:
ℎ??????? ???? = 2?? /(? + y)
#include <iostream> using namespace std; void harmonic_mean(double x, double y, double &hm) { hm = (2 * x * y) / (x + y); } int main() { double x, y, hm; while (true) { cout << "Enter two numbers(0 for either to exit): "; cin >> x >> y; if (x == 0 || y == 0) { break; } harmonic_mean(x, y, hm); cout << "Harmonic mean of " << x << " and " << y << " is " << hm << endl << endl; } return 0; }
Get Answers For Free
Most questions answered within 1 hours.