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

For Programming Assignment 3 you will be creating a program to manage a car deal

ID: 3763546 • Letter: F

Question

For Programming Assignment 3 you will be creating a program to manage a car dealership. This will again be a menu driven system. The following is your menu:

1.Display Inventory

2.Add a vehicle

3.Update a vehicle

4.Delete a vehicle

5.Sort inventory by VIN

6.Search inventory by Model

7.Read inventory from file

8.Write inventory to file and exit

Your program will be class based with the following UML representing the class:

Vehicle

- VIN:string

- make:string

- model:string

- year:int

- price:double

+ Vehicle(iVIN:string, iMake:string, iModel:string, iYear:int, iPrice:double)

+ Vehicle( )

+ getVIN( ):string

+ getMake( ):string

+ getModel( ):string

+ getYear( ):int

+ getPrice( ):double

+ setVIN(input:string):void

+ setMake(input:string):void

+ setModel(input:string):void

+ setYear(input:int):void

+ setPrice(input:double):void

You will have four files for your program (I want these file names!): main.cpp, functions.h, vehicle.h, vehicle.cpp.

main.cpp: this will be your driver file.

functions.h: this will contain your global functions for each of the menu items (display, addVehicle, deleteVehicle, updateVehicle, etc).

vehicle.h: this will contain the class declaration.

vehicle.cpp: this will contain the class implementation.

You will be storing your vehicle objects in a vector. In the main function, you will create a vector of vehicles with an initial size of zero (0). When the menu options display, delete, edit, sort, or search are called, you will have to check your vector and ensure that it has a vehicle in it before the function continues (error checking).

You will not have any global variables.

Each menu item will have a corresponding function, and the definition of the function will be found in the file functions.h. Each function will only have one parameter, the vector. All I/O will be done in the functions and not in main (expect asking for what menu option the user wants).

The following are the details for each of your menu options:

1. You will display each vehicle, using the following format:

Vehicle: #

VIN: VVVV

Make: MMMM

Model: MMMM

Year: YYYY

Price: $D.CC

The bold face letters represent the values for the individual vehicle, and it doesn’t have to be bolded. Notice the tab stop between the label and the value. Also notice that there is a dollar sign and decimal for the price. Lastly, for Vehicle: #, the pound sign represents the vehicle position number in the vector (starting at 1 not 0), which will be 1, 2, 3 … and so on.

2. You will ask the user for all of the information to add the vehicle and then you will add it to the vector.

3. You will display the vehicles and then ask the user which vehicle to edit; they will give you the index number (starting at 1). Check to ensure they gave you a valid entry, then prompt for which item they want to edit (year, make, model, price, or VIN). Once they make their selection prompt for the new information, then return to the main menu.

4. You will display the vehicles and then ask the user which vehicle to delete: they will give you the index number (starting at 1). You will then check to ensure they gave you a valid entry and then remove that vehicle from the vector.

5. You will sort the vector by VIN number (when sort is done, the vector in main will be sorted by VIN number).

6. You will ask the user for a make, then search the vector for that vehicle. You will return the first matching entry’s index number or an appropriate message if not found.

7. You will read the inventory from a file called inventory.dat, which is NOT provided for you (you will need to make your own to start with). The data is stored in the same order as listed above and it is newline delimited.

8. You will write the entire inventory out to a file called inventory.dat and then exit the program.

Explanation / Answer

Answer:

/***vehicle.h****/

#include <iostream>

#include <string>

using namespace std;

#ifndef vehicle_HEADER

#define vehicle_HEADER

class vehicle

{

private:

     string vin;

     string make;

     string model;

     int year;

     double price;

public:

     vehicle();

     vehicle(string, string, string, int, double);

     string getvin() const;

     string getmake() const;

     string getmodel() const;

     int getyear() const;

     double getprice() const;

     void setvin(string input);

     void setmake( string input);

     void setmodel( string input);

     void setyear(int year);

     void setprice(double price);

};

#endif

/***vehicle.cpp****/

#include "vehicle.h"

vehicle::vehicle()

{

vin = "123";

make = "honda";

model= "2010";

year=2015;

price=10000;

}

vehicle::vehicle( string iVin, string iMake, string iModel, int iYear, double iPrice)

{

vin = iVin;

make = iMake;

model = iModel;

year = iYear;

price = iPrice;

}

void vehicle::setvin(string input )

{

vin=input;

}

void vehicle::setmake( string input)

{

make=input;

}

void vehicle::setmodel( string input)

{

model=input;

}

void vehicle::setyear(int input)

{

year=input;

}

void vehicle::setprice(double input)

{

price=input;

}

string vehicle::getvin() const

{

return vin;

}

string vehicle::getmake() const

{

return make;

}

string vehicle::getmodel() const

{

return model;

}

int vehicle::getyear() const

{

return year;

}

double vehicle::getprice() const

{

return price;

}

/***functions.h****/

#ifndef FUCNTION_H

#define FUCNTION_H

#include <iostream>

#include <string>

#include <stdlib.h>

#include <fstream>

#include "vehicle.cpp"

#include "vehicle.h"

#include <vector>

using namespace std;

vector<vehicle> veh(10);

int inInd;

//DISPLAY VEHICLE INFORMATION

void displayInventory()

{

     cout<<"DISPLAYING THE VEHICLES INFORMATION IN THE INVENTORY:"<<endl;

     for(int k1 = 0; k1 < veh.size(); k1++)

     {

          cout << "VIN:"<<veh[k1].getvin();

          cout << " MAKE:"<<veh[k1].getmake();

          cout << " MODEL: "<<veh[k1].getmodel();

          cout << " YEAR:"<<veh[k1].getyear();

          cout << " PRICE: "<<veh[k1].getprice();

          cout<<endl;

     }

}

//ADD VEHICLES TO THE INVENTORY

void addToInventory()

{

     int useIn;

string vin;

    string make;

    string model;

    int year;

    double price;

     int cntIn=0;

    

     do

     {

          //GET MODEL,VIN,MAKE,YEAR,PRICE OF THE VEHICLE THEN ADD IT TO THE INVENTORY

    cout << PLEASE ENTER DETAILS n " << endl;

    cout << "ENTER VEHICLE NUMBER. " <<endl;

    cin >> vin;

    cout << "ENTR VEHICLE MAKE ";

    cin >> make;

    cout << "ENTR VEHICLE MODEL ";

    cin >> model;

    cout << "ENTER YEAR ";

    cin >> year;

    cout << "ENTER PRICE ";

    cin >> price;

     veh.push_back(vehicle(vin,make,model,year,price));

    cntIn++;

     //ASK USER WHETHER THEY WANT TO ADD ONE MORE VEHICLE IN THE INVENTORY

    cout << "DO YOU WANT TO ENTER DATA ONCE AGAIN(1/2) ";

    cin >> useIn;

     }while ((useIn) == 1&&cntIn<=10);

}

//UPDATE THE VEHICLE DETAILS IN THE INVENTORY

void updateInventory()

{

     string vin;

    string make;

    string model;

    int year;

    double price;

     int usINP;

     cout << "UPDATION OF VEHICLE IN THE INVENTORY. ";

     //GET THE INDEX NUMBER OF VEHICLE TO UPDATE

     cout << "SELECT AN INDEX NUMBER: ";

     displayInventory();

     cin >> inInd;

     inInd = inInd - 1;

     //WHAT INFORMATION THEY WANT TO UPDATE

     cout << "WHAT DO YOU WANT TO UPDATE? ";

     cout << "1: Vehicle VIN ";

     cout << "2: Vehicle MAKE ";

     cout << "3: Vehicle MODEL ";

     cout << "4: Vehicle YEAR ";

     cout << "5: Vehicle PRICE ";

     cin>>usINP;

     switch (usINP)

     {

     case 1:

          cout << "ENTER VIN: " << endl;

          cin>>vin;

          veh[inInd].setvin(vin);

    break;

     case 2:

          cout << "ENTER MAKE: " << endl;

          cin >>make;

          veh[inInd].setmake(make);

          break;

     case 3:

          cout << "ENTER MODEL: " << endl;

          cin >> model;

          veh[inInd].setmodel(model);

          break;

     case 4:

          cout << "ENTER UPDATED YEAR: " << endl;

          cin >>year;

          veh[inInd].setyear(year);

          break;

     case 5:

          cout << "ENTER NEW PRICE: " << endl;

          cin >> price;

          veh[inInd].setprice(price);

          break;

     default:

          cout << "INVALID CHOICEn";

          break;

     }

}

//DELETE A VEHICLE FROM THE INVENTORY

void deleteInventory()

{

          cout << "DELETING INVENTORY ";

          cout << "SELECT AN INDEX TO DELETE AN inventory: ";

          displayInventory();

          cin >> inInd;

          inInd = inInd - 1;

          veh.erase(veh.begin()+inInd);

}

//SORT VEHICLES IN THE INVENTORY BY VIN

void sortVehicle()

{

          vehicle tempVeh;

          int vehSize = veh.size();

          for (int k1 = 0; k1 < vehSize; k1++)

          {

              if (veh[k1 + 1].getvin() < veh[k1].getvin())

              {

                   tempVeh = veh[k1];

                   veh[k1] = veh[k1 + 1];

                   veh[k1 + 1] = tempVeh;

              }

          }

}

//SEARCH THE INVENTORY FOR THE GIVEN MODEL

void searchInventory()

{

    int vehSize = veh.size();

     string sea_Model;

     cout << "ENTER THE MODEL YOU WANT TO SEARCH " << endl << endl;

     cin >> sea_Model;

     for (int k1 = 0; k1< vehSize; k1++)

     {

          if (veh[k1].getmake() ==sea_Model)

          {

              cout << "MODEL IS FOUND AT "<<k1<<endl;

          }

     }

}

//WRITE VEHICLE DETAILS INTO FILE

void writeInventory()

{

     ofstream invFile("inventoryVehicle.txt");

     string vin;

    string make;

    string model;

    int year;

    double price;

     for(int k1=0;k1<veh.size();k1++)

     {

          vin=veh[k1].getvin();

          make=veh[k1].getmake();

          model=veh[k1].getmodel();

          year=veh[k1].getyear();

          price=veh[k1].getprice();

          invFile<<vin<<" "<<make<<" "<<model<<" "<<year<<" "<<price<<endl;

     }

}

//READ VEHICLE INFORMATION FROM FILE AND DISPLAY IT

void readInventory()

{

     ifstream invFile("inventoryVehicle.txt");

     string vin;

    string make;

    string model;

    int year;

    double price;

     while(invFile>>vin>>make>>model>>year>>price)

     {

         

          cout<<vin<<" "<<make<<" "<<model<<" "<<year<<" "<<price<<endl;

     }

}

#endif

/***MAIN.CPP****/

#include "iostream"

#include "functions.h"

#include <vector>

#include <string>

#include <fstream>

using namespace std;

int main()

{

     int usINP;

     do

     {

          //menu to the inventory program

          cout << "Please select an operation: ";

          cout << "1: DISPLAY INVENTORY ";

          cout << "2: ADD A VEHICLE ";

          cout << "3: UPDATE A VEHICLE ";

          cout << "4: DELETE A VEHICLE ";

          cout << "5: SORT INVENTORY BY VIN ";

          cout << "6: SEARCH INVENTORY FROM MODEL ";

          cout << "7: READ INVENTORY FROM FILE ";

          cout << "8: WRITE INVENTORY TO FILE AND EXIT ";

          cin >> usINP;

          switch (usINP)

          {

          case 1:

              displayInventory();    

              break;

          case 2:      

              addToInventory();      

              break;

          case 3:         

              updateInventory();    

              break;

          case 4:         

              deleteInventory();    

              break;

          case 5:         

              sortVehicle();    

              break;

          case 6:         

             searchInventory();       

              break;

          case 7:

              readInventory();

              break;

          case 8:

              writeInventory();

              break;

          default:

              cout<<"CHOICE IS NOT VALID"<<endl;

              break;

          }

     } while (usINP <= 8);

     system("pause");

     return 0;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote