A focus group recently met to evaluate a new product your co
A focus group recently met to evaluate a new product your company is thinking about offering. There are 6 people in the group who are rating your product on a scale of 1 to 5. Scores can be entered up to 2 decimal places. You are going to write a program that will read in the scores and determine the average score. Your program will also determine the highest and lowest scores.
Your program should implement functions that perform the following tasks:
Accept the data – function should prompt the user for score. Error checking should validate that it is in the range of 1 to 5. Function should be called for each of the ratings
Determine the highest rating – return the highest rating of the values passed to the function
Determine the lowest rating - return the lowest rating of the values passed to the function
Average the scores – display the average score of he values passed to the function.
Keep the following points in mind when creating your program:
Output should be labeled, aligned, and formatted to 2 decimal places.
Do not use global variables in your program.
Do not use arrays in your code.
Make sure you are using the correct data types and descriptive variable names.
Add a comment to the top of your program that includes your name, the program name, and a description of the program code.
Include descriptive comments throughout your program.
Test your calculations!
Solution
#include <iostream>
#include<iomanip>
using namespace std;
double acceptdata() //function to enter and validate data
{
double rating;
cout<<\"\ Enter rating of product on a scale of 1 to 5\";
cin>>rating;
if(rating < 1 || rating > 5)
cout<<\"\ Error: Please enter rating in the range 1 to 5\";
else
return rating;
}
double highestRating(double r1,double r2,double r3,double r4,double r5,double r6) // calculate highest rating
{
double max =0;
if(max < r1) max = r1;
if(max < r2) max = r1;
if(max < r3) max = r3;
if(max < r4) max = r4;
if(max < r5) max = r5;
if(max < r6) max = r6;
return max;
}
double lowestRating(double r1,double r2,double r3,double r4,double r5,double r6)//calculate lowest rating
{
double min = 6;
if(min > r1) min = r1;
if(min > r2) min = r1;
if(min > r3) min = r3;
if(min > r4) min = r4;
if(min > r5) min = r5;
if(min > r6) min = r6;
return min;
}
double averageScore(double r1,double r2,double r3,double r4,double r5,double r6)//calculate average rating
{
double sum;
sum = r1+r2+r3+r4+r5+r6;
return sum/6;
}
int main()
{
double rating1,rating2,rating3,rating4,rating5,rating6,avg,highest,lowest;
rating1 = acceptdata();
rating2 = acceptdata();
rating3 = acceptdata();
rating4 = acceptdata();
rating5 = acceptdata();
rating6 = acceptdata();
avg = averageScore(rating1,rating2,rating3,rating4,rating5,rating6);
highest = highestRating(rating1,rating2,rating3,rating4,rating5,rating6);
lowest = lowestRating(rating1,rating2,rating3,rating4,rating5,rating6);
cout<<fixed<<setprecision(2);
cout<<\"\ Average Rating Score : \"<<avg;
cout<<\"\ Highest Rating : \"<<highest;
cout<<\"\ Lowest Rating : \"<<lowest;
return 0;
}
output:

