In int main, you should start by establishing an array of three taxi companies.
ID: 3576085 • Letter: I
Question
In int main, you should start by establishing an array of three taxi companies. The following properties should be given to each taxi company:
Name Charge per mile Charge for trip
Checker Cab 0 $30
GTS Lawrence 0.20 $5
Jayhawk Taxi 0.80 $ 1
*** function definitions
-double rateMiles stores the charge per mile
-double rateTrips stores the charge per trip (flat rate)
+Taxi(string n, double rM, double rT) constructor that sets the name, and rates
+string getName() returns the companys name
+double calculateTrip(Trip t) calculates the cost of the trip passed as argument
+double calculateCart() calculates cost of all pending orders
+void addTrip(Trip t) adds a trip to the list of orders
+void showTripx() prints the total pending cost and shows all trips
Explanation / Answer
#include<iostream>
#include<vector>
#include<stdlib.h>
#include<iomanip>
#include<cstring>
using namespace std;
//function prototype
double calculateTripC2(int);
double calculateTripC3(int);
void setTime();
//Taxi Class
class Taxi
{
public:
string name;
double rateMile;
double rateTrips;
Taxi(string n, double rM, double rT)
{
name=n;
rateMile=rM;
rateTrips=rT;
}
};
/*class TRIP
{
public:
int miles;
int pickuptime;
string passenger;
*/
// Time Class
class Time
{
public:
int hr,min;
Time(int h, int m)
{
hr=h;
min=m;
}
int getH(int hr)
{
int Hour=hr-12;
return Hour;
}
int getM(int min)
{
return min;
}
void print()
{
cout <<"Time "<<getH(hr) <<":"<<getM(min)<<endl;
}
};
//Main Funtion Calling
int main()
{
int input;
string name;
int i,H,M;
int mile;
char c, ch;
/* make it as continue asyour wish
do{
cout << "=======Main Menu========"<<endl;
cout << "1. Order a trip"<<endl;
cout << "2. View Cart"<<endl;
cout << "3. Exit "<<endl;
cin>>input;
if(input==1)
{
cout << "What is the passenger's first name?";
cin >> name;
cout << "How many miles would you like to travel?";
cin >> mile;
cout << "Enter the time with whitespace seprating the hours and minuts:";
setTime();
int buf1=H;
int buf2=M;
Time T(buf1, buf2);
T.getH(buf1);
T.getM(buf2);
T.print();
cout << "Which Company would you like to place the Trip with?"<<endl;
cout << "1.Checker Cab -$30"<<endl;
cout << "2.GTS Lawrence-$"<<calculateTripC2(mile)<<endl;
cout << "3.JayHawk Taxi-$"<<calculateTripC3(mile)<<endl;
}
if(input==3)
{
return 0;
}
if (input==2){
Taxi T1("Checker Cab", 0, 30);
Taxi T2("GTS Lawrence", 0.20, 5);
Taxi T3("Jayhawk Taxi", 0.80, 1);
cout <<T1.name<<" "<<T1.rateMile<<" "<<T1.rateTrips<<endl;
cout <<T2.name<<" "<<T2.rateMile<<" "<<T2.rateTrips<<endl;
cout <<T3.name<<" "<<T3.rateMile<<" "<<T3.rateTrips<<endl;
}
cout<<"You wants more operation (Y/y): ";
cin>>ch;
}while(ch=='Y'||ch=='y');
return 0;
}
// Function Defination
double calculateTripC2(int mile)
{
double cost = mile*0.20;
return cost;
}
double calculateTripC3(int mile)
{
double cost = mile*0.80;
return cost;
}
void setTime()
{
int H, M;
char c;
cin >> H >> c >>M;
}