This is a homework that will help you with the 3rd and Final

This is a homework that will help you with the 3rd and Final Programming Assignment. For this homework, you will hand in 4 files. main.cpp, functions.h, vehicle.h, vehicle.cpp a. In your vehicle.h file, you will write the full Class Declaration. That should include public: and private: variables, as well as public member functions (as listed in PA3). b. In your vehicle.cpp file, you will list out the member function Definitions for the Vehicle class. For example: string Vehicle::getVIN( ) { return this.VIN} These are all one line member functions, so go ahead and define them (instead of just using comments) c. In your functions.h file, you will have function definitions for display, add, edit, delete, sort, read and write (note you will want to use slightly different names for your functions. In these function definitions, you will place an outline in comments of the steps you plan to take. Remember don\'t just print what, but how you plan to do it. d. In your main.cpp file, you will #include your vehicle.h (not your vehicle.cpp!), then your main should really be as simple as making function calls.

Can someone help me for this problem to write private and public class of car and dealership?

Solution

Answer:

//vehicle.h

#ifndef _vehicle_h

#define _vehicle_h

#include<string>

using namespace std;

class vehicle

{

private:

     int VIN;

     string model;

     int year;

public:

     vehicle();

     vehicle(int vin, string modelname, int makeyear);   

     void setVIN(int vin);  

     void setModel(string modelname) ;

     void setYear(int makeyear);

     int getVIN();

     string getModel() const;    

     int getYear();

    

};

#endif

//vehicle.cpp

#include<iostream>

#include<string>

#include \"vehicle.h\"

using namespace std;

vehicle::vehicle()

{

     VIN=1;

     model=\"suv\";

     year=2004;

}

vehicle::vehicle(int vin, string modelname, int makeyear)

{

     VIN=vin;

     model=modelname;

     year=makeyear;

}

void vehicle::setVIN(int vin)

{

     VIN=vin;

}

void vehicle::setModel(string modelname)

{

     model=modelname;

}

void vehicle::setYear(int makeyear)

{

     year=makeyear;

}

int vehicle::getVIN()

{

     return VIN;

}

string vehicle::getModel()const

{

     return model;

}

int vehicle::getYear()

{

     return year;

}

//functions.h

#ifndef _functions_h

#define _functions_h

#include \"vehicle.h\"

#include<iostream>

#include<vector>

#include<string>

#include<fstream>

using namespace std;

void displayVehicles(vector<vehicle>& veh)

{

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

     {

          cout<<\"Vehicle Number:\"<<veh.at(kk).getVIN()<<endl;

          cout<<\"Model:\"<<veh.at(kk).getModel()<<endl;

          cout<<\"Year:\"<<veh.at(kk).getYear()<<endl;

          cout<<\"---------------------------------------\"<<endl;

     }

}

void addVehicle(vector<vehicle>& veh)

{

     string mod;

     int vin;

     int yr;

     cout<<\"Enter vehicle VIN:\";

     cin>>vin;

     cout<<\"enter vehicle model:\";

     cin>>mod;

     cout<<\"Enter the year:\";

     cin>>yr;

     vehicle v(vin,mod,yr);

     veh.push_back(v);

}

void editVehicleInfo(vector<vehicle>& veh)

{

     string mod;

     int vin;

     int yr;

     cout<<\"Enter vin to edit vehicle info:\"<<endl;

     cin>>vin;

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

     {

          if(veh.at(kk).getVIN()==vin)

          {

              cout<<\"Enter vehicle VIN:\";

              cin>>vin;

              cout<<\"enter vehicle model:\";

              cin>>mod;

              cout<<\"Enter the year:\";

              cin>>yr;

              veh.at(kk).setVIN(vin);

              veh.at(kk).setModel(mod);

              veh.at(kk).setYear(yr);

              break;

          }

     }

}

void deleteVehicleInfo(vector<vehicle>& veh)

{

    

     int vin;

    

     cout<<\"Enter vin to delete vehicle info:\"<<endl;

     cin>>vin;

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

     {

          if(veh.at(kk).getVIN()==vin)

          {

             

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

              break;

          }

     }

}

void sortVehicleInfo(vector<vehicle>& veh)

{

     string mod;

     int vin;

     int yr;  

     for(int kk=0;kk<veh.size()-1;kk++)

     {

          for(int aa=0;aa<veh.size()-kk-1;aa++)

          {

              if(veh.at(aa).getVIN()>veh.at(aa+1).getVIN())

              {

                   vin=veh.at(aa).getVIN();

                   veh.at(aa).setVIN(veh.at(aa+1).getVIN());

                   veh.at(aa+1).setVIN(vin);

                   mod=veh.at(aa).getModel();

                   veh.at(aa).setModel(veh.at(aa+1).getModel());

                   veh.at(aa+1).setModel(mod);

                   yr=veh.at(aa).getYear();

                   veh.at(aa).setYear(veh.at(aa+1).getYear());

                   veh.at(aa+1).setYear(yr);

              }

          }

     }

}

void readFromFile(vector<vehicle>& veh)

{

     cout<<\"Enter filename:\"<<endl;

     string file;

     cin>>file;

     ifstream fID(file);

     if(fID.is_open())

     {

          string model;

          int vin;

          int yr;

          while(fID>>vin>>model>>yr)

          {

              vehicle v(vin,model,yr);

              veh.push_back(v);

          }

          fID.close();

     }

}

void writeToFile(vector<vehicle>& veh)

{

     cout<<\"Enter filename:\"<<endl;

     string file;

     cin>>file;

     ofstream fID(file);

     if(fID.is_open())

     {

          string model;

          int vin;

          int yr;

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

          {

              vin=veh.at(kk).getVIN();

              model=veh.at(kk).getModel();

              yr=veh.at(kk).getYear();

              fID<<vin<<\" \"<<model<<\" \"<<yr<<endl;

          }

          fID.close();

     }

}

#endif

//main.cpp

#include \"vehicle.h\"

#include \"functions.h\"

#include <iostream>

#include<string>

#include<vector>

#include<cstdlib>

using namespace std;

int main()

{

     vector<vehicle> veh;

     int c;

     while(1)

     {

          cout<<\"Menu:\"<<endl;

          cout<<\"1. Display\"<<endl;

          cout<<\"2. Add \ 3. Edit \ 4. Delete \ 5. Sort \ 6. Read from file \ 7. Write to file\ 8. Exit \ \"<<endl;

          cout<<\"Enter option:\"<<endl;

          cin>>c;

          if(c==8)

              break;

          switch(c)

          {

          case 1:

              displayVehicles(veh);

              break;

          case 2:

             

              addVehicle(veh);

              break;

          case 3:

              editVehicleInfo(veh);

              break;

          case 4:

              deleteVehicleInfo(veh);

              break;

          case 5:

              sortVehicleInfo(veh);

              break;

          case 6:

              readFromFile(veh);

              break;

          case 7:

              writeToFile(veh);

              break;

          default:

              cout<<\"\ \ WRONG CHOICE\"<<endl;

              break;

          }

     }

     system(\"pause\");

     return 0;

}

Sample output:

Menu:

1. Display

2. Add

3. Edit

4. Delete

5. Sort

6. Read from file

7. Write to file

8. Exit

Enter option:

1

Menu:

1. Display

2. Add

3. Edit

4. Delete

5. Sort

6. Read from file

7. Write to file

8. Exit

Enter option:

2

Enter vehicle VIN:1

enter vehicle model:hyundai

Enter the year:2004

Menu:

1. Display

2. Add

3. Edit

4. Delete

5. Sort

6. Read from file

7. Write to file

8. Exit

Enter option:

2

Enter vehicle VIN:6

enter vehicle model:suv

Enter the year:2000

Menu:

1. Display

2. Add

3. Edit

4. Delete

5. Sort

6. Read from file

7. Write to file

8. Exit

Enter option:

2

Enter vehicle VIN:3

enter vehicle model:innova

Enter the year:2005

Menu:

1. Display

2. Add

3. Edit

4. Delete

5. Sort

6. Read from file

7. Write to file

8. Exit

Enter option:

1

Vehicle Number:1

Model:hyundai

Year:2004

---------------------------------------

Vehicle Number:6

Model:suv

Year:2000

---------------------------------------

Vehicle Number:3

Model:innova

Year:2005

---------------------------------------

Menu:

1. Display

2. Add

3. Edit

4. Delete

5. Sort

6. Read from file

7. Write to file

8. Exit

Enter option:

5

Menu:

1. Display

2. Add

3. Edit

4. Delete

5. Sort

6. Read from file

7. Write to file

8. Exit

Enter option:

1

Vehicle Number:1

Model:hyundai

Year:2004

---------------------------------------

Vehicle Number:3

Model:innova

Year:2005

---------------------------------------

Vehicle Number:6

Model:suv

Year:2000

---------------------------------------

Menu:

1. Display

2. Add

3. Edit

4. Delete

5. Sort

6. Read from file

7. Write to file

8. Exit

Enter option:

3

Enter vin to edit vehicle info:

3

Enter vehicle VIN:3

enter vehicle model:qualis

Enter the year:2007

Menu:

1. Display

2. Add

3. Edit

4. Delete

5. Sort

6. Read from file

7. Write to file

8. Exit

Enter option:

1

Vehicle Number:1

Model:hyundai

Year:2004

---------------------------------------

Vehicle Number:3

Model:qualis

Year:2007

---------------------------------------

Vehicle Number:6

Model:suv

Year:2000

---------------------------------------

Menu:

1. Display

2. Add

3. Edit

4. Delete

5. Sort

6. Read from file

7. Write to file

8. Exit

Enter option:

4

Enter vin to delete vehicle info:

1

Menu:

1. Display

2. Add

3. Edit

4. Delete

5. Sort

6. Read from file

7. Write to file

8. Exit

Enter option:

1

Vehicle Number:3

Model:qualis

Year:2007

---------------------------------------

Vehicle Number:6

Model:suv

Year:2000

---------------------------------------

Menu:

1. Display

2. Add

3. Edit

4. Delete

5. Sort

6. Read from file

7. Write to file

8. Exit

Enter option:

8

Press any key to continue . . .

This is a homework that will help you with the 3rd and Final Programming Assignment. For this homework, you will hand in 4 files. main.cpp, functions.h, vehicle
This is a homework that will help you with the 3rd and Final Programming Assignment. For this homework, you will hand in 4 files. main.cpp, functions.h, vehicle
This is a homework that will help you with the 3rd and Final Programming Assignment. For this homework, you will hand in 4 files. main.cpp, functions.h, vehicle
This is a homework that will help you with the 3rd and Final Programming Assignment. For this homework, you will hand in 4 files. main.cpp, functions.h, vehicle
This is a homework that will help you with the 3rd and Final Programming Assignment. For this homework, you will hand in 4 files. main.cpp, functions.h, vehicle
This is a homework that will help you with the 3rd and Final Programming Assignment. For this homework, you will hand in 4 files. main.cpp, functions.h, vehicle
This is a homework that will help you with the 3rd and Final Programming Assignment. For this homework, you will hand in 4 files. main.cpp, functions.h, vehicle
This is a homework that will help you with the 3rd and Final Programming Assignment. For this homework, you will hand in 4 files. main.cpp, functions.h, vehicle
This is a homework that will help you with the 3rd and Final Programming Assignment. For this homework, you will hand in 4 files. main.cpp, functions.h, vehicle
This is a homework that will help you with the 3rd and Final Programming Assignment. For this homework, you will hand in 4 files. main.cpp, functions.h, vehicle
This is a homework that will help you with the 3rd and Final Programming Assignment. For this homework, you will hand in 4 files. main.cpp, functions.h, vehicle
This is a homework that will help you with the 3rd and Final Programming Assignment. For this homework, you will hand in 4 files. main.cpp, functions.h, vehicle
This is a homework that will help you with the 3rd and Final Programming Assignment. For this homework, you will hand in 4 files. main.cpp, functions.h, vehicle
This is a homework that will help you with the 3rd and Final Programming Assignment. For this homework, you will hand in 4 files. main.cpp, functions.h, vehicle

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site