This code doesn't work, please help me. ----------------------------------- #include #include using namespace std; class Taxi { private: string driver_name; string maker; string color; public: int calls; int passengers; static int Tpassengers; Taxi(string name, string maker, string color) { this->driver_name=name; this->maker=maker; this->color=color; this->passengers=0; this->calls=0; } Taxi(int pass) { this->passengers=pass; } int NPassenger() { int x = (rand()%10)+1; return x; } Taxi operator += (const Taxi x){ this->passengers +=x.passengers; this->calls+=1; return *this; } void write_Taxi_info() { ofstream outFile; outFile.open("CTC.txt", std::ios_base::app); outFile.close(); } }; int Taxi::Tpassengers{0}; int main() { srand((unsigned)time(0)); Taxi** taxis = new Taxi*[6]; taxis[0] = new Taxi("xyz qwe","erty","blue"); taxis[1] = new Taxi("xyz qwe","erty","blue"); taxis[2] = new Taxi("xyz qwe","erty","blue"); taxis[3] = new Taxi("xyz qwe","erty","blue"); taxis[4] = new Taxi("xyz qwe","erty","blue"); taxis[5] = new Taxi("xyz qwe","erty","blue"); char choice; cout <<"\nWelcome to CTC Taxi."; do{ cout <<"\nDo you need a taxi?\n"; cin >>choice; if(choice!='Y' && choice!='y') { break; } int taxi = rand()%6; cout <<"Taxi #"<NPassenger(); Taxi* temp = new Taxi(pass); *taxis[taxi]+=*temp; Taxi::Tpassengers+=pass; }while(1); cout << "************************************************************************" <calls <<" calls\t\t"<< taxis[1]->calls <<" calls\t\t"<< taxis[2]->calls <<" calls\t\t"<< taxis[3]->calls <<" calls\t\t"<< taxis[4]->calls <<" calls\t\t"<< taxis[5]->calls <<" calls\n"<< taxis[0]->passengers <<"passengers\t"<< taxis[1]->passengers <<"passengers\t"<< taxis[2]->passengers <<"passengers\t" << taxis[3]->passengers <<"passengers\t"<< taxis[4]->passengers <<"passengers\t"<< taxis[5]->passengers <<"passengers\n"; cout<< "**************************************************************************************************"<passengers; for(int i=1;i<6;i++) { if(taxis[i]->passengers>taxis[index]->passengers) { index=i; } sum+=taxis[i]->passengers; } cout<<"Today taxi "<
OOPs
In today's technology-driven world, computer programming skills are in high demand. The object-oriented programming (OOP) approach is very much useful while designing and maintaining software programs. Object-oriented programming (OOP) is a basic programming paradigm that almost every developer has used at some stage in their career.
Constructor
The easiest way to think of a constructor in object-oriented programming (OOP) languages is:
This code doesn't work, please help me.
-----------------------------------
#include<iomanip>
#include <fstream>
using namespace std;
class Taxi
{
private:
string driver_name;
string maker;
string color;
public:
int calls;
int passengers;
static int Tpassengers;
Taxi(string name, string maker, string color)
{
this->driver_name=name;
this->maker=maker;
this->color=color;
this->passengers=0;
this->calls=0;
}
Taxi(int pass)
{
this->passengers=pass;
}
int NPassenger()
{
int x = (rand()%10)+1;
return x;
}
Taxi operator += (const Taxi x){
this->passengers +=x.passengers;
this->calls+=1;
return *this;
}
void write_Taxi_info()
{
ofstream outFile;
outFile.open("CTC.txt", std::ios_base::app);
outFile.close();
}
};
int Taxi::Tpassengers{0};
int main()
{
srand((unsigned)time(0));
Taxi** taxis = new Taxi*[6];
taxis[0] = new Taxi("xyz qwe","erty","blue");
taxis[1] = new Taxi("xyz qwe","erty","blue");
taxis[2] = new Taxi("xyz qwe","erty","blue");
taxis[3] = new Taxi("xyz qwe","erty","blue");
taxis[4] = new Taxi("xyz qwe","erty","blue");
taxis[5] = new Taxi("xyz qwe","erty","blue");
char choice;
cout <<"\nWelcome to CTC Taxi.";
do{
cout <<"\nDo you need a taxi?\n";
cin >>choice;
if(choice!='Y' && choice!='y')
{
break;
}
int taxi = rand()%6;
cout <<"Taxi #"<<taxi+1<<" will pick you up in a few minutes.";
int pass=taxis[taxi]->NPassenger();
Taxi* temp = new Taxi(pass);
*taxis[taxi]+=*temp;
Taxi::Tpassengers+=pass;
}while(1);
cout << "************************************************************************" <<endl;
cout <<"\t\t*CTC Taxi served a total of "<< Taxi::Tpassengers <<" passengers today.**\n";
cout <<"***************************************************************************"<<endl;
cout <<"**********************************************************************"<<endl;
cout << "*Each taxi serve total number of passenger in this shift as bellow:**\n";
cout <<"***********************************************************************************************"<<endl;
cout <<"\nTaxi1\t\tTaxi2\t\tTaxi3\t\tTaxi4\t\tTaxi5\t\tTaxi6\n"<< taxis[0]->calls <<" calls\t\t"<< taxis[1]->calls
<<" calls\t\t"<< taxis[2]->calls <<" calls\t\t"<< taxis[3]->calls <<" calls\t\t"<< taxis[4]->calls <<" calls\t\t"<< taxis[5]->calls
<<" calls\n"<< taxis[0]->passengers <<"passengers\t"<< taxis[1]->passengers <<"passengers\t"<< taxis[2]->passengers <<"passengers\t"
<< taxis[3]->passengers <<"passengers\t"<< taxis[4]->passengers <<"passengers\t"<< taxis[5]->passengers <<"passengers\n";
cout<< "**************************************************************************************************"<<endl;
int index=0;
int sum=taxis[0]->passengers;
for(int i=1;i<6;i++)
{
if(taxis[i]->passengers>taxis[index]->passengers)
{
index=i;
}
sum+=taxis[i]->passengers;
}
cout<<"Today taxi "<<index+1<<" served most passengers.\n";
cout<<"Today on average each taxi served "<<fixed<<setprecision(1)<<sum/6.0<<" passengers.\n";
return 0;
}
Step by step
Solved in 2 steps