Answer to Question #216992 in C++ for Srikanth Kodamasim

Question #216992
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-14T04:48:03-0400
#include<iostream>
#include<iomanip>
using namespace std;
class Person{
private:
	string name; 
	float age, height;
public:
	Person(){
		
	}
	Person(string n, float g, float h){
		name = n;
		age =g;
		height = h;
	}
 const	void getInput(){
		cout<<"Enter the person name\t"<<endl;
		cin>>name;
		cout<<"Enter the person age\t"<<endl;
		cin>>age;
		cout<<"Enter the person height\t"<<endl;
		cin>>height;
	}
	const void showOutput(){
		cout<<"Name\t"<<name;
		cout<<setw(50)<<"\tThe age is\t"<<age<<"\tThe height is\t"<<height<<endl;
	}
const bool isTaller(Person p){
		if(p.height < this->height){
			return true;
		}
		else{
			return false;
		}
	} 
};
int main(){


	Person t1("Onyango",67,10);
		Person t2("John",47,6);
		Person t3("Ambrose",57,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<<"The tallest person is\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

Srikanth Kodamasimham
14.07.21, 12:00

Thanks

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS