lld viewing the Labl1-1.cpp file, w llg on your C++ development tool, you may ne
ID: 3919515 • Letter: L
Question
lld viewing the Labl1-1.cpp file, w llg on your C++ development tool, you may need to open iect/solution file first.) Run the program. The total company sales are HapllLabl1-1 Project folder or the Cpp81Chap which is ll-1's the program so that it displays the total domestic sales, total interna l company sales. Save and then run the program. es are $643900 and tota Now modify the program so that month numbers from 1 through a it also displays the total sales made in each month. Use 6. Save and then run the program. LAB 11-2 Plan and Create In this lab, you will plan and create an algorithm for the problem specification shown in Figure 11-46. 0° Problem specification Chris Kaplan runs five 5K races each year. Create a program that allows him to enter his finish time for each race. The program should then display both his average and lowest times. Store the five times in a one-dimensional array named finishTimes. Use two value-returning functions named getAverage and getLowest. Pass the array and the number of elements to each function. Display the average and lowest times with one decimal place. Problem specification for Lab 11-2 gure 11-46Explanation / Answer
PROGRAM
#include<iostream>
#include<iomanip>
using namespace std;
// function prototypes
double getAverage(double times[],int numElements);
double getLowest(double times[],int numElements);
int main()
{
double finishTimes[5]={0.0}; // declare constant double array finishTimes
// declare constant double variables
double avgTime=0.0;
double lowestTime=0.0;
// enter finish times
for(int i=0;i<5;i++) // create for loop until 5
{
cout<<"Time for race "<<i+1<<": ";
cin>>finishTimes[i]; // read 5 times
}
avgTime=getAverage(finishTimes,5); // calling getAverage() function and receive return value into avgTime
lowestTime=getLowest(finishTimes,5); // calling getLowest() function and receive return value into lowestTime
cout<<fixed<<setprecision(1)<<endl; // setprecision() function for set decimal 1
// display average Time and lowest time
cout<<"Average 5K finish time: "<<avgTime<<endl;
cout<<"Lowest 5K finish time: "<<lowestTime<<endl;
return 0;
}
// implement getAverage() function
double getAverage(double times[],int numElements)
{
double total=0.0; // declare constant double variable total
for(int i=0;i<numElements;i++) // create for loop until numElements
total+=times[i]; // calculate sum of elements
return total/numElements; // calculate average and return this value
}
// implement getLowest() function
double getLowest(double times[],int numElements)
{
double lowest=times[0]; // declare constant double variable lowest
for(int i=0;i<numElements;i++) // create for loop until numElements
{
if(times[i]<lowest) // check condition lowest value
lowest=times[i]; // the condition is true then store lowest until numElements
}
return lowest; // return resultant value lowest
}
OUTPUT-1
Time for race 1: 14.58
Time for race 2: 23
Time for race 3: 4.85
Time for race 4: 25.98
Time for race 5: 13.25
Average 5K finish time: 16.3
Lowest 5K finish time: 4.8
OUTPUT-2
Time for race 1: 5.25
Time for race 2: 14.98
Time for race 3: 7.29
Time for race 4: 9.66
Time for race 5: 8.25
Average 5K finish time: 9.1
Lowest 5K finish time: 5.2
OUTPUT-3
Time for race 1: 12.29
Time for race 2: 14.96
Time for race 3: 9.78
Time for race 4: 17.26
Time for race 5: 19.65
Average 5K finish time: 14.8
Lowest 5K finish time: 9.8
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.