Develop a C++ program to provide information regarding a recent downhill ski com
ID: 3708527 • Letter: D
Question
Develop a C++ program to provide information regarding a recent downhill ski competition. Have the user enter the full names and times of the skiers and determine the fasted speed (lowest time), average speed, look up a skier’s time, and display the skiers’ names and times.
Name
Time
Leela Neela
2.03
Sarah Hara
2.40
Anna Banana
1.85
Keesha Fleesha
1.90
Heidi Mighty
2.50
Requirements:
In main, define two parallel arrays and have the user enter the skiers’ names and times, and store them in two parallel arrays (validate that the times are greater than zero).
Do NOT use global variables. The arrays must be passed to all appropriate functions as arguments and used in the functions to produce the results.
Variable names must be descriptive and initialized where required.
Create a menu to ask the user if they want to:
Determine the fastest skier
Calculate the average time
Find the time of a skier
Display the skiers and their times
Quit the program
Display the menu repeatedly in main and have functions for each of the first four menu items.
The four functions will be:
Determine and display the fastest skier and her time
Calculate and display the skiers’ average time
Find a skier: have the user enter a skier’s full name in this function, then search for the skier, and display her name and associated time; if the user enters a name that is not in the array, display a message to let the user know the name is not in the list.
Display all the skiers and their times
Output must be labeled and easy to read.
Arrays must be processed using loops.
Earn 5 extra credit points by assigning back to main, using reference variables, the name and time from function Find_Fastest, and the average from function Calc_Average, and displaying the values in main instead of in the functions.
Submit:
Your .cpp file
Screen shots of your output (execute all 5 menu options)
Name
Time
Leela Neela
2.03
Sarah Hara
2.40
Anna Banana
1.85
Keesha Fleesha
1.90
Heidi Mighty
2.50
Explanation / Answer
#include <iostream>
#include <iomanip>
#include<string>
using namespace std;
void Find_Fastest(string[],double[],int,string &);
void Calc_Average(double[],int,double &);
void find_time(string[],double[],int);
void display_skiers(string[],double[],int);
int main()
{
int numberOfSkiers = 5;
string skiersName[numberOfSkiers];
double skiersTime[numberOfSkiers];
double time;
for(int i=0; i<numberOfSkiers; i++)
{
cout<<"Enter name "<<(i+1)<<": ";
getline(cin,skiersName[i]);
cout<<"Enter time: ";
cin>>time;
while(time<=0)
{
cout<<"Enter time: ";
cin>>time;
}
skiersTime[i]=time;
cin.clear();
cin.ignore();
cout<<endl;
}
while(true)
{
cout<<" MENU"<<endl;
cout<<"1. Determine the fastest skier"<<endl;
cout<<"2. Calculate the average time"<<endl;
cout<<"3. Find the time of a skier"<<endl;
cout<<"4. Display the skiers and their times"<<endl;
cout<<"5. Quit"<<endl;
int option;
cout<<"Enter option: ";
cin>>option;
string fastest_skier="";
double average=0;
switch(option)
{
case 1:
Find_Fastest(skiersName,skiersTime,numberOfSkiers,fastest_skier);
cout<<"Fastest Skier: "<<fastest_skier<<endl;
break;
case 2:
Calc_Average(skiersTime,numberOfSkiers,average);
cout<<"Average Time: "<<average<<endl;
break;
case 3:
find_time(skiersName,skiersTime,numberOfSkiers);
break;
case 4:
display_skiers(skiersName,skiersTime,numberOfSkiers);
break;
case 5:
cout<<"Exit Program!"<<endl;
return 0;
break;
default:
cout<<"Invalid option!"<<endl;
break;
}
}
return 0;
}
void Find_Fastest(string skiersName[],double skiersTime[],int numberOfSkiers,string &fastest_skier)
{
double fastest_time = skiersTime[0];
for(int i =1 ; i<numberOfSkiers; i++)
{
if(fastest_time>skiersTime[i])
{
fastest_time = skiersTime[i];
fastest_skier = skiersName[i];
}
}
}
void Calc_Average(double skiersTime[],int numberOfSkiers,double &average)
{
for(int i =0 ; i<numberOfSkiers; i++)
{
average += skiersTime[i];
}
average=average/numberOfSkiers;
}
void find_time(string skiersName[],double skiersTime[],int numberOfSkiers)
{
cin.clear();
cin.ignore();
string skier_name;
cout<<"Enter skier name: ";
getline(cin,skier_name);
for(int i =0 ; i<numberOfSkiers; i++)
{
if(skiersName[i]==skier_name)
{
cout<<"Skier Name: "<<skiersName[i]<<endl;
cout<<"Skier Time: "<<skiersTime[i]<<endl;
return;
}
}
cout<<"Skier name doesn't exists."<<endl;
}
void display_skiers(string skiersName[],double skiersTime[],int numberOfSkiers)
{
cout<<left<<setw(20)<<"Skier Name"<<"Skier Time"<<endl;
cout<<"-------------------------"<<endl;
for(int i =0 ; i<numberOfSkiers; i++)
{
cout<<left<<setw(20)<<skiersName[i]<<skiersTime[i]<<endl;
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.