You are on page 1of 2

#include<conio.

h>
#include<iostream>
#include<string.h>
using namespace std;
class Car
{
protected:
string brandname;
string color;
double odometer;
double newprice;
public:
Car()
{
brandname="";
color="";
odometer=0.0;
newprice=0.0;
}
void set_data()
{
cout<<"Enter Brand Name:"<<endl;
cin>>brandname;
cout<<"Enter Color:"<<endl;
cin>>color;
cout<<"Enter New Price"<<endl;
cin>>newprice;
}
double getpriceafteruse()
{
return newprice*(1-odometer/600000);
}
void updatemileage(double distance)
{
odometer=distance;
}
void get_data()
{

cout<<"Brand Name: "<<brandname<<endl;


cout<<"Color of car is: "<<color<<endl;
cout<<"New Price is: "<<newprice<<endl;
cout<<"Distance travelled is: "<<odometer<<endl;
cout<<"Price After use is: "<<getpriceafteruse()<<endl;
}
};
int main()
{
Car c1;
double Distance;
c1.set_data();
cout<<"Second hand price is "<<c1.getpriceafteruse();
cout<<endl<<"Enter mileage"<<endl;
cin>>Distance;
c1.updatemileage(Distance);
cout<<"Seocnd hand price is "<<c1.getpriceafteruse();
cout<<endl<<"Details of Car"<<endl;
c1.get_data();
getch();
return(0);
}

OUTPUT:

You might also like