Write a main function to create objects of distance class input two distances and output the sum.
AIM:
Write
a main function to create objects of distance class input two distances and
output the sum.
THEORY:
Develop a class to
measure distance as feet (should be
int
),
inches (should be float
). Include member functions to set and get
attributes. Include constructors. Develop functions to add two distances.
SOURCE
CODE:
#include<iostream>
using
namespace std;
class
dist
{
public:
int feet,inch,x,y,z;
void input()
{
cout<<"enter
feet and inches:"<<"\n";
cin>>feet>>inch;
}
void show()
{
cout<<"the
distance is \n";
cout<<feet<<"feet"<<inch<<"inch";
}
void sum(dist x,dist y)
{
feet=x.feet+y.feet;
inch=x.inch+y.inch;
if(inch>=12)
{
feet=feet+1;
inch=inch-12;
}
}
};
int
main()
{
dist x,y,z;
x. input();
y. input();
z. sum(x,y);
z. show();
}
Labels: oop through c++ lab
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home