Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database 101

Authors: Guy Kawasaki

1st Edition

0938151525, 978-0938151524

Students also viewed these Databases questions