Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

c++ 13.7 \"Gentle\" exercise 9.2 The root mean square is a specific kind of aver

ID: 3936752 • Letter: C

Question

c++ 13.7 "Gentle" exercise 9.2 The root mean square is a specific kind of average which is used for various purposes. It is given by the formula shown here. This means that a sequence of values is squared and summed, then divided by the count of the values; the entire calculation is then square-rooted. Ask the user for input; stop when the user enters -1. Be sure to use the square and squareRoot functions you used in "Gentle" exercise 9.1. Here is a sample run: Enter a positive number: 1 Enter a positive number: 2 Enter a positive number: 3 Enter a positive number: 4 Enter a positive number: 5 Enter a positive number: -1 The root mean square is 3.31662 c++

Explanation / Answer

Program To find Root Mean Square in C++:

#include <iostream>
#include <cmath>
using namespace std;
int main()
{
double posNum = 0, posPow = 0, sum = 0, newVal, div, end1;
int counter = 0;
while (posNum >= 0)
{
cout <<"enter a positive number (-1 to exit) : ";
cin >> posNum;
if(posNum >= 0)
{
counter++;
posPow = pow (posNum, 2);
sum = posPow + sum;
}
}
if (sum <= 0)
{
cout << "NO data" << end1;
}
else
{
div = sum / counter;
newVal = sqrt(div);
cout << "The Root mean Square is:";
cout << newVal << end1;
}
}

Sample Out Put:

enter a positive number (-1 to exit) : 1

enter a positive number (-1 to exit) : 2

enter a positive number (-1 to exit) : 3

enter a positive number (-1 to exit) : 4

enter a positive number (-1 to exit) : 5

enter a positive number (-1 to exit) : -1

The Root mean Square is:3.316620

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote