Question: Define the Person class's GetName ( ) accessor that gets data member name and the GetHeight ( ) accessor that gets data member height. Ex:

Define the Person class's GetName() accessor that gets data member name and the GetHeight() accessor that gets data member height.
Ex: If the input is Fay 4.5, then the output is:
Person: Fay
Height: 4.5 feet#include
#include
#include
using namespace std;
class Person {
public:
void SetName(string personName);
void SetHeight(double personHeight);
string GetName() const;
double GetHeight() const;
private:
string name;
double height;
};
void Person::SetName(string personName){
name = personName;
}
void Person::SetHeight(double personHeight){
height = personHeight;
}
int main(){
Person person;
string inputName;
double inputHeight;
cin >> inputName;
cin >> inputHeight;
person.SetName(inputName);
person.SetHeight(inputHeight);
cout << "Person: "<< person.GetName()<< endl;
cout << "Height: "<< fixed << setprecision(1)<< person.GetHeight()<<" feet" << endl;
return 0;
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!