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

And main: #include \"Vehicle.h\" #include \"Showroom.h\" #include \"Dealership.h

ID: 3745012 • Letter: A

Question

And main:

#include "Vehicle.h"
#include "Showroom.h"
#include "Dealership.h"
#include <iostream>
#include <limits>
#include <memory>
#include <iomanip>
using namespace std;

void TestOne(Vehicle *v);
void TestTwo(Vehicle *v);

int main()
{
   // Initialize some data. It's hard-coded here, but this data could come from a file, database, etc
   Vehicle vehicles[] =
   {
       Vehicle("Ford", "Mustang", 1973, 9500, 113000),
       Vehicle("Mazda", "CX-5", 2017, 24150, 5900),
       Vehicle("Dodge", "Charger", 2016, 18955, 9018),
       Vehicle("Telsa", "Model S", 2018, 74500, 31),
       Vehicle("Toyota", "Prius", 2015, 17819, 22987),
       Vehicle("Nissan", "Leaf", 2016, 12999, 16889),
       Vehicle("Chevrolet", "Volt", 2015, 16994, 12558),
   };

int testNum;
cin >> testNum;

if (testNum == 1)
TestOne(vehicles);
else if (testNum == 2)
TestTwo(vehicles);

   return 0;
}

void TestOne(Vehicle *vehicles)
{
// Showrooms to store the vehicles
   Showroom showroom("Primary Showroom", 3);
   showroom.AddVehicle(&vehicles[0]);
   showroom.AddVehicle(&vehicles[1]);
   //showroom.AddVehicle(&vehicles[2]);
  
   Showroom secondary("Fuel-Efficient Showroom", 4);
   secondary.AddVehicle(&vehicles[3]);
   secondary.AddVehicle(&vehicles[4]);
   secondary.AddVehicle(&vehicles[5]);
   secondary.AddVehicle(&vehicles[6]);

   // A "parent" object to store the Showrooms
   Dealership dealership("COP3503 Vehicle Emporium", 2);
   dealership.AddShowroom(&showroom);
   dealership.AddShowroom(&secondary);

   dealership.ShowInventory();
}

void TestTwo(Vehicle *vehicles)
{
   // Showrooms to store the vehicles
   Showroom showroom("Primary Showroom", 3);
   showroom.AddVehicle(&vehicles[0]);
   showroom.AddVehicle(&vehicles[1]);
  
   Showroom secondary("Fuel-Efficient Showroom", 4);

   secondary.AddVehicle(&vehicles[4]);
   secondary.AddVehicle(&vehicles[5]);
  
   Showroom third("Fuel-Efficient Showroom", 4);
   third.AddVehicle(&vehicles[3]);
   // A "parent" object to store the Showrooms
   Dealership dealership("COP3503 Vehicle Emporium", 3);
   dealership.AddShowroom(&showroom);
   dealership.AddShowroom(&secondary);
   dealership.AddShowroom(&third);

cout << "Using just the GetAveragePrice() function ";

   cout << "Average price of the cars in the dealership: $" << std::fixed << std::setprecision(2);
   cout << dealership.GetAveragePrice();
}

Description This program will represent a hypothetical car dealership, which consists of showrooms that contain the vehicles for sale. To that end, there are three classes you will be writing: Vehicle Showroom . Dealership For this assignment, main.cpp will be provided for you, so you don't have to worry about the structure of the program. Instead, you can focus solely on the structure of the classes and their interactions Vehicle The Vehicle class is the basic container of this assignment. You will need to store the following data: . The make of the vehicle (such as Mazda, Toyota, etc) . The model of the vehicle (such as Mustang, Model S, F-150, etc) The year The price . How many miles does the vehicle have on it? In addition to a constructor which takes in the necessary information, you will also need the following functions defined. If you are using dynamic memory in your class, you will also want to define a destructor, in which you will clean up (delete) any memory which was allocated by the class. Print all the information on a single line void Display() const; // Return a string in the form of "1970 Ford Mustang" string GetYearMakeModel() const; // How much to buy this? float GetPrice() const;

Explanation / Answer

Below is your code . Please let me know if you have any issues

Vehicle.h

#ifndef VEHCILE_H
#define VEHCILE_H
#include <string>

using namespace std;

class Vehicle
{
private:
string Make;
string Model;
int Year;
float Price;
int Mileage;
public:
Vehicle();
Vehicle(string Make1,string Model1,int Year1,float Price1,int Mileage1);
void Display() const;
string GetYearMakeModel() const;
float GetPrice() const;
};

#endif

Vehicle.cpp

#include "Vehicle.h"
#include <iostream>
#include <string>

using namespace std;

Vehicle :: Vehicle() // default constructor
{
Make="";
Model="";
Year=0;
Price=0;
Mileage=0;
}

Vehicle :: Vehicle(string Make1,string Model1,int Year1,float Price1,int Mileage1) // parametric constructor
{
Make=Make1;
Model=Model1;
Year=Year1;
Price=Price1;
Mileage=Mileage1;
}

void Vehicle :: Display() const
{
cout<<Make<<" "<<Model<<" "<<Year<<" "<<Price<<" "<<Mileage<<endl;
}

string Vehicle :: GetYearMakeModel() const
{
string year = to_string(Year);
return year + Make + Model;
}

float Vehicle :: GetPrice() const
{
return Price;
}

Showroom.h

#ifndef SHOWROOM_H

#define SHOWROOM_H

#include "Vehicle.h"

#include <string>

using namespace std;

class Showroom

{

private:

int maxSize; // the max size of vehicles

int currentSize; // the current number of vehicles

Vehicle* vehiclelist;

string Name;

public:

Showroom();

Showroom(string n,int cur);

Showroom(const Showroom &t);

~Showroom();

Showroom& operator=(const Showroom &t);

void AddVehicle(const Vehicle *v);

void ShowInventory() const;

const Vehicle *GetVehicleList() const;

unsigned int GetCapacity() const;

unsigned int GetCount() const;

const char * GetName() const;

};

#endif

Showroom.cpp

#include "Showroom.h"

#include "Vehicle.h"

#include <iostream>

#include <string>

using namespace std;

Showroom :: Showroom()

{

maxSize = 20; // change 20 to increase the maximum no of vehicles

currentSize = 0;

vehiclelist = new Vehicle[maxSize];

Name = "";

}

Showroom :: Showroom(string n,int cur)

{

maxSize = 20; // change 20 to increase the maximum no of vehicles

currentSize = cur;

vehiclelist = new Vehicle[maxSize];

Name = n;

}

Showroom :: Showroom(const Showroom &t)

{

maxSize = t.maxSize;

currentSize =t.currentSize;

vehiclelist =t.vehiclelist;

Name = t.Name;

}

Showroom :: ~Showroom()

{

delete [] vehiclelist;

}

Showroom& Showroom ::operator=(const Showroom &t)

{

}

void Showroom :: AddVehicle(const Vehicle *v)

{

vehiclelist[currentSize++]=v;

}

void Showroom :: ShowInventory() const

{

if (currentSize == 0)

{

cout << " Current Inventory is empty. ";

return;

}

for (int i = 0; i < currentSize; i++) // For each entry,

vehiclelist[i].Display(); // send it to output

}

const Vehicle Showroom :: *GetVehicleList() const

{

if (currentSize == 0)

{

cout << " Current Showroom is empty. ";

return nullptr;

}

else

{

return vehiclelist;

}

}

unsigned int Showroom :: GetCapacity() const

{

return maxSize;

}

unsigned int Showroom :: GetCount() const

{

return currentSize;

}

const char Showroom :: * GetName() const

{

return Name;

};

Dealership.h

#ifndef DEALERSHIP_H

#define DEALERSHIP_H

#include "Showroom.h"

#include "Vehicle.h"

#include <string>

using namespace std;

class Dealership

{

private:

int maxSize; // the max size of vehicles

int currentSize; // the current number of vehicles

Showroom* showroomlist;

string Name;

public:

Dealership(string n,int cur);

Dealership(const Dealership &t);

~Dealership();

Dealership& operator=(const Dealership &t);

unsigned int GetCapacity() const;

unsigned int GetCount() const;

const char * GetName() const;

void AddShowroom(const Showroom *v);

void ShowInventory() const;

void GetAveragePrice() const;

};

#endif

Dealership.cpp

#include "Vehicle.h"

#include "Showroom.h"

#include "Dealership.h"

#include <iostream>

#include <string>

using namespace std;

Dealership :: Dealership(string n,int cur)

{

maxSize = 20; // change 20 to increase the maximum no of vehicles

currentSize = cur;

showroomlist = new Showroom[maxSize];

Name = n;

}

Dealership :: Dealership(const Dealership &t)

{

maxSize = t.maxSize;

currentSize =t.currentSize;

showroomlist =t.showroomlist;

Name = t.Name;

}

Dealership :: ~Dealership()

{

delete [] showroomlist;

}

Dealership& Dealership :: operator=(const Dealership &t)

{

}

void Dealership :: AddShowroom(const Showroom *v)

{

showroomlist[currentSize++]=v;

}

void Dealership :: ShowInventory() const

{

if (currentSize == 0)

{

cout << " Current Dealership is empty. ";

return;

}

for (int i = 0; i < currentSize; i++) // For each entry,

showroomlist[i].ShowInventory();

}

unsigned int Dealership :: GetCapacity() const

{

return maxSize;

}

unsigned int Dealership :: GetCount() const

{

return currentSize;

}

const char Dealership :: * GetName()

{

return Name;

}

void GetAveragePrice() const

{

Vehicle* vehicle;

float price=0;

int i,j,n=0;

if (currentSize == 0)

{

cout << " Current Dealership is empty. ";

return 0;

}

for (i = 0; i < currentSize; i++) // For each entry,

{

vehicle = showroomlist[i].GetVehicleList();

for(j=0; j< showroomlist[i].GetCount(); j++)

{

price+= vehicle[j].GetPrice();

++n;

}

}

return price/n;

}