In this post we will write a C++ program to display the distance in feet and inches.
C++ program to display the distance in feet and inches.
#include<iostream>
#include<conio.h>
class distance
{
private:
int feet;
float inches;
public:
distance()
{
feet = 0;
inches = 0.0;
}
distance(int ft, float in)
{
feet = ft;
inches = in;
}
void input()
{
std::cout<<"Ente the feet = ";
std::cin>>feet;
std::cout<<"Enter the inches = ";
std::cin>>inches;
}
void show()
{
std::cout<<feet<<"\t"<<inches<<std::endl;
}
distance adddis(distance d2);
};
int main()
{
system("cls");
distance dis1, dis3;
distance dis2(11,6.5);
dis1.input();
dis3 = dis1.adddis(dis2);
std::cout<<"distance one = ";
dis1.show();
std::cout<<"distance two = ";
dis2.show();
std::cout<<"distance three = ";
dis3.show();
getch();
}
distance distance::adddis(distance d2)
{
distance temp;
temp.inches = inches+d2.inches;
temp.feet = d2.feet;
return(temp);
}
Output
Enter the feet = 5 Enter the inches = 2.8 distance one = 5 2.8 distance two = 11 6.5 distance three = 16 9.3
0 Comments