Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Showroom The Showroom class is a bit more sophisticated. Its purpose is to store a collection of Vehicle objects. Each Showroom that you create could

Showroom
The Showroom class is a bit more sophisticated. Its purpose is to store a collection of Vehicle objects.
Each Showroom that you create could have a different number of Vehicles (depending on its size), so for
this assignment well use a vector. Your Showroom should contain variables for the following:
The name of the Showroom
A vector to store Vehicle objects
A maximum capacity of the showroom (we dont want to add Vehicles beyond this limit)
In addition, you should create the following functions:
Default constructor (all parameters have default values)
Showroom(string name = "Unnamed Showroom'', unsigned int capacity =0);
// Accessor
vector GetVehicleList();
// Behaviors
void AddVehicle(Vehicle v);
void Showinventory();
float GetinventoryValue();
Function Reference
Constructor Same as all constructors! Initialize class member variables
GetVehicleList Return the vector objects, so other code can access it
AddVehicle If the Showroom is already full (numberOfVehicles == capacity), then you should
print out "Showroom is full! Cannot add 2015 Mazda Miata" (this will use
the GetYearMakeModel() function from the Vehicle class)
If there is space in the showroom, add the pass-in Vehicle to the class vector.
Vector objects can be expanded with the push_back() function.
ShowInventory Show all vehicles in the showroom, using the Display() function of each vehicle
GetInventoryValue Sum up the prices of all vehicles in the showroom and return that value
#include "Vehicle.h"
#include "Showroom.h"
#include
#include
using namespace std;
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("Tesla", "Model S",2018,74500,31),
Vehicle("Toyota", "Prius", 2015,17819,22987),
Vehicle("Nissan", "Leaf", 2016,12999,16889),
Vehicle("Chevrolet", "Volt", 2015,16994,12558),
};
// Set the precision for showing prices with 2 decimal places
cout << std::fixed << std::setprecision(2);
int testNum;
cin >> testNum;
if (testNum ==1)
{
Showroom testShowroom;
testShowroom.ShowInventory();
}
else if (testNum ==2)
{
Showroom one("Small Showroom", 2);
one.AddVehicle(vehicles[3]);
one.AddVehicle(vehicles[5]);
one.ShowInventory();
}
else if (testNum ==3)
{
Showroom one("Full Showroom", 2);
one.AddVehicle(vehicles[0]);
one.AddVehicle(vehicles[3]);
one.AddVehicle(vehicles[5]);
one.ShowInventory();
}
else if (testNum ==4)
{
Showroom one("Price Test", 3);
one.AddVehicle(vehicles[2]);
one.AddVehicle(vehicles[4]);
one.AddVehicle(vehicles[6]);
cout << "Total value: $"<< one.GetInventoryValue();
}
else if (testNum ==5)
{
Showroom one("Room 1",3);
one.AddVehicle(vehicles[1]);
one.AddVehicle(vehicles[3]);
one.AddVehicle(vehicles[5]);
cout << "Total value: $"<< one.GetInventoryValue()<< endl;
Showroom two("Room 2",6);
two.AddVehicle(vehicles[6]);
two.AddVehicle(vehicles[5]);
two.AddVehicle(vehicles[4]);
two.AddVehicle(vehicles[3]);
two.AddVehicle(vehicles[2]);
two.AddVehicle(vehicles[1]);
cout << "Total value: $"<< two.GetInventoryValue();
}
return 0;
}
#include
#include
using namespace std;
class Vehicle {
private:
std::string make;
std::string model;
unsigned int year;
float price;
unsigned int mileage;
public:
Vehicle(){
make = "COP3503";
model = "Rust Bucket";
year =1900;
price =0;
mileage =0;
}
Vehicle(string make, string model, int year, float price, int mileage){
this->make = make;
this->model = model;
this->year = year;
this->price = price;
this->mileage = mileage;
}
void Display(){
cout << year <<""<< make <<""<< model <<" $"<< price <<""<< mileage << endl;
}
string GetYearMakeModel(){
string str = to_string(year)+""+ make +""+ model;
return str;
}
float GetPrice(){
return price;
}
};

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Rules In Database Systems Third International Workshop Rids 97 Sk Vde Sweden June 26 28 1997 Proceedings Lncs 1312

Authors: Andreas Geppert ,Mikael Berndtsson

1997th Edition

3540635165, 978-3540635161

More Books

Students also viewed these Databases questions

Question

3. What are the current trends in computer hardware platforms?

Answered: 1 week ago