I'm trying to pass down the input values of variables from the base class Watch to the derived class Repair. I have tried to insert getter and setter function inside the Watch class but it doesn't work. Please help! For example, I insert "antique" as the watch variable but it doesn't pass down to the watch variable inside the Repair class.
#include<iostream>
#include<string>
#include<iomanip>
using namespace std;
class Watch
{
protected:
int price, age;
string watch;
public:
void type_watch()
{
cout<<"\nHow much is your watch?\n";
cin>>price;
cout<<"And, how old is your watch?\n";
cin>>age;
if(price>800&&age<=50)
{
watch=="designer";
cout<<"\nYour watch is classified as designer.\n";
}
else if(price<=800&&age<=50)
{
watch=="non-designer";
cout<<"\nYour watch is classified as non-designer.\n";
}
else
{
watch=="antique";
cout<<"\nYour watch is classified as antique.\n";
}
}
};
class Repair:public Watch
{
string gold_silver, free_repair;
float repair_price;
public:
void repair_watch()
{
cout<<"\nYour watch is classified as "<<watch<<".\n";
if(watch=="designer")
{
cout<<"Is your watch made of gold or silver?\n";
cin>>gold_silver;
if(gold_silver=="gold")
{
repair_price=price*(1/4);
}
else if(gold_silver=="silver")
{
repair_price=price*(1/3);
}
else
{
cout<<"Sorry, no matches.\n";
return;
}
}
else if(watch=="non-designer")
{
cout<<"Is it on the free repair list?\n";
cin>>free_repair;
if(free_repair=="yes")
{
repair_price=0;
}
else if(free_repair=="no")
{
repair_price=price*0.15;
}
}
else if(watch=="antique")
{
repair_price=age/2;
}
}
void total_price()
{
cout<<"The total cost of repair is $"<<fixed<<setprecision(2)<<repair_price<<".\n";
}
};
int main(void)
{
string ans, repair_watch;
Watch w;
Repair r;
cout<<"~~~Welcome to ABC Watches~~~\n\n";
while(ans!="no")
{
cout<<"\nWould you like to classify your watch?\n";
cin>>ans;
if(ans=="no")
{
cout<<"\nThank you for choosing ABC Watches! Good bye!\n";
}
else if(ans=="yes")
{
w.type_watch();
cout<<"\nWould you like to repair your watch?\n";
cin>>repair_watch;
if(repair_watch=="yes")
{
r.repair_watch();
r.total_price();
}
}
}
return 0;
}