(C++) The CSIT Racing Club is a group that runs amateur car racing events throughout the US. In This project, write a program that will help the club determine the winner of their Fall Rally Race. You will need to determine each racer’s average time and identify the first place finisher. An input file with race information contains records of all the laps run by each driver. The record for each driver includes the number of the car the driver races and times for each of 8 laps run during the race.
For the record of each driver, your program should determine the average lap time based on the following rules:
a. Each driver’s slowest two lap times are discarded before the average is calculated
b. Any driver that has a lap time that is recorded as a negative number means that the driver incurred a penalty and is disqualified from the race (so no average needs to be calculated).
Your program also needs to determine the numbers of qualified and disqualified drivers.
The program has to ask the user for the input file name first, and then read the data into your program. After that, calculate the average lap time. Furthermore, the program has to decide the first place finisher. If two or more drivers have the exact same best record, you have to display all of them as the first place finishers. In this program, you can assume that the total number of drivers entered into the race will not be greater than 30
Sample Input File The following shows a sample input data file. The first line has the number of drivers. Each line indicates the racer’s number and 8 lap times.
5
42 5.6 6.2 3.6 4.5 5.5 4.56 3.75 4.65
8 4.9 5.5 4.8 5.75 4.6 5.6 6.2 6.3
16 5.6 6.2 3.6 -4.5 4.6 5.6 6.2 6.3
75 4.7 8.5 2.6 3.4 5.5 4.56 3.75 4.65
10 5.6 6.2 3.6 -5 -7 4.56 3.75 4.65
Sample Run
A sample run of your program might look like this.
Note that the user’s inputs are highlighted in bold.
Enter an input file: C:\\Temp\\rally.txt
---------------------------------------------------
Rally Race Result
---------------------------------------------------
Racers Avg. Lap
42 4.43
8 5.19
16 DQ
75 3.94
10 DQ
---------------------------------------------------
First Place: Racer 75 (Avg. Lap: 3.94)
Number of Qualified Racers: 3
Number of Disqualified Racers: 2
Design and Implementation You must develop your program with the following two functions or more. 1. A function to read a data file and calculate the average lap times: This function should prompt the user a data file name and read the data. Then it calculates the average lap time for each driver. 2. A function to print the race result and determine the top finisher. For this project, you may need several arrays to store the ids of drivers and results. Additionally, it may need to pass the arrays between functions.
Here is the required code you needed. Everything implemented according to the specifications. Make sure your input file is in valid format (no unwanted spaces, blank line breaks etc). Thanks.
//rally.cpp
#include<iostream>
#include<fstream>
#include<iomanip>
using namespace std;
//method to read data from file and fill the arrays
void readData(int *drivers,float *avg,int &count){
char filename[50];
cout<<"Enter input file name: ";
cin>>filename;
ifstream inFile(filename); //opening file for reading
//reading from file, assuming file is in valid format
if(!inFile){
cout<<"File not found!"<<endl;
exit(1);
}
inFile>>count;//reading number of drivers
float time;
float times[8];//array to store lap times of a single driver
for(int i=0;i<count;i++){
inFile>>drivers[i];
bool disq=false;//flag to check if driver is diqualified
for(int j=0;j<8;j++){
//reading times
inFile>>time;
if(time<0){
disq=true;//disqualified
}
times[j]=time;
}
if(disq){
avg[i]=-1; //setting average to -1 for disqualified drivers
}else{
//sorting times, so that we can find smallest(highest) two lap times easily
for(int j=0;j<8;j++){
for(int k=0;k<7;k++){
if(times[k]>times[k+1]){
float tmp=times[k];
times[k]=times[k+1];
times[k+1]=tmp;
}
}
}
//finding the average value excluding the last two times (slowest)
float total=0;
for(int k=0;k<6;k++){
total+=times[k];
}
avg[i]=total/6;//finding the average lap time
}
}
}
//method to print driver ids, average times and fastest driver
void printStats(int *drivers, float *averages, int count){
int qualified=0, disqualified=0;
float first=-1;// to store fastest time
cout<<"-----------------"<<endl;
cout<<"Rally Race Result"<<endl;
cout<<"-----------------"<<endl;
cout<<"Racers\tAvg. Lap"<<endl;
for(int i=0;i<count;i++){
cout<<drivers[i]<<"\t";
if(averages[i]==-1){ //disqualified driver
disqualified++;
cout<<"DQ"<<endl;
}else{
qualified++;
//printing average with 2 decimal point precision
cout<<setprecision(2)<<fixed<<averages[i]<<endl;
if(first==-1){ //first entry, assuming this is the winner's time
first=averages[i];
}else if(averages[i]<first){
//this average is smaller than the first, so making it as the
//fastest time (first place)
first=averages[i];
}
}
}
cout<<"-----------------"<<endl;
cout<<"First Place: ";
for(int i=0;i<count;i++){
//printing all drivers with fastest time= first
if(averages[i]==first){
cout<<"Racer "<<drivers[i]<<" (Avg. Lap: "<<first<<") ";
}
}
cout<<endl;
cout<<"Number of Qualified Racers: "<<qualified<<endl;
cout<<"Number of Disqualified Racers: "<<disqualified<<endl;
}
int main(){
int drivers[30];//array to store drivers
float averages[30];//array to store averages
int count=0;//counter
//reading data
readData(drivers,averages,count);
//printing stats
printStats(drivers,averages,count);
return 0;
}
/*OUTPUT*/
Enter input file name: rally.txt
-----------------
Rally Race Result
-----------------
Racers Avg. Lap
42 4.43
8 5.19
16 DQ
75 3.94
10 DQ
-----------------
First Place: Racer 75 (Avg. Lap: 3.94)
Number of Qualified Racers: 3
Number of Disqualified Racers: 2
(C++) The CSIT Racing Club is a group that runs amateur car racing events throughout the...
***C++ Code*** What this Assignment Is About: -Learn to define and call void & non-void functions -Learn to use reference variables Coding Guidelines for All Labs/Assignments (You will be graded on this) -Give identifiers semantic meaning and make them easy to read (examples numStudents, grossPay, etc). -Keep identifiers to a reasonably short length. -Use upper case for constants. Use title case (first letter is upper case) for classes. Use lower case with uppercase word separators for all other identifiers (variables,...
This C++ Program consists of: operator overloading, as well as experience with managing dynamic memory allocation inside a class. Task One common limitation of programming languages is that the built-in types are limited to smaller finite ranges of storage. For instance, the built-in int type in C++ is 4 bytes in most systems today, allowing for about 4 billion different numbers. The regular int splits this range between positive and negative numbers, but even an unsigned int (assuming 4 bytes)...