Answer to Question #219614 in C++ for Yeswanth

Question #219614
Create a class called Person that has three private data members name, age and height and the
following public member functions:
• Default constructor – To initialize the data members
• Parameterized constructor – To initialize it to the given values
• getInput() - To get the person details from the user
• showOutput() - A constant member function to display the person details. Names
should be left justified and age and height to be right justified
isTaller() - A constant member function that takes a constant person object as parameter and
compares the height of the person object which calls this function with the height of the person
object that is passed as parameter and returns true if the calling object is taller than passed
argument; otherwise returns false; Write a main function to create an array of 3 Person objects
and find the tallest person. Display all the persons details and print the details of the tallest
person.
1
Expert's answer
2021-07-21T16:34:38-0400
#include<iostream>
#include<iomanip>
using namespace std;
class Person{
private:	
string name; 
	float age, height;
public:	Person(){			}
	Person(string na, float ag, float hi){		
name = na;		
age =ag;	
	height = hi;	
} 
const	void getInput(){	
	cout<<"person name\t"<<endl;	
	cin>>name;		
cout<<"person age\t"<<endl;	
	cin>>age;	
	cout<<" person height\t"<<endl;	
	cin>>height;	
}	
const void showOutput(){	
	cout<<"Name: \t"<<name;	
	cout<<setw(60)<<"\tAge is\t"<<age<<"\tHeight\t"<<height<<endl;
	}
const bool isTaller(Person p){	
	if(p.height < this->height){	
		return true;	
	}		
else{		
	return false;	
	}
	}
 };
int main()
{	
Person t1("Don",17,4);		
Person t2("Saul",20,10);	
	Person t3("David",7,7);	
	Person o[3] ={t1,t2,t3};	
	Person t4 = t1;		
if(t2.isTaller(t1) == true && t2.isTaller(t3) == true){		
	t4 = t2;	
	}	
	else if(t3.isTaller(t1) == true && t3.isTaller(t2)){		
	t4 = t3;	
	}	
	cout<<"Tallest person:   \n";		
t4.showOutput();
}

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
New on Blog
APPROVED BY CLIENTS