Write a program to create a class named 'height', containing variable 'feet', 'inch'. Create two objects of the class, set some value to the first class. Then increment that object by 1 and assign this object to the second object. Display the results of both object after the procedure is completed.
#include<iostream>
using namespace std;
class height{
private:
double feet, inch;
public:
height(){
}
height(double f, double i){
feet = f;
inch = i;
}
height add(){
height h;
h.feet = this->feet + 1;
h.inch = this->inch + 1;
return h;
}
void display(){
cout<<"Feet: "<<feet<<"\nInch: "<<inch<<endl;
}
};
int main(){
height h(3,5), h1;
cout<<"The first object:\n";
h.display();
h1 = h.add();
cout<<"The second object:\n";
h1.display();
}
Comments
Leave a comment