Question

In: Computer Science

in c++ Write a program that can calculate the arithmetic mean, the geometric mean, and the...

in c++ Write a program that can calculate the arithmetic mean, the geometric mean, and the harmonic mean of a set of five numbers. •The program should ask the user to enter fiver numbers, calculate the means, and print all the data to a text file. The program should output the expected results.•Example: The text file should read: For the set of numbers {1,2,3}. The arithmetic mean is 2, the geometric mean is about 1.82, and the harmonic mean is about 1.64•The screen should display: Expected: arithmetic mean: 2, geometric mean 1.82, harmonic mean 1.64

Solutions

Expert Solution

Here is the answer for your question in C++ Programming Language.

Kindly upvote if you find the answer helpful.

#######################################################################

CODE :

#include<iostream>
#include<fstream>
#include<cmath>
#include<iomanip>

using namespace std;

int main(){
   //Required variables
   int numbers[5],i=0;  
   double arithmeticMean = 0,geometricMean = 1,harmonicMean = 0;
  
   //create output file object and create and open your own file
   ofstream outFile;
   outFile.open("meansOfNumbers.txt");
  
   //Read five numbers from user
   cout << "Please enter 5 numbers: ";
   for(int i=0;i<5;i++){
       cin >> numbers[i];
      
       //add,multiply and sum up inverses of each number to respected means
       arithmeticMean += numbers[i];
       geometricMean *= numbers[i];
       harmonicMean += pow(numbers[i],-1);
   }  
  
   //Calculate means  
   arithmeticMean = arithmeticMean/5;
   geometricMean = pow(geometricMean,0.2);
   harmonicMean = 5/harmonicMean;
  
   //Write output to text file
   outFile << "For the set of numbers {";
   for(int i=0;i<5;i++){
       if(i == 4)
           outFile << numbers[i] << "}" << endl;
       else
           outFile << numbers[i] << ", ";
   }
   outFile << "The arithmetic mean is " << fixed << setprecision(2) << arithmeticMean << endl;
   outFile << "The geometric mean is about " << geometricMean << endl;
   outFile << "The harmonic mean is about " << harmonicMean << endl;
  
   //Print output to console
   cout << "Expected : Arithmetic mean : " << fixed << setprecision(2) << arithmeticMean << ",";
   cout << "Geometric mean : " << geometricMean << ",";
   cout << "Harmonic mean : " << harmonicMean << endl;  

}

###################################################################

SCREENSHOTS :

Please see the screenshots of the code below for the indentations of the code.

###################################################################

OUTPUT :

Text File output

Any doubts regarding this can be explained with pleasure :)


Related Solutions

Write short notes on Harmonic Mean, Arithmetic Mean, Geometric Mean, Median, Mode, Range, Standard Deviation, Interquartile...
Write short notes on Harmonic Mean, Arithmetic Mean, Geometric Mean, Median, Mode, Range, Standard Deviation, Interquartile Deviation, Skewness, Kurtosis and using practical examples, explain how these measures are useful in the field of Business Administration. (10marks)
How are various types of mean like Arithmetic mean, Geometric mean, and Harmonic mean different?
How are various types of mean like Arithmetic mean, Geometric mean, and Harmonic mean different? How are they calculated?
Which of the following best describes the differences between the arithmetic mean and geometric mean growth...
 Which of the following best describes the differences between the arithmetic mean and geometric mean growth rates? The procedures used to calculate the geometric mean growth rate and arithmetic mean growth rate are somewhat different, but produce the same result. The geometric mean growth rate calculation takes into account changes in the basis, while the arithmetic mean growth rate does not. The arithmetic mean growth rate is preferable to the geometric mean growth rate when calculating rates of return based on changes in stock...
: In this assignment you will write a C++ program that evaluates an arithmetic expression (represented...
: In this assignment you will write a C++ program that evaluates an arithmetic expression (represented with an infix notation), then outputs this expression in prefix form and also outputs the result of the calculation. The program will first convert the input infix expression to a prefix expression (using the Stack ADT) and then calculate the result (again, using the Stack ADT). The details are provided in the following sections.
In C++ Write a program that will conduct a quiz consists of 10 arithmetic questions and...
In C++ Write a program that will conduct a quiz consists of 10 arithmetic questions and display the final score as ‘Your score in the quiz is X’ with a response message in the next line. A response message will be as follows based on the student’s performance: a. Number of correct answers >= 9: Excellent, your are passed with ‘A’ grade! b. Number of correct answers >= 7, but less than 9: Very Good, you are passed with ‘B’...
C++ Write a program that can be used to calculate the federal tax. The tax is...
C++ Write a program that can be used to calculate the federal tax. The tax is calculated as follows: for single people, the standard exemption is $4,000; for married people, the standard exemption is $7,000. A person can also put up to 6% of his or her gross income in a pension plan. the tax rates are as follows: if the taxable income is: Between $0 and $15,000, the tax rate is 15%. Between $15,001 and 40,000 the tax rate...
Show what relation exists between arithmetic mean, A, Geometric mean, G and Harmonic mean, H?
Show what relation exists between arithmetic mean, A, Geometric mean, G and Harmonic mean, H?
Calculate annual arithmetic rate of return and annual geometric rate of return of stock A and...
Calculate annual arithmetic rate of return and annual geometric rate of return of stock A and B. Consider the data in table below, which show the movements in price for two stocks over two successive holding periods. Both stocks have a beginning price of $10. Stock A rises to $40 in period 1 and then declines to $30 in period 2. Stock B falls to $8 in period 1 and then rises to $25 in period 2.
Write a program using the switch statement to calculate geometric quantities. Prompt the user to enter...
Write a program using the switch statement to calculate geometric quantities. Prompt the user to enter a radius. Then present a menu of choices for quantities to be calculated from that radius:                         A         Area of a Circle                         C         Circumference of a Circle                         S          Surface Area of a Sphere                         V         Volume of a Sphere Prompt the user to enter the character corresponding to the quantity to be calculated. Use a switch statement to handle the calculations. Use...
Using the following returns, calculate the arithmetic average returns, the standard deviations, and the geometric average...
Using the following returns, calculate the arithmetic average returns, the standard deviations, and the geometric average returns for the stock A, B, and C. Assume the returns of stocks are normally distributed. If Mr. Wong owns a stock C, based on the historical return data, there is only a 2.5 percent chance that the stock C will produce a return less than _____ percent in any one year.   If Mr. Wong owns a stock B, which range of returns would...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT