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

If you just copy others I will thumb down;( Thanks appreciated. Submit Assignm P

ID: 3572588 • Letter: I

Question


If you just copy others I will thumb down;( Thanks appreciated. Submit Assignm Programming Assignment 3 Points 35 submitting a file upload Due Tuesday by 11pm File Types cpp and h For Programming Assignment 3 you will be creating a program to manage cars in a dealership. This will ag 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 wil be class based with the following UML representing the classes:

Explanation / Answer

vehicle.h

#include <string>
using namespace std;
class Dealer
{
private:
   string name;
   string address;

public:
   Dealer();
   Dealer(string iName);

   void setName(string);
   void setAddress(string);
   string getName();
   string getAddress();
  
};


class Vehicle
{
private:
   string VIN;
   string make;
   string model;
   int year;
   double price;

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

   string getVIN();
   string getMake();
   string getModel();
   int getYear();
   double getPrice();

   void setVIN(string);
   void setMake(string);
   void setModel(string);
   void setYear(int);
   void setPrice(double);

};

_________________________________________________________

vehicle.cpp

#include "vehicle.h"
using namespace std;

Dealer::Dealer(string iName){
   name = iName;
}

void Dealer::setName(string iName){
   name = iName;
}

void Dealer::setAddress(string iAddress){
   address = iAddress;
}

string Dealer::getName(){
   return name;
}

string Dealer::getAddress(){
   return address;
}

Vehicle::Vehicle(string iVIN, string iMake, string iModel, int iYear, double iPrice){
   VIN = iVIN;
   make = iMake;
   model = iModel;
   year = iYear;
   price = iPrice;
}

string Vehicle::getVIN(){
   return VIN;
}

string Vehicle::getMake(){
   return make;
}

string Vehicle::getModel(){
   return model;
}

int Vehicle::getYear(){
   return year;
}

double Vehicle::getPrice(){
   return price;
}

void Vehicle::setVIN(string iVIN){
   VIN = iVIN;
}

void Vehicle::setMake(string iMake){
   make = iMake;
}

void Vehicle::setModel(string iModel){
   model = iModel;
}

void Vehicle::setYear(int iYear){
   year = iYear;
}

void Vehicle::setPrice(double iPrice){
   price = iPrice;
}

________________________________________________

functions.h

#include "vehicle.cpp"
#include <vector>
#include <iostream>
using namespace std;

void displayInventory(std::vector<Vehicle > *vehicles){
   if(vehicles->size()==0){
       cout <<"No Vehicle Exist! "<<endl;
   }
   for(int i=0;i<vehicles->size();i++){
       cout << "Vehicle:   "<<(i+1)<<endl;
       cout << "VIN:       "<< vehicles->at(i).getVIN()<<endl;
       cout << "Make:       "<< vehicles->at(i).getMake() <<endl;
       cout << "Model:       "<< vehicles->at(i).getModel() <<endl;
       cout << "Year:       "<< vehicles->at(i).getYear() <<endl;
       cout << "Price:       $"<< vehicles->at(i).getPrice() <<endl;
   }
}

void addVehicle(std::vector<Vehicle > *vehicles){
   string iVIN, iMake, iModel;
   int iYear; double iPrice;
   cout << "Enter the Vehicle Details "<<endl;
   cout << "VIN:   "; cin >> iVIN;
   cout << "Make:   "; cin >> iMake;
   cout << "Model:   "; cin >> iModel;  
   cout << "Year:   "; cin >> iYear;
   cout << "Price:   $"; cin >> iPrice;
   Vehicle vehicle(iVIN, iMake, iModel, iYear, iPrice);
   vehicles->push_back(vehicle);
   // return vehicles;
}

void updateVehicle(std::vector<Vehicle > *vehicles){
   displayInventory(vehicles);
   int index;
   cout << "Enter the Vehicle Number: "; cin >> index;
   while(index<1 || index > vehicles->size() ){
       cout << "Enter a valid Vehicle Number: "; cin >> index;
   }
   int option = 1;
   while(option>0 && option<6){
       cout <<"1. VIN"<<endl;
       cout <<"2. Make"<<endl;
       cout <<"3. Model"<<endl;
       cout <<"4. Year"<<endl;
       cout <<"5. Price"<<endl;
       cout <<"0. Go Back" <<endl;
       cout << "What do you want to edit: ";
       cin >> option;
       switch(option){
           case 1:
               {string iVIN;
               cout << "new VIN:   "; cin >> iVIN;
               vehicles->at(index-1).setVIN(iVIN);
               break;}
           case 2:
               {string iMake;
               cout << "new Make:   "; cin >> iMake;
               vehicles->at(index-1).setMake(iMake);
               break;}
           case 3:
               {string iModel;
               cout << "new Model:   "; cin >> iModel;
               vehicles->at(index-1).setModel(iModel);
               break;}
           case 4:
               {int iYear;
               cout << "new Year:   "; cin >> iYear;
               vehicles->at(index-1).setYear(iYear);
               break;}
           case 5:
               {double iPrice;
               cout << "new Price:   "; cin >> iPrice;
               vehicles->at(index-1).setPrice(iPrice);
               break;}
       }
   }
}

void deleteVehicle(std::vector<Vehicle > *vehicles){
   displayInventory(vehicles);
   int index=0;
   cout << "Enter the Vehicle Number: "; cin >> index;
   while(index<1 || index>vehicles->size()){
       cout << "Enter a valid Vehicle Number: "; cin >> index;
   }
   vehicles->erase(vehicles->begin()+index-1);
}

void sortByVIN(std::vector<Vehicle > *vehicles){
   int n = vehicles->size();
   for(int j=0;j<n;j++){
       int iMin = j;
       for(int i=j+1;i<n;i++){
           if(vehicles->at(i).getVIN() < vehicles->at(iMin).getVIN()){
               iMin =i;
           }
       }
       if(iMin!=j){
           Vehicle tmp = vehicles->at(j);
           vehicles->at(j) = vehicles->at(iMin);
           vehicles->at(iMin) = tmp;
       }
   }
}

void searchByModel(std::vector<Vehicle > *vehicles){
   string iModel;
   cout << "Model:   ";cin >> iModel;
   for(int i=0;i<vehicles->size();i++){
       if(vehicles->at(i).getModel().compare(iModel)==0){
           cout << "Vehile Number with Model "<< iModel <<": "<<i+1<<endl;
           return;
       }
   }
   cout <<"No vehicle with this model exist."<<endl;
}

void showMenu(){
   cout <<"Main Menu"<<endl;
   cout <<"1. Display Invetory"<<endl;
   cout <<"2. Add a Vehicle"<<endl;
   cout <<"3. Update a Vehicle"<<endl;
   cout <<"4. Delete a Vehicle"<<endl;
   cout <<"5. Sort Invetory by VIN"<<endl;
   cout <<"6. Search Invetory by Model"<<endl;
   cout <<"0. Exit the System"<<endl;
   cout << "Enter your choice: ";
}

_______________________________________

main.cpp

#include <vector>
#include "functions.h"
int main(){
   int option = 1;
   std::vector<Vehicle > *vehicles = new vector<Vehicle>();
   while(option>0 && option<7){
       showMenu();
       cin >> option;
       switch(option){
           case 1:
               {
                   displayInventory(vehicles);
                   break;
               }
           case 2:
               {
                   addVehicle(vehicles);
                   break;
               }
           case 3:
               {
                   updateVehicle(vehicles);
                   break;
               }
           case 4:
               {
                   deleteVehicle(vehicles);
                   break;
               }
           case 5:
               {
                   sortByVIN(vehicles);
                   break;
               }
           case 6:
               {
                   searchByModel(vehicles);
               }
       }
   }

}

___________________________________________

Sample Output

//output was large so hard to take all screen shots

Rahuls-MacBook-Air:Vehicle RahulPatidar$ g++ main.cpp

Rahuls-MacBook-Air:Vehicle RahulPatidar$ ./a.out

Main Menu

1. Display Invetory

2. Add a Vehicle

3. Update a Vehicle

4. Delete a Vehicle

5. Sort Invetory by VIN

6. Search Invetory by Model

0. Exit the System

Enter your choice: 2

Enter the Vehicle Details

VIN:   xyz123

Make:   xyz

Model:   abc

Year:   2011

Price:   $12312.12

Main Menu

1. Display Invetory

2. Add a Vehicle

3. Update a Vehicle

4. Delete a Vehicle

5. Sort Invetory by VIN

6. Search Invetory by Model

0. Exit the System

Enter your choice: 2

Enter the Vehicle Details

VIN:   abc789

Make:   abc

Model:   xyz

Year:   2016

Price:   $123.24

Main Menu

1. Display Invetory

2. Add a Vehicle

3. Update a Vehicle

4. Delete a Vehicle

5. Sort Invetory by VIN

6. Search Invetory by Model

0. Exit the System

Enter your choice: 2

Enter the Vehicle Details

VIN:   asd121

Make:   asd

Model:   asd

Year:   2014

Price:   $123

Main Menu

1. Display Invetory

2. Add a Vehicle

3. Update a Vehicle

4. Delete a Vehicle

5. Sort Invetory by VIN

6. Search Invetory by Model

0. Exit the System

Enter your choice: 3

Vehicle:   1

VIN:       xyz123

Make:       xyz

Model:       abc

Year:       2011

Price:       $12312.1

Vehicle:   2

VIN:       abc789

Make:       abc

Model:       xyz

Year:       2016

Price:       $123.24

Vehicle:   3

VIN:       asd121

Make:       asd

Model:       asd

Year:       2014

Price:       $123

Enter the Vehicle Number: 4

Enter a valid Vehicle Number: 3

1. VIN

2. Make

3. Model

4. Year

5. Price

0. Go Back

What do you want to edit: 3

new Model:   xyz

1. VIN

2. Make

3. Model

4. Year

5. Price

0. Go Back

What do you want to edit: 0

Main Menu

1. Display Invetory

2. Add a Vehicle

3. Update a Vehicle

4. Delete a Vehicle

5. Sort Invetory by VIN

6. Search Invetory by Model

0. Exit the System

Enter your choice: 2

Enter the Vehicle Details

VIN:   as

Make:   asdhs

Model:   asdas

Year:   2000

Price:   $21321

Main Menu

1. Display Invetory

2. Add a Vehicle

3. Update a Vehicle

4. Delete a Vehicle

5. Sort Invetory by VIN

6. Search Invetory by Model

0. Exit the System

Enter your choice: 1

Vehicle:   1

VIN:       xyz123

Make:       xyz

Model:       abc

Year:       2011

Price:       $12312.1

Vehicle:   2

VIN:       abc789

Make:       abc

Model:       xyz

Year:       2016

Price:       $123.24

Vehicle:   3

VIN:       asd121

Make:       asd

Model:       xyz

Year:       2014

Price:       $123

Vehicle:   4

VIN:       as

Make:       asdhs

Model:       asdas

Year:       2000

Price:       $21321

Main Menu

1. Display Invetory

2. Add a Vehicle

3. Update a Vehicle

4. Delete a Vehicle

5. Sort Invetory by VIN

6. Search Invetory by Model

0. Exit the System

Enter your choice: 4

Vehicle:   1

VIN:       xyz123

Make:       xyz

Model:       abc

Year:       2011

Price:       $12312.1

Vehicle:   2

VIN:       abc789

Make:       abc

Model:       xyz

Year:       2016

Price:       $123.24

Vehicle:   3

VIN:       asd121

Make:       asd

Model:       xyz

Year:       2014

Price:       $123

Vehicle:   4

VIN:       as

Make:       asdhs

Model:       asdas

Year:       2000

Price:       $21321

Enter the Vehicle Number: 4

Main Menu

1. Display Invetory

2. Add a Vehicle

3. Update a Vehicle

4. Delete a Vehicle

5. Sort Invetory by VIN

6. Search Invetory by Model

0. Exit the System

Enter your choice: 1

Vehicle:   1

VIN:       xyz123

Make:       xyz

Model:       abc

Year:       2011

Price:       $12312.1

Vehicle:   2

VIN:       abc789

Make:       abc

Model:       xyz

Year:       2016

Price:       $123.24

Vehicle:   3

VIN:       asd121

Make:       asd

Model:       xyz

Year:       2014

Price:       $123

Main Menu

1. Display Invetory

2. Add a Vehicle

3. Update a Vehicle

4. Delete a Vehicle

5. Sort Invetory by VIN

6. Search Invetory by Model

0. Exit the System

Enter your choice: 5

Main Menu

1. Display Invetory

2. Add a Vehicle

3. Update a Vehicle

4. Delete a Vehicle

5. Sort Invetory by VIN

6. Search Invetory by Model

0. Exit the System

Enter your choice: 1

Vehicle:   1

VIN:       abc789

Make:       abc

Model:       xyz

Year:       2016

Price:       $123.24

Vehicle:   2

VIN:       asd121

Make:       asd

Model:       xyz

Year:       2014

Price:       $123

Vehicle:   3

VIN:       xyz123

Make:       xyz

Model:       abc

Year:       2011

Price:       $12312.1

Main Menu

1. Display Invetory

2. Add a Vehicle

3. Update a Vehicle

4. Delete a Vehicle

5. Sort Invetory by VIN

6. Search Invetory by Model

0. Exit the System

Enter your choice: 6

Model:   xyz

Vehile Number with Model xyz: 1

Main Menu

1. Display Invetory

2. Add a Vehicle

3. Update a Vehicle

4. Delete a Vehicle

5. Sort Invetory by VIN

6. Search Invetory by Model

0. Exit the System

Enter your choice: 0

Rahuls-MacBook-Air:Vehicle RahulPatidar$

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