Question

For Programming Assignment 3 you will be creating
For Programming Assignment 3 you will be creating
For Programming Assignment 3 you will be creating
For Programming Assignment 3 you will be creating

For Programming Assignment 3 you will be creating
For Programming Assignment 3 you will be creating
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Solution:

Note: The function names and variables are used as given in the problem

C++ files for the problem

//VEHICLE.H
//Vehicle.h file
#ifndef vehicleH
#define vehicleH
#include <iostream>
#include <string>

using namespace std;

//Class Vehicle definition
class Vehicle

{
//private scope class member variables
private:

     string VIN;
     string make;
     string model;
     int year;
     double price;

//public functions of the class Vehicle  
public:

  
   //Constructors
     Vehicle(string iVIN,string iMake,string iModel,int iYear,double iPrice);
   Vehicle();
  
   //getVIN() function
     string getVIN();
   //getMake() function
     string getMake();
   //getModel() function
     string getModel();
   //getYear() function of return type int
     int getYear();
   //getPrice() function of return type double
     double getPrice();
   //setMake() function prototype
     void setMake(string input);
   //setVIN() function prototype
     void setVIN(string input);
   //setModel() function header
     void setModel( string input);
   //setYear() function definition
     void setYear(int input);
   //setpRice function definition
     void setPrice(double input);

};

#endif

//FUNCTIONS.H
//functions.h file
//functions.h file
//header files inclusion
#ifndef functionsH
#define functinosH
#include <iostream>
#include <string>
#include <fstream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include "vehicle.h"

//Addvehicle function definition
void addVehicle(vector<Vehicle> &vehList)

{

     string VIN,carmake,carmodel;
   int makeyear;
   double vehprice;

     cout<<"Enter the VIN of the vehicle: ";

     cin>>VIN;

     cout<<"Enter the car make: ";

     cin>>carmake;

     cout<<"Enter the car model: ";

     cin>>carmodel;

     cout<<"Enter the make year: ";

     cin>>makeyear;

     cout<<"Enter the vehicle price: ";

     cin>>vehprice;

     Vehicle *insertveh=new Vehicle(VIN,carmake,carmodel,makeyear,vehprice);

     vehList.push_back(*insertveh);

     cout<<"New vehicle has been added"<<endl;

}

void display(vector<Vehicle> &vehList)

{
   //if no vehicle found
     if(vehList.size()==0)

     {

          cout<<"No records found"<<endl;
          return;

     }

     cout<<endl<<"VEHICLE DATA"<<endl;

   //the for loop to display the vehicles
     for ( int vi = 0; vi <vehList.size() ; vi++)

     {
       //Display the vehicle data
          cout <<"Vehicle:"<<vi+1<<endl;
          cout<<"VIN:"<< vehList[vi].getVIN()<<endl;
          cout<<"Make: "<<vehList[vi].getMake()<<endl;
          cout<<"Model: "<<vehList[vi].getModel()<<endl;
          cout<<"year: "<<vehList[vi].getYear()<<endl;
          cout<<"Price: "<< std::fixed<<setprecision(2)<<vehList[vi].getPrice()<<endl;
    }
     cout<<endl;
}

void Update(vector<Vehicle> &vehList)

{

     bool status=false;

     string tempVIN;

     string carMake,newmodel;
   int newyear;
   double newprice;

     cout<<"Enter the VIN of the vehicle:";

     cin>>tempVIN;

     for(int vi=0;vi<vehList.size();vi++)

     {

          if(tempVIN==vehList[vi].getVIN())

          {
           //read the data to update
              cout<<"Enter the make to update: ";
              cin>>carMake;
              vehList[vi].setMake(carMake);
          
          
              cout<<"Enter the model: ";

              cin>>newmodel;

              vehList[vi].setModel(newmodel);

              cout<<"Enter new year: ";

              cin>>newyear;

              vehList[vi].setYear(newyear);

              cout<<"Enter the price: ";

              cin>>newprice;

              vehList[vi].setPrice(newprice);

              cout<<"UYpdated the vehicle data!!1"<<endl;

              status=true;

              break;

          }

     }

     if(status==false)

     cout<<"No vehicle found with the given VIN"<<endl;

}

//Sort function
void sortInventory(vector<Vehicle> &vehList)

{

     cout<<"Sorted"<<endl;

}

//Delete vehicle functin definition
void deleteVehicle(vector<Vehicle> &vehList)

{

     bool status=false;

     string tempVIN;

     cout<<"Enter the VIn of the vehicle: ";

     cin>>tempVIN;

     for(int vi=0;vi<vehList.size();vi++)

     {

          if(tempVIN==vehList[vi].getVIN())

          {

              vehList.erase(vehList.begin()+vi);

              status=true;

              break;

          }

     }

     if(status==false)

     cout<<" Vehicle not found"<<endl;

     cout<<"Deleted!!!"<<endl;

}


//Search function
void searchInventory(vector<Vehicle> &vehList)

{

     bool status=false;

     string tempVIN;

     cout<<"Enter VIN to search: "<<endl;

     cin>>tempVIN;

     for(int vi=0;vi<vehList.size();vi++)

     {

          if(tempVIN==vehList[vi].getVIN())

          {

              cout<<"Vehicle is in list: details"<<endl;

              cout<<"VIN:"<< vehList[vi].getVIN()<<endl;

              cout<<"Make: "<<vehList[vi].getMake()<<endl;

              cout<<"Model: "<<vehList[vi].getModel()<<endl;

              cout<<"year: "<<vehList[vi].getYear()<<endl;

              cout<<"Price: "<< std::fixed<<setprecision(2)<<vehList[vi].getPrice()<<endl;

              status=true;

              break;

          }

     }

     if(status==false)

     cout<<"No vehicle found"<<endl;

}

//function to read from the file
void readInventory(vector<Vehicle> &vehList)

{

     string mystring;

     ifstream inputFile;
   //open the file to read
     inputFile.open("Invent.txt");

     while(!inputFile.eof())

     {

          inputFile>>mystring;

          cout<<"VIN:";

          cout<<mystring<<endl;

          inputFile>>mystring;

          cout<<"Make:";

          cout<<mystring<<endl;

          inputFile>>mystring;

          cout<<"Model:";

          cout<<mystring<<endl;

          inputFile>>mystring;

          cout<<"Year:";

          cout<<mystring<<endl;

          inputFile>>mystring;

          cout<<"Price:";

          cout<<mystring<<endl;

          inputFile>>mystring;

     }

     cout<<endl;

}

//Function to write to a file
void writeInventory(vector<Vehicle> &vehList)

{

     ofstream outputfilePoint;

     outputfilePoint.open("Invent.txt");

     cout<<endl<<"Vehicle data"<<endl;

     for ( int vi = 0; vi <vehList.size() ; vi++)

     {

          outputfilePoint<<vehList[vi].getVIN()<<"   ";

          outputfilePoint<<vehList[vi].getMake()<<" ";

          outputfilePoint<<vehList[vi].getModel()<<" ";

          outputfilePoint<<vehList[vi].getYear()<<" ";

          outputfilePoint<<vehList[vi].getPrice()<<" ";

          outputfilePoint<<"\n";

    }

     cout<<endl;

     outputfilePoint.close();

     cout<<"Data saved to the file Invent.txt"<<endl;

}

#endif

//VEHICLE.CPP

//Vehicle.cpp file
#include "vehicle.h"

Vehicle::Vehicle(string VINinput,string MakeInput,string ModelInput,int YearIInput,double PriceInput)

     {

          VIN=VINinput;

          make=MakeInput;

          model=ModelInput;

          year=YearIInput;

          price=PriceInput;

     }

   //default constructor
     Vehicle::Vehicle()

     {

          VIN="";

          make="";

          model="";

          year=0;

          price=0.0;

     }

   //function getVIN() definition
     string Vehicle::getVIN()

     {

          return VIN;

     }
   //function getMake() definition

     string Vehicle::getMake()

     {

          return make;

     }

   //function getnodel definition
     string Vehicle::getModel()

     {

          return model;

     }
  
   //function getYear definition
     int Vehicle::getYear()

     {

          return year;

     }
  
   //function getprice definition
     double Vehicle:: getPrice()

     {

          return price;

     }

   //function setVIN definition
     void Vehicle::setVIN(string input)

     {

          VIN=input;

     }

   //function setMake definition
     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;

     }

  
//MAIN.CPP
//driver main.cpp file
#include <iostream>
#include "vehicle.h"
#include<vector>
#include "functions.h"

using namespace std;

int main()

{
     vector<Vehicle> vList;
     int mych;
     while(true)

     {

     cout<<"MENU"<<endl;

     cout<<"1.Display Inventory"<<endl<<"2.Add a vehicle"<<endl
   cout<<"3.Update a vehicle"<<endl<<"4.Delete a vehicle"<<endl
   cout<<"5.Sort inventory by VIN"<<endl<<"6.Search inventory by Model"<<endl;
     cout<<"7.Read inventory from file"<<endl<<"8.Write inventory to file"<<endl;

     cout<<"Enter the function: ";

     cin>>mych;

   //switch to hande the choices
     switch(mych)

     {

     case 1:

              display(vList); break;

     case 2:

              addVehicle(vList); break;

     case 3:

              Update(vList);break;

     case 4:

              deleteVehicle(vList);break;

     case 5:

              sortInventory(vList);break;

     case 6:

              searchInventory(vList);break;

     case 7:

              readInventory(vList);break;

     case 8:

              writeInventory(vList);break;

     }

     }

   //for visual studio console freze
     system("pause");

     return 0;

}

Sample Output Run:

돋 causers1302330documents\visual studio 2010\Projectswehicle\Debug\vehicle.exe New vehicle has been added MENU 1-Display Inve

Sample Input file:

Invent.txt X main.cpp vehicle.cpp functions.h vehicle.h V F FORD 2015 50000.2 D DD ASDSA 2017 2000.

Add a comment
Know the answer?
Add Answer to:
For Programming Assignment 3 you will be creating a program to manage cars in a dealership....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I need an OUTLINE ONLY (pseudocode/comments). DO NOT DO THE PROGRAMMING ASSIGNMENT. Part I: PA3 Outline...

    I need an OUTLINE ONLY (pseudocode/comments). DO NOT DO THE PROGRAMMING ASSIGNMENT. Part I: PA3 Outline (10 points). Create an outline in comments/psuedocode for the programming assignment below. Place your comments in the appropriate files: main.cpp, functions.h, dealer.cpp, dealer.h, dealer.cpp (as noted below). Place into a file folder named LastnamePA3, the zip the content and hand in a zip file to Canvas. Part II: PA3: Car Dealership (40 points) For Programming Assignment 3 you will be creating a program to...

  • Wolfie's Car Repair Shop For this assignment you will be completing a program that manages cars...

    Wolfie's Car Repair Shop For this assignment you will be completing a program that manages cars and car repairs at Wolfie's Car Repair Shop. The program is menu-driven. The menu can be found in Homework.Driver.java. Provided in that file is a series of methods that begin with the prefix main_. Those methods request input from the user and then call methods from the class CarRepairShop. It is these methods in the CarRepairShop that you will be implementing for homework. In...

  • Java Create a program for a car dealer to use where you have a class for...

    Java Create a program for a car dealer to use where you have a class for Salesman, Cars, and the Records of sale. 4 salesman and 4 cars to start with but have array size for 50 cars, have space for 100 records in array. The program should have 6 options in the menu. buy car, sell car, show inventory, show salesman, show sales records, and exit. Salesman class - Name, ID number, Commision rate, Total commisions earned, Totals number...

  • Need help working through CLion: Description: For this assignment you will create a program to manage...

    Need help working through CLion: Description: For this assignment you will create a program to manage phone contacts. Your program will allow the user to add new phone contacts, display a list of all contacts, search for a specific contact by name, delete a specific contact. Your program should provide the user with a console or command line choice menu about possible actions that they can perform. The choices should be the following: 1. Display list of all contacts. 2....

  • Use your Car class from the previous Programming Assignment. For this assignment, create a new class...

    Use your Car class from the previous Programming Assignment. For this assignment, create a new class that represents a Used Car Dealership. Your Java program will simulate an inventory system for the dealership, where the employees can manage the car information. Start by creating an array of 10 cars, with an "ID" of 0 through 9, and use the default constructor to create each car. For example, the third car in an array called cars would have ID 2. You...

  • C++ program Write a C++ program to manage a hospital system, the system mainly uses file...

    C++ program Write a C++ program to manage a hospital system, the system mainly uses file handling to perform basic operations like how to add, edit, search, and delete record. Write the following functions: 1. hospital_menu: This function will display the following menu and prompt the user to enter her/his option. The system will keep showing the menu repeatedly until the user selects option 'e' from the menu. Arkansas Children Hospital a. Add new patient record b. Search record c....

  • Write a C++ program to manage a Point of Sale System for a Supermarket. The main...

    Write a C++ program to manage a Point of Sale System for a Supermarket. The main user is an employee at the Supermarket. Build Specifications (36 points) 1. The system should load a catalog of all items that the store sells. 2. A user can search the inventory: The user of the system can search the inventory by using the name of the item or by category. 3. A user can sell items once they are found. Or can sell...

  • For Java Program In this lab you will gain experience using all the concepts we learned...

    For Java Program In this lab you will gain experience using all the concepts we learned to this point, which include classes, methods, collections, and file input/output. Also, you will gain experience in team programming. This assignment will be completed by teams of 2. Each member must complete an equal amount of the work in order to receive credit for this assignment. You must write the programmer’s name in a comment for each method you write. You need to create...

  • Java - Car Dealership Hey, so i am having a little trouble with my code, so...

    Java - Car Dealership Hey, so i am having a little trouble with my code, so in my dealer class each of the setName for the salesman have errors and im not sure why. Any and all help is greatly appreciated. package app5; import java.util.Scanner; class Salesman { private int ID; private String name; private double commRate; private double totalComm; private int numberOfSales; } class Car { static int count = 0; public String year; public String model; public String...

  • DESCRIPTION Create a C++ program to manage phone contacts. The program will allow the user to...

    DESCRIPTION Create a C++ program to manage phone contacts. The program will allow the user to add new phone contacts, display a list of all contacts, search for a specific contact by name, delete a specific contact. The program should provide the user with a console or command line choice menu about possible actions that they can perform. The choices should be the following: 1. Display list of all contacts. 2. Add a new contact. 3. Search for a contact...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT