Question: My previous project (in C++) had us writing a menu for a rental car service. Our menu included the following options: 1. Take in an
My previous project (in C++) had us writing a menu for a rental car service. Our menu included the following options:
1. Take in an input file of 5 cars and store it.
2. Print out all data for all cars to the terminal
3. Print out all data for all cars to an output file
4. Sort the car array by ascending price
5. Provide a list of cars along with their cost based on how many days they want the car
6. Provide cost based on the type of car and the number of days they want it
7. Exit program
Previous Project input file structure:
year, an int (year of production)
make, a C-string (char array of 10 maximum size)
model, a C-string (char array of 10 maximum size
price, a float (price per day)
available, a bool (1 = true; 0 = false; try to display true/falseSample Input File: (cars.txt)
2014 Toyota Tacoma 115.12 0
2015 Ford Fusion 90.89 1
2009 Dodge Neon 45.25 0
2015 Ford F150 112.83 1
2016 Subaru Outback 71.27 1
This is what my code ended up looking like
*************************************************
#include
#include
#include
using namespace std;
struct rentalCar {
char make[10];
char model[10];
int year;
float price;
bool available;
};
//Purpose: take the users selection choice and save it to selection variable
void select(int &selection){
cout
cin >> selection;
cout
}
//Purpose: [1] read input file and store the arrayy into our struct
void readFile(rentalCar cars[]) {
ifstream fin; // Create input stream variable
char ifileName[20]; // Create var to hold input file name
cout
cin >> ifileName; // Save user input to file name
fin.open(ifileName); // open user-definied file
if (fin.is_open()){ // Check if file opened correctly
for (int i = 0; i
fin >> cars[i].year >> cars[i].make >> cars[i].model
>> cars[i].price >> cars[i].available;
}
cout
}
else { cout
}
//Purpose: Prints all cars to terminal [2] and all available cars to terminal [5]
void printCars(rentalCar cars[]) {
cout
for (int i = 0; i
cout
}
}
//Purpose: copy struct from input file to output file [3]
void output(rentalCar cars[]){
char filename[20];
ofstream fout;
cout
cin >> filename;
fout.open(filename);
int count = 0;
for (int i = 0; i
fout
if (cars[i].available == false){
fout
}
else{
fout
}
}
}
void printAvailable(bool availableOnly, rentalCar cars[]) {
//Ask for number of days wanted
int dayCount;
cout
cin >> dayCount;
cout
//print only available cars
for (int i = 0; i
// if availableOnly is true, print cars that are available and order it by ascending price
if (cars[i].available != false || availableOnly != true) {
cout
//total cost
float cost = cars[i].price*dayCount; // calculate final cost
cout
}
}
}
//Purpose: [6] Estimates price based on car choice and number of days
void estimatePrice(rentalCar cars[]) {
int carNumber;
int dayCount;
cout
cin >> carNumber;
cout
cin >> dayCount;
//if available
if(cars[carNumber+1].available == true){
//change to unavailable
cars[carNumber+1].available = false;
cout
//total cost
float cost = cars[carNumber+1].price*dayCount;
cout
}
else{
cout
}
}
//Purpose: to help aid in ascending price function
void copy (char p[10] , char q[10]){
for (int i = 0; i
p[i] = q[i];
}
//Sorts car list by ascending price [4][5]
void ascendingPrice(struct rentalCar cars[]) {
struct rentalCar temp;
for (int i = 0; i
for (int j =i+1; j
if (cars[i].price > cars[j].price){
//rentalcar temp;
//if ( );
//temp
temp.year = cars[i].year;
copy(temp.make,cars[i].make);
copy(temp.model,cars[i].model);
temp.price = cars[i].price;
temp.available = cars[i].available;
cars[i].year = cars[j].year;
copy(cars[i].make,cars[j].make);
copy(cars[i].model,cars[j].model);
cars[i].price = cars[j].price;
cars[i].available = cars[j].available;
cars[j].year = temp.year;
copy(cars[j].make,temp.make);
copy(cars[j].model,temp.model);
cars[j].price = temp.price;
cars[j].available = temp.available;
}
}
}
}
main() {
//Menu
int selection = 0;
do {
//Menu title and options
cout
cout
cout
cout
cout
cout
cout
cout
cout
//run select function to get user's choice
select(selection);
rentalCar cars[5]; //makes array of 5 cars
switch (selection){ //run respective function using cars array
case 1: readFile(cars);
break;
case 2: printCars(cars);
break;
case 3: output(cars);
break;
case 4: ascendingPrice(cars);
break;
case 5: ascendingPrice(cars);
printAvailable(true, cars);
break;
case 6: estimatePrice(cars);
break;
case 7: cout
break;
default:
cout
}
}
while (selection != 7);
return 0;
}
***********************************************
Here is our new project





New Input File: (Agencies.txt)
Hertz 93619
2014 Toyota Tacoma 115.12 1
2012 Honda CRV 85.10 02015 Ford Fusion 90.89 0
2013 GMC Yukon 110.43 0
2009 Dodge Neon 45.25 1
Alamo 89502
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
Budget 93035
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
Sample output for menu option 2:
Hertz 93619
2014 Toyota Tacoma , $115.12 per day , Available: true
2012 Honda CRV , $85.1 per day , Available: false
2015 Ford Fusion , $90.89 per day , Available: false
2013 GMC Yukon , $110.43 per day , Available: false
2009 Dodge Neon , $45.25 per day , Available: true
Alamo 89502
2011 Toyota Rav4 , $65.02 per day , Available: true
2012 Mazda CX5 , $86.75 per day , Available: true
2016 Subaru Outback , $71.27 per day , Available: false
2015 Ford F150 , $112.83 per day , Available: true
2010 Toyota Corolla , $50.36 per day , Available: true
Budget 93035
2008 Ford Fiesta , $42.48 per day , Available: false
2009 Dodge Charger , $55.36 per day , Available: true
2012 Chevy Volt , $89.03 per day , Available: false
2007 Subaru Legacy , $59.19 per day , Available: false
2010 Nissan Maxima , $51.68 per day , Available: true
Please let me know if you have any questions. Thank you very much for your help!
Description: This project will expand Project 2 by adding additional functionality, using pointers, and implementing abstract data types (ADTs) through classes. Pointers must be used for all array manipulation, including arrays with ADTs (structs, classes) e.g, rental cars, rental agencies. Pointers must be used in function prototypes and function parameter lists not square brackets. Make sure pointers (parameters list and function implementation). Square brackets are to be used only when (e.g.string copy, string compare, etc.) work with For this project, pointers can only be moved by conducting post/pre- in increment/decrement operations on them (ie., ++ or-), or by setting the pointer back to the base address using the array name. All pointers must be passed by value. Note Try to use the arrow operator (->) with Class Object pointers for member access, if you use such in your code.) The new functionality is as follows: You are given an updated data file (e.g. Agencies.txt) where there are 3 rental Car Agency locations, where each of the 3 locations (RentalAgency) has 5 cars (RentalCar). You will have similar menu options, but the functionality has been updated below. Note: using multiple helper functions to do smaller tasks will make this project significantly easier. You may want to create a function that will get a car from a location based on the location and car indices
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
