Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need serious help with a relatively difficult coding assignment. This is a mor

ID: 644402 • Letter: I

Question

I need serious help with a relatively difficult coding assignment. This is a more complex assignment and therefore I will award 1400 MORE points on a blank question provided the code is what is needed. I WILL test it! Read comments for addiotional info.

Objective: Write the inventory program for a bike shop - Program should read the codes from the file and perform the following transactions:

1: Create bike, call the function to input bike data, read the bike ID, size, cost perday 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 bikes

3: Print list of bikes by sorted ID

4: Print list of bikes, sorted by manufactures name

5: printing bikes, available for rent

6: Print rented bikes

7: Perform rental transaction (Read bikes ID, # of days and persons name) calculate and display cost of rental and set bike's status to rented and to whom

8: Perform return transaction (Read bikes ID from file)

9: Delete bike by ID (read ID from file) - soft delete i.e. set the flag of the deleted bike to true.

10: Delete bike by manufacturer's name (read manufacture. name from file)

You will have the following data types and functions in the header file:

#ifndef _BIKES_H_

#define _BIKES_H_

enum status {NO_STATUS, NOT_RENTED, RENTED, ALL};

enum order {NO_ORDER, ID, MANUF};

struct Bike

{ char manufact[25];

int id_num; status rented_code;

//RENTED/NOT_RENTED char to_whom[25]; //to whom bike is rented

int size; float cost_per_day; bool deleted; //to mark bike as deleted in the list.

Bike *next_manuf; //pointer to next node in the //manufacturers 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 };

//Functions:

//*readBike:-

*Purpose: 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 the manufacturer. *Parameters - handle to the input file, and head pointers to the three lists. */

void readBike(fstream &, Bike*& head, Bike*& manuf, Bike*& id);

/* *addBike:- *Purpose: adds bike to the general list *Parameters: pointer to the first node in the list, pointer to the new node *Returns pointed to the first node in the list. *This function is overloaded with two other functions below */

Bike * addBike(Bike* head, Bike* new_bike); /* *addBike:- (optional) *Purpose: Overloaded function to add bike to the list, sorted by ID. *Note, that you have only one set of nodes. You will need to implement different *lists by different sets of pointers. * + 5 extra points. */

Bike * addBike(Bike * head_id, Bike * new_bike, order); /* *addBike:- (optional) *Purpose: Overloaded function to add bike to the list, sorted by the manufacturer. *Note that the last parameter is just a placeholder to tell compiler to call this *overloaded function. you can pass any value there, it is not used in the function. *+ 5 extra points */ Bike * addBike(Bike * head_manufacturer, Bike * new_bike, order, int);

/* *printBike:- *Purpose: Prints any list of bikes, that have not been deleted, depending on the *status, and the head pointer passed. If status is RENTED, you print only bikes *that are rented. If status is ALL, you print the entire list of (not deleted) *bikes. Note, that depending on the list, you pointer assignments should be *different. *The last part is not applicable if you choose not to implement sorted list *Parameters: *Bike* - pointer to the first node of the list of bikes. *order - needed to control pointer re-assignment. I.e. if order == ID, * you should move along the list, sorted by ID. *status - Determines which bikes to print from the list. I.e. rented, not * rented, or all. */

void printBikes(Bike*, order, status);

/*do_transact:- *Purpose: Reads the ID, number of days from the file, and depending on the status *(RENTED/NOT_RENTED) either rents bike to the person (in which case you need to * read person's name from the file, or performs return transaction. If transaction *is rented, you should also display the total cost of the rent *(number of days * cost of rent per day). *in both cases, if status of bike does not correspond to the type of the * transaction (i.e. you try to rent the bike which status is RENTED), you need to * output an appropriate message and return. */ void do_transact( fstream &, Bike*, status); /

* *del_id_bike:- *Purpose: Finds the bike by the ID in the list and sets its deleted flag to true. *Note, that you do not delete the node. You set its deleted flag to true. *Parameters: *fstream object to the file to read the bike's ID *pointer to the head of the bike's list sorted by ID. If you did not implement *the sorted list, pass there a pointer to the head of the general list. */

void del_id_bike( fstream &, Bike*);

/* del_manuf:- *Purpose: Finds the bike by the manufacturer's name in the list and sets its *deleted flag to true. *Parameters: as above. */

void del_manuf( fstream &, Bike*); /* deleteBikes:- *Purpose: To traverse the general list of bikes and deletes all the nodes in *it, releasing back the memory. It is called before your program exits. *Note, that if you implemented any dynamically allocated memory in the node, *you will need to release that memory first, before deleting the node itself. *Parameters: *pointer to the head of the general list of bikes. */ void deleteBikes(Bike *);

/* *init:- *Purpose: This function initializes the new Bike's object to all default values *(char array should be initialized to "" */

void init(Bike*); #endif /* _BIKES_H_*/

The main opens the file and reads the codes from the file, based on which it controls the process with the while loop and switch statement. All the other file reading is done in the corresponding functions. For that purpose, main passes reference to the fstream object to the called functions. Run your program with the test data file provided. Note, that if you do not implement the two extracredit functions, you will need to remove corresponding sections from that file. Do not forget to close the file, when you are done and delete all the nodes in the list.

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;
}