a//DISTANCE TRAVELLED PER HOUR
#include<iostream.h>
#include<conio.h>
class travel
{
private:
int km,hr;
public:
travel() //constructor
{
km=hr=0;
}
void set()
{
cout<<"enter km travelled ";
cin>>km;
cout<<"enter hours ";
cin>>hr;
}
void show()
{
cout<<"\n you travelled "<<km<<" kilometer "<<" in "<<hr<<" hours\n\n";
}
void total(travel p,travel q)
{
travel temp;
temp.km=km+p.km+q.km;
temp.hr=hr+p.hr+q.hr;
cout<<"\n\n total travelling is "<<temp.km<<" kilometers "<<" in "<<temp.hr<<" hours";
}
};
void main()
{
travel t1,t2,t3;
t1.set();
t1.show();
t2.set();
t2.show();
t3.set();
t3.show();
t1.total(t2,t3);
getch();
}
#include<iostream.h>
#include<conio.h>
class travel
{
private:
int km,hr;
public:
travel() //constructor
{
km=hr=0;
}
void set()
{
cout<<"enter km travelled ";
cin>>km;
cout<<"enter hours ";
cin>>hr;
}
void show()
{
cout<<"\n you travelled "<<km<<" kilometer "<<" in "<<hr<<" hours\n\n";
}
void total(travel p,travel q)
{
travel temp;
temp.km=km+p.km+q.km;
temp.hr=hr+p.hr+q.hr;
cout<<"\n\n total travelling is "<<temp.km<<" kilometers "<<" in "<<temp.hr<<" hours";
}
};
void main()
{
travel t1,t2,t3;
t1.set();
t1.show();
t2.set();
t2.show();
t3.set();
t3.show();
t1.total(t2,t3);
getch();
}
0 comments:
Post a Comment