We created in class a Person class to represent a person. The class has instance
ID: 655691 • Letter: W
Question
Explanation / Answer
#include <iostream.h>
#include <string.h>
#include <conio.h>
class Person
{
char name[50];
int age;
public:
Person()
{
strcpy(name,"no name yet");
age=0;
}
Person(char *s, int a)
{
strcpy(name,s);
age=a;
}
void display()
{
cout<<name<<" "<<age;
}
static Person& createAdult(char S[], int a , Person &P)
{
strcpy(P.name,S);
P.age=a;
return P;
}
}
void main()
{
int a;
char str[50];
Person p1=new Person();
cout<<"Person 1 Details:";
p1.display();
cout<<"Enter the name of the Generic Adult:";
cin>>str;
cout<<endl<<"Enter the age: ";
cin>>a;
Person p2=new Person(str,a);
p2.display();
Person p4=new Person();
Person p3=new Person("An Adult",21,p4);
Person::createAdult();
cout<<"Generic Adult Details:";
p3.display();
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.