Agencyh Computer Science Project Car List Data National 9361

Agency.h

Computer Science Project

Car List Data

National 93619

2014 Toyota Tacoma 115.12 1

2012 Honda CRV 85.10 0

2015 Ford Fusion 90.89 0

2013 GMC Yukon 110.43 0

2009 Dodge Neon 45.25 1

2011 Toyota Rav4 65.02 1

2012 Mazda CX5 86.75 1

2016 Subaru Outback 71.27 0

2015 Ford F150 112.83 1

2010 Toyota Corolla 50.36 1

2008 Ford Fiesta 42.48 0

2009 Dodge Charger 55.36 1

2012 Chevy Volt 89.03 0

2007 Subaru Legacy 59.19 0

2010 Nissan Maxima 51.68 1

Objectives: This project test your ability to create, use, and test C++ classes with multiple constructors and a destructor. Using const is also tested. A review of your knowledge of pointers, dynamic memory, I/O and C-style strings is included Description: For this project, you are to modify and extend Project 3 to use classes with constructors and destructors. The header file for rental Car and Agency classes are attached. No changes to the class specifications are allowed. All the data members are the same as Project 3\'s struct data members. All class function implementations should be based on the description below. You must also use pointers without bracket notation or pointer arithmetic as specified in the previous projects. It is NOT required to size your arrays exactly. Note: the provided header file has both class definitions inside of it. You can create a single file that implements both classes\' member functions. Const should be used as appropriate in parameter lists and functions The revised functionality is as follow: An updated data file with one Agency with 15 cars. The main driver will be significantly less complex than Project 3. A menu (9 menu options including exit) is required that will test all of the Agency\'s member functions The Car class will have the following member functions: default constructor- allocates the memory for arrays and sets data members to initial values parameterized constructor-creates a new object based on the values passed into it (allocates memory and assigns data) copy constructor creates a duplicate of the class object (allocates memory and assigns data) destructor deallocates data members and/or resets to initial values. copy -takes in a Car and copies the data into the calling object. print prints all data members to screen. get/set functions -for all data members

Solution

Please find below the program code in C++ :

FILE:

National 93619
2014 Toyota Tacoma 115.12 1
2012 Honda CRV 85.10 0
2015 Ford Fusion 90.89 0
2013 GMC Yukon 110.43 0
2009 Dodge Neon 45.25 1
2011 Toyota Rav4 65.02 1
2012 Mazda CX5 86.75 1
2016 Subaru Outback 71.27 0
2015 Ford F150 112.83 1
2010 Toyota Corolla 50.36 1
2008 Ford Fiesta 42.48 0
2009 Dodge Charger 55.36 1
2012 Chevy Volt 89.03 0
2007 Subaru Legacy 59.19 0
2010 Nissan Maxima 51.68 1


/***********CarRental.cpp*********************\\
/*********Car Rental Program******************\\


#include <iostream>
#include <fstream>

using namespace std;

struct Agency
{
char name[15];
int zip;
};

struct Vehicle
{
int year;
char model[15];
char type[15];
float price;
bool available;
};

void AllCars(Vehicle (*allVehicles)[5], Agency allAgencies[]);
void MostExpensiveCar( Vehicle (*allVehicles)[5], int *x, int *y);
float carRentalCost( Vehicle (*allVehicles)[5], int carID, int amountOfDays, char *select);
void availableCars( Vehicle (*allVehicles)[5], Agency *allAgencies);

int main()
{
int i, j, a = 0, b = 0, option, amountOfDays;
int carNumber, carRow;
float priceOfCarRental;
char inputFileName[50], agencySelection[15];
Vehicle Vehicles[3][5];
Agency Agencies[3];

cout << \"Input name of File\";
cout << \"(must be less than 48 characters): \";
cin >> inputFileName;

inputFileName[49] = \'\\0\';
ifstream fin;
fin.open(inputFileName); //This Opens file based on the user\'s input

for (j = 0; j < 3; j++)
{
fin >> Agencies[j].name;
fin >> Agencies[j].zip;

for (i = 0; i < 5; i++)
{
fin >> Vehicles[j][i].year;
fin >> Vehicles[j][i].model;
fin >> Vehicles[j][i].type;
fin >> Vehicles[j][i].price;
fin >> Vehicles[j][i].available;
}
}
fin.close();

do
{
cout << \"MENU OPTIONS \" << endl;
cout << \"1. PRINT ALL DATA FOR CARS. \" << endl;
cout << \"2. ESTIMATE A CAR RENTAL COST.\" << endl;
cout << \"3. FIND MOST EXPENSIVE CAR.\" << endl;
cout << \"4. PRINT OUT ONLY THE AVAILABLE CARS.\" << endl;
cout << \"5. EXIT PROGRAM.\" << endl;
cout << endl;
cout << \"ENTER OPTION NUMBER 1-5: \";
cin >> option;
cout << endl;

if (option == 1) // To Check if user selected option 1
{
AllCars(Vehicles, Agencies); // Print ALL Car Data
}

else if (option == 2) // To Check if user selected option 2
{
cout << \"Select which agency and car number you would like to estimate rental cost: \" << endl; //Promts user for car selection
cout << \"Agency: \";
cin >> agencySelection;
cout << \"Car # \";
cin >> carNumber;
cout << \"Enter How many days you would like to rent the car: \"; //Promts user for amount of days
cin >> amountOfDays;
cout << endl;
priceOfCarRental = carRentalCost(Vehicles, carNumber, amountOfDays, agencySelection);
cout << \"Price to rent car #\" << carNumber<< \" For \"<< amountOfDays;
cout << \" days\" << \": $\" << priceOfCarRental; // price of car Rental * Number of days
cout << endl;
cout << endl;
}

else if (option == 3) // To Check if user selected option 3
{
cout << \"Searching for most expensive car....\" << endl;
MostExpensiveCar(Vehicles, &a, &b); // This Returns Car Number and Agency associated with Highest price
carNumber = a;
carRow = b;
cout << \"Most Expensive car: \";
cout <<Vehicles[carRow][carNumber].year << \" \";
cout <<Vehicles[carRow][carNumber].model << \" \";
cout <<Vehicles[carRow][carNumber].type << \" \";
cout <<\"$\"<<Vehicles[carRow][carNumber].price << \"(Per Day) \" ;   
if (Vehicles[carRow][carNumber].available == 1)
{
cout << \"(Available: True)\";
}
else
{
cout << \"(Available: False)\";
}
cout << endl;
cout << endl;
}
else if (option == 4) // To Check if user selected option 4
{
availableCars(Vehicles, Agencies);
cout << endl;

}
else if (option == 5) // To Check if user selected option 5
{
cout << \"Terminating Program\" << endl; // End program
}
else
{
cout << \" INVALID SELECTION\" << endl;
}
}
while (option !=5); // This is the Condition of do-while loop

return 0;
}
void availableCars( Vehicle (*allVehicles)[5], Agency *allAgencies)
{
bool yes = true;

cout << \"Printing available vehicles ...\";
cout << endl;

for (int j= 0; j < 3; j++)
{
cout << endl;
cout << allAgencies[j].name << \" \";
cout << allAgencies[j].zip << endl;
for (int i = 0; i < 10; i++)
{
if (allVehicles[j][i].available == yes )
{

cout <<allVehicles[j][i].year << \" \";
cout <<allVehicles[j][i].model << \" \";
cout <<allVehicles[j][i].type << \" \";
cout <<\"$\" << allVehicles[j][i].price << \"(Per Day) \" ;
cout << \"(Available: True)\";
cout << endl;

}
}
}
}

float carRentalCost(Vehicle (*allVehicles)[5], int carID, int amountOfDays, char *select)
{
int count = 0;

if (select[0] == \'A\')
{
count = 1;
}
else if (select[0] == \'B\')
{
count = 2;
}
else
{
count = 0;
}

float price;
price = allVehicles[count][carID- 1].price;
price *= amountOfDays;

return price;
}

void MostExpensiveCar(Vehicle (*allVehicles)[5], int *x, int *y)
{
float most = 0, saveMost = 0;
for (int j = 0; j < 3; j++)
{
for (int i = 0; i <5; i++)
{
most = allVehicles[j][i].price;
if (most > saveMost)
{
saveMost = most;
*x = j;
cout << x << endl;
}
}
}

}

void AllCars(Vehicle (*allVehicles)[5], Agency allAgencies[])
{
int i, j;
for (j = 0; j < 3; j++)
{
cout << allAgencies[j].name << \" \";
cout << allAgencies[j].zip << endl;


for (i = 0; i < 5; i++)
{
cout << \"Car #\" << i+1 << \" \";
cout << allVehicles[j][i].year << \" \";
cout << allVehicles[j][i].model << \" \";
cout << allVehicles[j][i].type << \" \";
cout <<\"$\"<<allVehicles[j][i].price << \"(Per Day) \" ;
if (allVehicles[j][i].available == 1)
{
cout << \"(Available: True)\";
}
else
{
cout << \"(Available: False)\";
}
cout << endl;
}
cout << endl;
}

}

Agency.h Computer Science Project Car List Data National 93619 2014 Toyota Tacoma 115.12 1 2012 Honda CRV 85.10 0 2015 Ford Fusion 90.89 0 2013 GMC Yukon 110.43
Agency.h Computer Science Project Car List Data National 93619 2014 Toyota Tacoma 115.12 1 2012 Honda CRV 85.10 0 2015 Ford Fusion 90.89 0 2013 GMC Yukon 110.43
Agency.h Computer Science Project Car List Data National 93619 2014 Toyota Tacoma 115.12 1 2012 Honda CRV 85.10 0 2015 Ford Fusion 90.89 0 2013 GMC Yukon 110.43
Agency.h Computer Science Project Car List Data National 93619 2014 Toyota Tacoma 115.12 1 2012 Honda CRV 85.10 0 2015 Ford Fusion 90.89 0 2013 GMC Yukon 110.43
Agency.h Computer Science Project Car List Data National 93619 2014 Toyota Tacoma 115.12 1 2012 Honda CRV 85.10 0 2015 Ford Fusion 90.89 0 2013 GMC Yukon 110.43
Agency.h Computer Science Project Car List Data National 93619 2014 Toyota Tacoma 115.12 1 2012 Honda CRV 85.10 0 2015 Ford Fusion 90.89 0 2013 GMC Yukon 110.43

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site