Question: Pls do option 4 and 5. #ifndef _FUNCTIONS_H #define _FUNCTIONS_H #include Dealer.h #include #include #include #include #include using namespace std; void Read(vector &dealers){ ifstream ifs(in.txt);

Pls do option 4 and 5.

 #ifndef _FUNCTIONS_H #define _FUNCTIONS_H #include "Dealer.h" #include  #include  #include  #include  #include  using namespace std; void Read(vector&dealers){ ifstream ifs("in.txt"); string vin,make,model; int year, dealerNumber, size; dealerNumber = 0; double price; string dealerName = ""; int dealerCount = 0; Dealer *ptr = new Dealer[10]; if (ifs.is_open()){ while (getline(ifs, dealerName)){ ifs >> dealerNumber; ifs >> size; ifs.ignore(256, ' '); Car *car = new Car[size]; int i = 0; while (i < size) { getline(ifs, vin); getline(ifs, make); getline(ifs, model); ifs >> year; ifs >> price; ifs.ignore(256, ' '); *(car + i) = Car(vin, make, model,year, price); i++; } ptr[dealerCount].setDealerName(dealerName); ptr[dealerCount].setDealerNumber(dealerNumber); ptr[dealerCount].setNumberOfCars(size); ptr[dealerCount].setCarArray(car); dealers.push_back(ptr[dealerCount]); dealerCount++; } } ifs.close(); } void displayDealers(vector &dealers){ for (int i = 0;i < dealers.size();i++) cout << dealers[i] << endl; } void displayCars(vector&dealers){ int DN; cout << "Dealer Number: "; cin >> DN; for (int i = 0; i < dealers.size(); i++){ if (DN == dealers[i].getDealerNumber()){ Car* carArray = dealers[i].getCarArray(); int Num_car = dealers[i].getNumberOfCars(); for (int i = 0; i < Num_car; i++) cout << carArray[i]; } } } 

For this programming assignment, you will be creating a program to manage cars in a dealership. This will again be a menu driven system. You will make a vector of Dealers (there can be zero to many dealers). Each dealer can have zero to many cars on the lot, represented by a dynamic array. The following is your menu:

  1. Read Dealers and Cars from file
  2. Display Dealers
  3. Choose a Dealer Number, Display Cars
  4. Choose a Dealer Number, Add Car
  5. Choose a Dealer Number, List Cars and Modify a Car (EXTRA CREDIT)
  6. Choose a Dealer, Sort cars by VIN (EXTRA CREDIT)
  7. Write Dealers and Cars to file.
  8. Exit

Your program will be object oriented (using classes, not structs) with the following classes defined in Dealer.h:

Dealer.h

#ifndef _DEALER

#define _DEALER

class Dealer {

private:

string dealerName;

int dealerNumber;

int numberOfCars;

Car *carArrayPtr; //This is the pointer to dynamic array of Car, you can also declare this to

//be public

public:

Dealer ( )

Dealer ( string _dealerName, int _dealerNumber);

void setDealerName (string _dealerName);

void setDealerNumber (string _dealerNumber);

void setNumberOfCars ( int _numberOfCars);

void setCarArray(Car * carArrayPtr); //You don't need this if the attribute is public

string getDealerName ( );

int getDealerNumber ( );

int getNumberOfCars( );

Car* getCarArray(); //You don't need this if the array pointer is public

friend ostream & operator << (ostream &out, Dealer _dealer);

//Print the Dealer Name and Number and Blank line for a specific dealer.

};

class Car

{

private:

string vin;

string make;

string model;

int year;

double price;

public:

Car( );

Car(string _vin, string _make, string model, int year, double price);

string getVIN( );

string getMake( );

string getModel( );

int getYear( );

double getPrice( );

void setVIN(string _vin);

void setMake(string _make);

void setModel(string _model);

void setYear(int _year);

void setPrice(double _price);

friend ostream& operator << (ostream & out, Car _car); //Print the VIN, Make, Model, Year,

//Price and Blank line for a specific car

};

#endif

You will have four files for your program (Use these file names!): main.cpp, functions.h, Dealer.h, and Dealer.cpp. Place them in a folder named LastnamePA3, then zip the content and hand in a zip file to canvas

  • main.cpp: this will be your driver file.
  • functions.h: this will contain your functions for each of the menu items.
  • Dealer.h: this will contain the class declarations for Car and Dealer including the operators <<.
  • Dealer.cpp: this will contain the class implementations for Car and Dealer.

Remember, you do not #include "Dealer.cpp", just #include "functions.h" and #include "Dealer.h" in main.cpp.

You will be storing your dealer objects in a vector. In the main function, you will create a vector of Dealers. When the menu is called, you will have to check your vector and ensure that it is not empty (size == 0) before referring to the index number of the vector. Your Dealer vector points to a dynamic array of cars (remember dynamic arrays use the keyword new). When you access the cars class you should verify that it is not set to nullptr before accessing it.

You may not use any global variables, so must pass vectors and arrays into parameters. If you want to change a vector you must pass by reference (&). If you have arrays, you must pass size and the array, but arrays are already pointers, so do not use & when passing an array.

Each menu item will have a corresponding function, and the definition of the function will be found in the file functions.h. Also, your operator << function for Dealer and Car will be implemented in your functions.h. All input/output will be done in the functions and not in main (except asking for what menu option the user wants).

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

  1. Read Dealers and Cars from file
  2. Display Dealers
  3. Choose a Dealer Number, Display Cars
  4. Choose a Dealer Number, Add Car
  5. Choose a Dealer Number, List Cars and Modify a Car (EXTRA CREDIT)
  6. Choose a Dealer, Sort cars by VIN (EXTRA CREDIT)
  7. Write Dealers and Cars to file.
  8. Exit

Option 1. Read Dealers and Cars from file

Pass the vector of dealers (from main) into the function by reference. Each Dealer will have a name and number followed by the number of cars in the dealership (on separate lines). Then you will read in a Vin, Make, Model, Year and Price for each car (on separate lines). You can assume that the number of cars as well as the Vin, Make, Model, Year and Price will be complete for each car. Each dealer can have a file format as follows:

Dealer Name

Dealer Number

Number of cars e.g. 2

Car1 Vin

Car1 Make

Car1 Model

Car1 Year

Car1 Price

Car2 Vin

Car2 Make

Car2 Model

Car2 Year

Car2 Price

Dealer Name

Dealer Number

Number of cars e.g. 1

Car1 Vin

Car1 Make

Car1 Model

Car1 Year

Car1 Price

Don't forget, between << and a getline you must use a .ignore( ) (e.g. infile.ignore( ) )

Here is an example of the input file: in.txt. You are welcome to add your own cars/dealers info.

Auto Express

1

2

VIN123

Dodge

Ram 1500 Quad Cab

2019

45186.00

VIN456

Chevrolet

Traverse Premier SUV

2017

47868.00

Premier Tesla

25

1

VIN789

Tesla

Model X

2019

105200

Option 2. Display Dealers

Pass the vector of dealers (from main) into the function by reference. Display the Dealer Name and Number for each dealer (put a blank line between dealers). Use the << operator with cout (cout << dealer[x];)

Option 3. Choose a Dealer Number, Display Cars

Pass the vector of dealers (from main) into the function by reference. Display the Dealer Names and Numbers (menu #2). Ask the user for the dealer number, display all of the cars by using a for loop (from zero to size of the car array) using the << operator with cout ( cout << dealer[x].carArrayPtr[x];)

Option 4. Choose a Dealer Number, Add Car

Pass the vector of dealers (from main) into the function by reference. a) Display the Dealer Names and Numbers (menu #2). b) Ask the user for the dealer number then the new car information. Follow the steps found in CSCI 1411 Lab 09 to increase the dynamic array. (Essentially you will make a new array, one bigger than the previous car array. Then you will copy everything over from the old car array to the new one. Then you will point the car pointer to the new array)

You can earn up to 20% extra credit (48/40) for completing 5 and 6 as long as you get at least 80% on the required tasks.

Option 5. Choose a Dealer Number, List Cars and Modify a Car (EXTRA CREDIT)

Pass the vector of dealers (from main) into the function by reference. Display the Dealer Names and Numbers (menu #2). Ask the user for the dealer number, display cars for that dealer. Ask the user to enter the vin number for the car to modify. The user will enter new car information including car vin, make, model, year and price. Update the car information in the car array of the dealer. This requires accurate access of the dealer car element.

Option 6. Choose a Dealer, Sort cars by VIN (EXTRA CREDIT)

Pass the vector of dealers (from main) into the function by reference. Display the Dealer Names and Numbers (menu #2). Ask the user for the dealer number. Sort the cars by vin and display them (with blank lines between each car)

Option 7. Write Dealers and Cars to file.

Pass the vector of dealers (from main) into the function by reference. Also pass in the filestream (from main) by reference. Call the output file out.txt. Write all of the Dealers and Cars to a separate output file in the same format as in item #1. This should include all changes to the vector and dynamic array (including add, delete, modify, sorting etc.)

Option 8. Exit out of the program

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!