C++ Help! Can\'t find what is wrong with my program, won\'t run Advanced Taxi Sy
ID: 3575242 • Letter: C
Question
C++ Help! Can't find what is wrong with my program, won't run
Advanced Taxi System- For this program, implement two classes and a struct. You will have a class for taxi companies, a class for times, and a struct for orders. Build a menu system that will allow the user to order a trip, view their cart, or exit. Ordering a trip should ask the user for the passenger’s name, the number of miles to be driven, and use the Time class method to get the time of the pickup. Create a Trip instance with those pieces of information. Next, display a submenu for the user to choose a taxi company from which to order. Show the cost the trip would be with each company using the calculateTrip class method. Use a for loop to iterate over your taxi company array rather than re-writing the same basic menu option for each company. When the user selects a company to place the order with, use the addTrip class method of the corresponding taxi company to add the Trip instance you created earlier. Viewing the cart should use a for loop to iterate over the companies in the array, calling the showTrips class method for each. You will likely need the vector, iomanip, and iostream libraries. **********cannot be global.
The class and struct attributes and methods should be as follows:
TIME
-int h, m stores the time in 24h mode
-void rollForward()
-int getH() converts h to 12-hour mode, used by print
-int getM() returns m, used by print
+Time(int h, int m) constructor, sets h and m
+Time() constructor, doesn’t set anything
+void setTime() asks the user to input time in 24h mode
+void print() nicely prints the time in 12h mode
TRIP:
-int miles
-Time pickup
-string passenger
TAXI
-string name stores the name of the taxi company
-vector< Trip > trips stores the list of trips ordered with the company
-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
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
**********Sample Output: (user input in italics) I can't get it to turn out like this, help!
===Main Menu===
1. Order a trip
2. View Cart
3. Exit > 2
Active Trips: $ 0.00 pending with Checker Cab $ 0.00 pending with GTS Lawrence $ 0.00 pending with Jayhawk Taxi
===Main Menu===
1. Order a trip
2. View Cart
3. Exit > 1
What is the passenger's first name? Bob How many miles would you like to travel? 10 Enter the time with whitespace separating the hours and minutes: 5 45
Which company would you like to place the Trip with? 1. Checker Cab - $30.00 2. GTS Lawrence - $7.00 3. Jayhawk Taxi - $9.00 > 2
===Main Menu===
1. Order a trip
2. View Cart
3. Exit > 2
Active Trips: $ 0.00 pending with Checker Cab
$ 7.00 pending with GTS Lawrence Trip scheduled for Bob covering 10 miles with pickup at 05:45 am
$ 0.00 pending with Jayhawk Taxi
===Main Menu===
1. Order a trip
2. View Cart
3. Exit > 1
What is the passenger's first name? Jane How many miles would you like to travel? 100 Enter the time with whitespace separating the hours and minutes: 18 20
Which company would you like to place the Trip with? 1. Checker Cab - $30.00 2. GTS Lawrence - $25.00 3. Jayhawk Taxi - $81.00 > 2
===Main Menu===
1. Order a trip
2. View Cart
3. Exit > 2
Active Trips: $ 0.00 pending with Checker Cab
$ 32.00 pending with GTS Lawrence Trip scheduled for Bob covering 10 miles with pickup at 05:45 am Trip scheduled for Jane covering 100 miles with pickup at 06:20 pm
$ 0.00 pending with Jayhawk Taxi
===Main Menu===
1. Order a trip
2. View Cart
3. Exit > 1 What is the passenger's first name? Sam How many miles would you like to travel? 4 Enter the time with whitespace separating the hours and minutes: 10 13
Which company would you like to place the Trip with? 1. Checker Cab - $30.00 2. GTS Lawrence - $5.80 3. Jayhawk Taxi - $4.20 > 3
===Main Menu===
1. Order a trip
2. View Cart
3. Exit > 2
Active Trips: $ 0.00 pending with Checker Cab
$ 32.00 pending with GTS Lawrence Trip scheduled for Bob covering 10 miles with pickup at 05:45 am Trip scheduled for Jane covering 100 miles with pickup at 06:20 pm
$ 4.20 pending with Jayhawk Taxi Trip scheduled for Sam covering 4 miles with pickup at 10:13 am
===Main Menu===
1. Order a trip
2. View Cart
3. Exit > 1
What is the passenger's first name? Zoe How many miles would you like to travel? 200 Enter the time with whitespace separating the hours and minutes: 23 59
Which company would you like to place the Trip with? 1. Checker Cab - $30.00 2. GTS Lawrence - $45.00 3. Jayhawk Taxi - $161.00 > 1
===Main Menu===
1. Order a trip
2. View Cart
3. Exit > 2
Active Trips: $ 30.00 pending with Checker Cab Trip scheduled for Zoe covering 200 miles with pickup at 11:59 pm
$ 32.00 pending with GTS Lawrence Trip scheduled for Bob covering 10 miles with pickup at 05:45 am Trip scheduled for Jane covering 100 miles with pickup at 06:20 pm
$ 4.20 pending with Jayhawk Taxi Trip scheduled for Sam covering 4 miles with pickup at 10:13 am
===Main Menu===
1. Order a trip
2. View Cart
3. Exit > 3
Exiting...
**This is what I have so far, pretty sure its wrong... I have CLion, and it keeps saying "function definition is not allowed here" I can't figure it out
#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;
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;
}
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;
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;
}}
Explanation / Answer
Define function definition outside main function because your functions are global. Then it will not give any error. Try below code.
#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;
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;
}
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;
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;
}
Note...
Alloted Time was not enough to solve the problem entirely. Try once again and come up with your issue, if any .
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.