Answer to Question #240845 in C++ for Redx

Question #240845

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. 


1
Expert's answer
2021-09-22T23:43:41-0400
#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();
	
	
	
	
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS