All of my variables are printing properly when the program runs....except string color....why is this?
//program create vehicle, prompt user to fill values, once user is done adding objects to "parking lot" prints associated values for each object//
#include <iostream>
#include <string>
#include <vector>
using namespace std;
//VEHICLE CLASS//
class Vehicle
{
public:
Vehicle();
void printFeatures();
void change_price(double thenewprice);
void change_year(int thenewyear);
void change_numberOfDoors( int thenewnumberOfDoors);
void change_color(string thenewcolor);
void print_color(string anothercolor);
string get_color();
private:
double price;
int year;
int numberOfDoors;
double mpg;
string color; //variable that refuses to print with cout//
};
//SUV CLASS//
class SUV: public Vehicle
{
public:
SUV();
void print_hybrid2();
private:
bool isHybrid;
};
//SEDAN CLASS//
class Sedan: public Vehicle
{
public:
Sedan();
void print_hybrid();
private:
bool isHybrid;
};
//SPORTS CAR CLASS//
class SportsCar: public Vehicle
{
public:
SportsCar();
private:
};
//VEHICLE CONSTRUCTOR DEFINITION//
Vehicle::Vehicle()
{
price=1000;
year=1986;
numberOfDoors=4;
mpg=20;
color="brown";
}
//VEHICLE FUNCTION DEFINTIONS//
void Vehicle::change_price( double thenewprice)
{
price= thenewprice;
}
void Vehicle::change_year(int thenewyear)
{
year= thenewyear;
}
void Vehicle::change_numberOfDoors(int thenewnumberOfDoors)
{
numberOfDoors = thenewnumberOfDoors;
}
void Vehicle:: change_color(string thenewcolor)
{
color = thenewcolor;
}
void Vehicle:: print_color(string anothercolor)
{
cout << anothercolor;
}
string Vehicle:: get_color()
{
return color;
}
//SEDAN AND SUV MEMBER FUNCTIONS//
void Sedan:: print_hybrid()
{
if (isHybrid == true)
{
cout << " Hybrid: Yes";
}
if (isHybrid == false)
{
cout << " Hybrid: No";
}
}
void SUV:: print_hybrid2()
{
if (isHybrid == true)
{
cout << " Hybrid: Yes";
}
if (isHybrid == false)
{
cout << " Hybrid: No";
}
}
//SPORTSCAR CONSTRUCTOR DEFINTION//
SportsCar::SportsCar()
{
int numberOfDoors1=2;
int year1;
int price1;
string color1;
cout << "What is the color of the car?" << "\n";
cin >> color1;
cout << "What is the price of the car?" << "\n";
cin >> price1;
cout << "What is the year of the car?" << "\n";
cin >> year1;
change_year(year1);
change_color(color1);
change_price(price1);
change_numberOfDoors(numberOfDoors1);
}
//SEDAN CONSTRUCTOR DEFINTION//
Sedan::Sedan()
{
string Hybridornot;
int year;
int price;
string color1;
cout << "What is the color of the car?" << "\n";
cin >> color1;
cout << "What is the price of the car?" << "\n";
cin >> price;
cout << "What is the year of the car?" << "\n";
cin >> year;
cout << "Is the car a hybrid?" << "\n";
cin >> Hybridornot;
if (Hybridornot=="Yes"||Hybridornot=="yes")
{
isHybrid=true;
}
if (Hybridornot=="No"||Hybridornot=="no")
{
isHybrid=false;
}
change_year(year);
change_price(price);
change_color(color1);
}
// SUV CONSTRUCTOR DEFINTION//
SUV::SUV()
{
int mgp=10;
string Hybridornot;
int year;
int price;
string color;
cout << "What is the color of the car?" << "\n";
cin >> color;
cout << "What is the price of the car?" << "\n";
cin >> price;
cout << "What is the year of the car?" << "\n";
cin >> year;
cout << "Is the car a hybrid?" << "\n";
cin >> Hybridornot;
if (Hybridornot=="Yes"||Hybridornot=="yes")
{
isHybrid=true;
}
if (Hybridornot=="No"||Hybridornot=="no")
{
isHybrid=false;
}
change_year(year);
change_price(price);
change_color(color);
}
//PRINT FEATURES FUNTION DEFITION//
void Vehicle::printFeatures()
{
cout << "Price: " << price << " Year: " << year << " Color: " << get_color() << "Number of Doors: " << numberOfDoors << " mgp: " << mpg;
}
int main ()
{
//ONE VECTOR FOR EACH TYPE OF VEHICLE (OR RATHER FOR EACH DERIVED CLASS)//
vector<SUV*> SUVs;
vector<Sedan*> Sedans;
vector<SportsCar*> SportsCars;
string answer1;
string answer2;
do{
cout << "Would you like to add a car to the lot? Enter Yes or No." << "\n";
cin >> answer1;
if (answer1=="No"||answer1=="no")
{
break;
}
cout <<"What typ of car of would you like to add to the the lot? Please enter Sedan, Suv, or SportsCar." << "\n";
cin >> answer2;
if (answer2=="Sedan" || answer2=="sedan")
{
Sedan newSedan;
Sedan* ThenewSedan;
ThenewSedan = &newSedan;
Sedans.push_back(ThenewSedan);
}
if (answer2=="Suv"||answer2=="suv"|| answer2=="SUV")
{
SUV newSUV;
SUV* ThenewSUV;
ThenewSUV = &newSUV;
SUVs.push_back(ThenewSUV);
}
if (answer2=="SportsCar"||answer2=="sportscar")
{
SportsCar newSportsCar;
SportsCar* ThenewSportsCar;
ThenewSportsCar = &newSportsCar;
SportsCars.push_back(ThenewSportsCar);
}
}
while(answer1=="yes"||answer1=="Yes");
//AFTER EXITING THE LOOP, PRINT THE CARS AND ASSOCIATED STATISTICS//
for(int i=0; i<SportsCars.size(); i++)
{
SportsCars[i]->printFeatures();
cout << "\n";
}
for(int i=0; i<Sedans.size(); i++)
{
Sedans[i]->printFeatures();
Sedans[i]->print_hybrid();
cout << "\n";
}
for(int i=0; i<SUVs.size(); i++)
{
SUVs[i]->printFeatures();
SUVs[i]->print_hybrid2();
cout << "\n";
}
;
return 0;
}