Question
In this lab, you complete a partially prewritten C++ program that uses an array. The program prompts the user to interactively enter eight batting averages,
In this lab, you complete a partially prewritten C++ program that uses an array. The program prompts the user to interactively enter eight batting averages, which the program stores in an array. The program should then find the minimum and maximum batting average stored in the array as well as the average of the eight batting averages. The data file provided for this lab includes the input statement and some variable declarations. Comments are included in the file to help you write the remainder of the program. Instructions Ensure the source code file named BattingAverage.cpp is open in the code editor. Write the C++ statements as indicated by the comments. Execute the program by clicking the Run button. Enter the following batting averages: .299, .157, .242, .203, .198, .333, .270, .190. The minimum batting average should be .157, and the maximum batting average should be .333. The average should be .2365.
Program produces correct batting averages
2
0 out of 2 checks passed. Review the results below for more details.
Checks
Test CaseIncomplete
Output Test 1
Input
.299 .157 .242 .203 .198 .333 0.270 0.190
Output
Enter batting average.299 Enter batting average.157 Enter batting average.242 Enter batting average.203 Enter batting average.198 Enter batting average.333 Enter batting average0.270 Enter batting average0.190 Entered batting averages are 0.299 0.157 0.242 0.203 0.198 0.333 0.27 0.19 Sum is 1.892 Average is 0.2365 Maximum batting average is 0.333 Minimum batting average is 0.157
Results
Minimum batting average is 0.157
Maximum batting average is 0.333
Average batting average is 0.236
Show DetailsTest CaseIncomplete
Output Test 2
Input
.300 .333 .290 .157 .300 .270 .269 .242
Output
Enter batting average.300 Enter batting average.333 Enter batting average.290 Enter batting average.157 Enter batting average.300 Enter batting average.270 Enter batting average.269 Enter batting average.242 Entered batting averages are 0.3 0.333 0.29 0.157 0.3 0.27 0.269 0.242 Sum is 2.161 Average is 0.270125 Maximum batting average is 0.333 Minimum batting average is 0.157
Results
Minimum batting average is 0.157
Maximum batting average is 0.333
Average batting average is 0.270
BattingAverage.cpp:
#include
#include
using namespace std;
int main()
{
//Float array
float batting_averages[8];
int i;
float min,max;
float sum=0.0;
for (i=0;i<8;i++)
{
cout<<"Enter batting average";
cin>>batting_averages[i];
}
cout<<"Entered batting averages are"< for (i=0;i<8;i++) { cout< cout< sum=sum+batting_averages[i]; } cout< cout<<"Sum is "< cout<<"Average is "< //Assume that first element of array is Maximum max=batting_averages[0]; //Assume that first element of array is Minimum min=batting_averages[0]; for (i=1;i<8;i++) { if (max { //larger value will be assigned in max max=batting_averages[i]; } if (min>batting_averages[i]) { //Smaller value will be assigned in min min=batting_averages[i]; } } cout<<" Maximum batting average is "< cout< cout<<" Minimum batting average is "< return 0; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started