You are an engineer for a pipeline company and you need to calibrate the “meter”
ID: 3690699 • Letter: Y
Question
You are an engineer for a pipeline company and you need to calibrate the “meter” that tracks how much fluid is flowing through the apparatus that “counts” the amount of fluid flowed to bill the customer. You need to assess how much variation there is in the day to day readings. You have the following data. Week1: 56.7 55.3 57.8 57.5 57.1 56.8 57 Week2: 55 57.3 58.9 58.2 58.4 56.3 56.8 You must write a C++ program that uses the array data structure. Prompt the user for the data; build your program for use today and the future. As such, when a negative number is entered, stop taking data. Also, reject any data that is an integer. (Only accept positive real (double) numbers. Calculate the average for week one and week two. Highlight with a **any data that is below the average. Output to the user the: the average of each week all of the data for the week with the below average #’s highlighted (with an **)
Bonus Round: + 10 Points: Extra Credit for reading in a data file vs. manual entry.
Explanation / Answer
#include <iostream>
#include <string>
using namespace std;
int main()
{
double first[7],second[7],r,avg1=0,avg2=0;
cout << "Enter first weeks reading" << endl;
for(int i=0;i<7;i++){
cin >> r;
if(r<0){
while(r<0){
cout << "Negative values are not allowed, try again" << endl;
cin >> r;
}
}
first[i]=r;
avg1 = avg1 + r;
}
avg1 = avg1/7;
cout << "Enter second weeks reading" << endl;
for(int i=0;i<7;i++){
cin >> r;
if(r<0){
while(r<0){
cout << "Negative values are not allowed, try again" << endl;
cin >> r;
}
}
second[i]=r;
avg2 = avg2 + r;
}
avg2 = avg2/7;
cout << "First weeks average : " << avg1 << endl;
cout << "Second weeks average : " << avg2 << endl;
cout << "First weeks data : " << endl;
for(int i=0;i<7;i++){
double d = avg1 - first[i];
string s = d>0 ? "**" : "" ;
cout << s << first[i] << " " << flush;
}
cout << endl;
cout << "Second weeks data : " << endl;
for(int i=0;i<7;i++){
double d = avg1 - second[i];
string s = d>0 ? "**" : "" ;
cout << s << second[i] << " " << flush;
}
cout << endl;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.