PART 1: C++ Design a class and name it Person that holds the following personal
ID: 3744932 • Letter: P
Question
PART 1: C++ Design a class and name it Person that holds the following personal data: name: a string that holds the person's name address: a string that holds the person's address .age: an int that holds the person's age Write appropriate accessor (getter) and mutator (setter) methods. In addition, the class should have the following two constructors: . A default constructor that assigns empty strings () to the name and address, and 0 to the age. .A constructor that accepts the following values as arguments and assigns them to the appropriate member variables: person's name, person's address, and a Demonstrate the class by writing a program that creates three instances of it. 0 One instance should hold your information, and the other two should hold your friends' or family member's information.Explanation / Answer
As per chegg policy, solving first question, Please post rest of the questions saperatly.
Below is your code in C++
#include<iostream>
using namespace std;
class Person{
private:
string name;
string address;
int age;
public:
Person() {
name = "";
address = "";
age = 0;
}
Person(string nme, string addr, int perAge) {
name = nme;
address = addr;
age = perAge;
}
int getAge() {
return age;
}
string getName() {
return name;
}
string getAddress() {
return address;
}
void setAge(int ag) {
age = ag;
}
void setAddress(string addr) {
address = addr;
}
void setName(string nme) {
name = nme;
}
};
int main() {
Person p1("Jack Ryan","North Carolina",26);
Person p2,p3;
p2.setName("Chandra Prakash");
p2.setAddress("Vasai Villa");
p2.setAge(21);
p3.setName("Nav Singh");
p3.setAddress("Victoria Street, California");
p3.setAge(30);
cout<<"Person 1: "<<p1.getName()<<" living in "<<p1.getAddress()<<" is having age of "<<p1.getAge()<<endl;
cout<<"Person 2: "<<p2.getName()<<" living in "<<p2.getAddress()<<" is having age of "<<p2.getAge()<<endl;
cout<<"Person 3: "<<p3.getName()<<" living in "<<p3.getAddress()<<" is having age of "<<p3.getAge()<<endl;
return 0;
}
OutPut
Person 1: Jack Ryan living in North Carolina is having age of 26
Person 2: Chandra Prakash living in Vasai Villa is having age of 21
Person 3: Nav Singh living in Victoria Street, California is having age of 30
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.