Write c++ inventory program for a bike shop. The program should read the codes f
ID: 643925 • Letter: W
Question
Write c++ inventory program for a bike shop. The program should read the codes from the file "data.txt" and perform the following transactions:
1 Create bike, call the function to input bike data, read the bike ID, size, cost per day, and manufacturer. Call the function to add bike to the general list, then call the function to add bike to the list, sorted by ID, and also call the function to add bike to the list, sorted by the manufacturer's name.
2 Print list of the bikes.
3 Print the list of the bikes sorted by id
4 Print list of the bikes, sorted by manufacturer's name
5 Printing bikes available for rent
6 Printing the rented bikes
7 Perform rental transaction (read bike's id, number of days, and person's name from the file), calculate and display the cost of rental, and set the bike's status to rented and to whom.
8 Perform return transaction (read bike's id from the file)
9 Delete bike by ID (read the ID from the file) (soft delete, i.e. set the flag of the deleted bike to true.
10 Delete bike by manufacturer's name (read manufacturer's name from the file)
This is the code that I have so far but I need help with the functions:
#include <iostream>
#include <fstream>
#include <cstdlib>
//#include "bikes.h"
using namespace std;
int main()
{
int opt;
char fileName[] = {"data.txt"};
fstream inFile;
inFile.open(fileName,ios::in);
if (inFile.fail( ))
{
cout << "Input file opening failed. ";
exit(1);
}
cout <<" XYZ Bike Shop"<<endl;
cout <<" Inventory Menu"<<endl;
cout <<" Code Action";
cout <<" ______________________________________________ ";
cout <<" 1 Create New Bike or Add a bike.";
cout <<" 2 Print All Bikes.";
cout <<" 3 Print Bikes by ID Number.";
cout <<" 4 Print Bikes by Manufacturer's Name.";
cout <<" 5 Print Bikes available for Rent.";
cout <<" 6 Print Bikes that are currently Rented.";
cout <<" 7 Perform a rental Transaction.";
cout <<" 8 Perform a return Transaction.";
cout <<" 9 Delete Bike by ID.";
cout <<" 10 Delete Bike by Manufacturer Name.";
cout <<" ______________________________________________ ";
cout <<" Reading data from: "<< fileName <<" ";
cout <<" Code entered: ";
while ((opt)&&(!inFile.eof( )))
{
opt = 0;
inFile >> opt;
cout << opt << " ";
switch(opt)
{
case -1:
case 0:
continue;
break;
case 1: // Create bike
cout<<" Gathering information from the file...... "<<endl;
/*readBike(inFile, pFirst, pFirstManuf, pFirstId, pFirstCostPerDay);*/
break;
case 2: // Print list of all the bikes.
cout<<" Printing all Bikes";
/*printBikes(pFirst, NO_ORDER, ALL);*/
break;
case 3: // Print bikes sorted by ID.
cout<<" Printing list sorted by ID Number";
/*printBikes(pFirstId, ID, ALL);*/
break;
case 4: // Print bikes sorted by manufacturer's name.
cout<<" Printing list sorted by manufacturer";
/*printBikes(pFirstManuf, MANUF, ALL);*/
break;
case 5: // Print bikes available for rent.
cout<<" Printing Bikes that are available for rent"<<endl;
/*printBikes(pFirst, NO_ORDER, NOT_RENTED);*/
break;
case 6: // Print rented bikes.
cout<<" Printing Rented Bikes"<<endl;
/*printBikes(pFirst, NO_ORDER, RENTED);*/
break;
case 7: // Perform rental transaction.
cout<<" Performing a Rental transaction:"<<endl;
/*do_transact(inFile, pFirst, RENTED);*/
break;
case 8: // Perform return transaction.
cout<<" Performing Return transaction "<<endl;
/*do_transact(inFile, pFirst, NOT_RENTED);*/
break;
case 9: // Delete bike by ID.
cout<<" Deleting Bike by ID number"<<endl;
/*del_id_bike(inFile, pFirst);*/
break;
case 10: // Delete bike by manufacturer's name.
cout<<" Deleting Bike by manufacturer"<<endl;
/*del_manuf(inFile, pFirst);*/
break;
default:
break;
}
}
inFile.close();
// deleteBikes(pFirst);
return 0;
}
/*void readBike(fstream inFile&, Bike* & head, Bike *& manufact, Bike *& id, Bike *& cost_per_day)
{
}*/
/*Bike *addBike(Bike* head, Bike* new_bike)
{
}*/
/*Bike *addBike(Bike *head_id, Bike *new_bike, order)// extra
{
}*/
/*Bike *addBike(Bike *head_manufacturer, Bike *new_bike, order, int)// extra
{
}*/
/*void printBikes(Bike*, order, status)
{
}*/
/*void do_transact(fstream inFile&, Bike*, status)
{
}*/
/*void del_id_bike(fstream inFile&, Bike* pFirst)
{
}*/
/*void del_manuf(fstream inFile&, Bike* pFirst)
{
}*/
/*void deleteBikes(Bike* pFirst)
{
}*/
/*void init(Bike*)
{
}*/
Here is the information for the header file:
#ifndef BIKES_H_INCLUDED
#define BIKES_H_INCLUDED
#include <iostream>
using namespace std;
enum status {NO_STATUS, NOT_RENTED, RENTED, ALL};
enum order {NO_ORDER, ID, MANUF};
struct Bike
{
int id_num;
int size;
float cost_per_day;
char manufact[26];
char to_whom [26]; // to whom the bike is rented.
bool deleted; // to mark bike as deleted in the list.
status rented_code; // RENTED/NOT RENTED.
Bike *next_manuf; // pointer to the next node in the manufacturer list.
Bike *next_id; // pointer to the next node in the list by ID.
Bike *next; // pointer to the next node in the general list.
};
/* Reads bikes from the file, creates new Bike object, and calls functions to add bike to the general
list, to the list sorted by id, and to the list sorted by manufacturer.*/
void readBike(fstream&, Bike*& head, Bike*& manufact, Bike*& id);
/* adds bike to the general list*/
Bike *addBike(Bike* head, Bike *new_bike);
/*(optional) - Overload function to add bike to the list, sorted by ID*/
Bike *addBike(Bike *head_id, Bike *new_bike, order); // extra
/*(optional) - overload function to add bike to the list, sorted by manufacturer*/
Bike *addBike(Bike *head_manufacturer, Bike *new_bike, order, int); // extra
/* Prints any list of bikes, that have not been deleted, depending on the status, and the head pointer
passed. If the status is ALL, it will print the entire list of (not deleted) bikes.*/
void printBikes(Bike*, order, status);
/* Reads the ID, number of days from the file, and depending on the status (RENTED/NOT_RENTED), it will either rent
a bike to the person (in which case, it will read the person's name from the file, or performs a return transaction.)
If transaction is rented, it will display the total cost of the rent (number of days * cost of rent per day).*/
void do_transact(fstream& Bike*, status);
/* Finds a bike by ID in the list and sets its deleted bike to true.*/
void del_id_bike(fstream&, Bike*);
/* Finds a bike by the manufacturer's name in the list and sets its deleted flag to true.*/
void del_manuf(fstream&, Bike*);
/* Traverses the general list of bikes and deletes all the nodes in it, releasing the memory back.*/
void deleteBikes(Bike* pFirst);
/* This function initializes the new Bike's object to all default values*/
void init(Bike*);
#endif // BIKES_H_INCLUDED
Here is the information for the data file:
1
234
20
12.5
honda
1
123
12
23.22
yamaha
1
456
20
33.5
bmw
1
567
20
44.5
suzuki
1
789
20
55.5
harley
2
3
4
5
6
7
123
3
Johny A
5
6
8
123
3
5
6
8
123
3
9
123
3
2
10
honda
2
3
4
Explanation / Answer
#include "Car.h"
#include "Truck.h"
#include "Motorcycle.h"
using namespace std;
int main() {
int tempInt;
string temp;
int menu=0;
int current_vehicle=0;
int tmpInt=0;
// My Vehicle set up(Make, model, color, year, type,bedsize, bike, mileage)
Vehicle *myVehicles[9];
myVehicles[0] = new Car("Porsche","911","Silver",2005, 12000);
myVehicles[1] = new Car("Ford","Mustang","Red",2007, 14213);
myVehicles[2] = new Motorcycle("Kawasaki","Ninja","Black",2004, " Custom ", 11989);
myVehicles[3] = new Truck("Ford","F150","White",2007, 10, 23458);
myVehicles[4] = new Car("Voltzwagon","Jetta","Black",2006, 45000);
myVehicles[5] = new Motorcycle("Harley","Cherokee","Silver",2000, "Chopper ", 53246);
myVehicles[6] = new Truck("Toyota","Tacoma","Blue",2002, 12, 73000);
myVehicles[7] = new Motorcycle("Honda","CBR1500CC","Red",2008, "Cruiser", 7050);
myVehicles[8] = new Truck("Toyota","Tacoma","White",2009, 6, 10);
while (menu!=7)//keep going until 7 is selected
{
cout << "Vehicle Menu "; //Menu
cout << "1. Select the Vehicle to edit: ";
cout << "2. Change the Model of one Car: ";
cout << "3. Change the Bed Size of one Truck: ";
cout << "4. Change the Bike Type for one Motorcycle: ";
cout << "5. Change the Year of a Truck: ";
cout << "6. Display the Vehicle Inventory List: ";
cout << "7. Exit the Program: ";
cout << "Please choose one of the above options: ";
cin >> menu;
cin.ignore();
cout << "_______________________________________________________ ";
//switch begin
switch ( menu )
{
case 1:
//Here the user will select which vehicle on the lot that they want to edit!
cout << " Pick a vehicle to edit ";
cin >> current_vehicle;
--current_vehicle;
cin.ignore();
cout << "_______________________________________________________ ";
break;
case 2:
//User will be able to change the model of the car
cout << " The Model of car is: "
<< *myVehicles[current_vehicle].getModel() << endl;
cout << " Please enter the change to the model of the car: ";
getline(cin, temp);
myVehicles[current_vehicle].setModel(temp);
cout << "_______________________________________________________ ";
break;
case 3:
//The user can change the bed size of the current vehicle selected
cout << " The Bed Size of the current truck is: "
<< myVehicles[current_vehicle].getBedSize() << endl;
cout << " Please enter the change the change to the Bed Size: ";
getline(cin, temp);
myVehicles[current_vehicle].setBedSize(temp);
cout << "_______________________________________________________ ";
break;
case 4:
//User can change the bike type of the current vehicle selected
cout << " The Bike Type of the current motorcycle is: "
<< myVehicles[current_vehicle].getBikeType() << endl;
cout << " Please enter the change to the Bike Type: ";
getline(cin, temp);
myVehicles[current_vehicle].setBikeType(temp);
cout << "_______________________________________________________ ";
break;
case 5:
//User can change the year of the current vehicle selected
cout << " The current year of the truck is: "
<< myVehicles[current_vehicle].getYear() << endl;
cout << " Please enter the change to the year of the truck: ";
getline(cin, temp);
myVehicles[current_vehicle].setYear(temp);
cout << "_______________________________________________________ ";
break;
case 6:
//Pointers to print details for all cars
cout << " The current Cars on the lot are: ";
&Car::details;
//Pointer to print details for all trucks
cout << " The current Trucks on the lot are: ";
&Truck::details;
//Pointers to print details for all motorcycles
cout << " The current Motorcycles on the lot are: ";
&Motorcycle::details;
cout << "_______________________________________________________ ";
break;
default:
cout << " Please restart the program, you have entered invalid information! ";
break;
} //switch end
} //while
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.