Question
The goal for this assignment is to create some classes for a warmup in my C++ class. I have successfully made the showroom class (somewhat...),
The goal for this assignment is to create some classes for a warmup in my C++ class. I have successfully made the showroom class (somewhat...), but for some reason my Vehicle vector is not working. Whenever I try to compile the code, I get an "undefined symbol" error. If you have any suggestions on how I could get this to work, please let me know.
Below is my main class, and the showroom class I made. If there is anything else you need just let me know. I used xCode.
/// Main.cpp ///
#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
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
}
else if (testNum == 5)
{
Showroom one("Room 1", 3);
one.AddVehicle(vehicles[1]);
one.AddVehicle(vehicles[3]);
one.AddVehicle(vehicles[5]);
cout
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
}
return 0;
}
/// Showroom. h ///
#include "Vehicle.h"
#include
#include
using namespace std;
class Showroom{
public:
Showroom (string name = "Unnamed Showroom", unsigned int capacity = 0);
vector
void AddVehicle(Vehicle& v);
void ShowInventory();
float GetInventoryValue();
string name;
vector
unsigned int capacity;
};
/// Showroom.cpp ///
//#include "Vehicle.h"
//#include "Vehicle.cpp"
#include "Showroom.h"
#include
#include
using namespace std;
vector
return vehicleList();
};
void Showroom :: AddVehicle(Vehicle& v){
vehicleList().push_back(v);
};
void Showroom :: ShowInventory(){
for (int i = 0; i
vehicleList()[i].Display();
}
};
float Showroom :: GetInventoryValue(){
float value = 0.0;
float inventoryValue = 0;
for (int i = 0; i
inventoryValue += vehicleList()[i].GetPrice();
}
return inventoryValue;
return value;
};
1 #include "Vehicle.h" 2 #include "Showroom.h" 3 #includeStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started