Question
The company needs a more detailed report to be generated at the end of each shift (4 points). The sample screen output with the report
The company needs a more detailed report to be generated at the end of each shift (4 points). The sample screen output with the report is listed below:
Welcome to CTC Taxi.
Do you need a taxi?
Y
Taxi CTC0001 will pick you up in a few minutes. (Taxi CTC0001 determined that there were 3 passengers)
Do you need a taxi?
Y
Taxi CTC0004 will pick you up in a few minutes. (Taxi CTC0004 determined that there were 5 passengers)
Do you need a taxi?
N
CTC Taxi served a total of 124 passengers today.
CTC0001 CTC00022 CTC0003 CTC0004 CTC0005 CTC0006
19 Calls 25 Calls 10 Calls 12 Calls 22 Calls 13 Calls
25 Passengers 45 Passengers 34 Passengers 29 Passengers 24 Passengers 30 Passengers
Today CTC0002 served most passengers.
Today on average each taxi served 31.7 passengers.
You must include the following parts in your program:
- Overload + to add total calls and total passengers of all taxis (2 points);
- Overload < to determine which taxi served most passengers (2 points);
- Store the report in a disk file (2 points)
#include
#include
using namespace std;
class Taxi { // Taxi Class Definition
private:
string name, maker, color, id;
int numPass, totalNum;
static int totalPassenger; // static variable to store
public:
Taxi() {
name = maker = color = "";
numPass = 0;
}
Taxi(string num, string name, string maker, string color) {
this->id = num;
this->name = name;
this->maker = maker;
this->color = color;
numPass = 0;
}
int getRandomPass() { // random upon request
return rand() %4+1;
}
void display() { // random taxi sent
numPass = getRandomPass();
cout << "Taxi " << id << " a " << color << " " << maker << " driven by " << name << " will pick you up in a few minutes.";
cout << "(Taxi " << id << " Determined that there were " << numPass << " passengers)" << endl;
recordNum();
totalPassenger += numPass;
}
void showRecord() { // show taxi record
cout << name << " served " << totalNum << " passengers." << endl;
}
void recordNum() { // record totalPassenger of each taxi;
totalNum += numPass;
}
int totalPassengerServed() {
return totalPassenger;
}
};
int Taxi::totalPassenger = 0;
int main() {
// taxi number, driver name, maker, color
Taxi taxi1( "CTC10001", "Ted", "Toyota Camry", "red");
Taxi taxi2( "CTC10002", "Ron", "Ford Escape", "black");
Taxi taxi3( "CTC10003", "Kai", "BMW M4", "black");
Taxi taxi4( "CTC10004", "Mark", "Audi R7", "black");
Taxi taxi5( "CTC10005", "John", "Mercedes-Benz G65", "Grey");
Taxi taxi6( "CT10006", "Aciel", "Hyundai Santa Fe", "White");
char ch;
cout << "Welcome to CTC" << endl;
while (true) {
cout << " Do you need a Taxi?" << endl;
cin >> ch;
if (ch == 'N')
break;
int select = rand() %6+1;
switch (select) {
case 1:
taxi1.display();
break;
case 2:
taxi2.display();
break;
case 3:
taxi3.display();
break;
case 4:
taxi4.display();
break;
case 5:
taxi5.display();
break;
case 6:
taxi6.display();
break;
}
}
cout << "CTC served a total of " << taxi1.totalPassengerServed() << " passengers today. " << endl;
taxi1.showRecord();
taxi2.showRecord();
taxi3.showRecord();
taxi4.showRecord();
taxi5.showRecord();
taxi6.showRecord();
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