You have to write a C++ Program in which you will Write aclass ‘ person’ which h
ID: 3619372 • Letter: Y
Question
You have to write a C++ Program in which you will Write aclass ‘person’ which has three typesof data members name, age and CNIC No. and getName(), getAge() andgerCNIC() functions that returns the name, age and CNIC No ofthe person respectively.
Write a second class ‘adult’which inherited the person class and has “implementedin term of” relationship to person. The‘adult’ class restrict the functionality of getAge()function by overriding the gatAge() function of person class.You also have to check the condition if age is greater than 18 thenprint “Adult Person”.
If object of adult class is initialized with the age lessthan 18, then it prints a message “age is less than18” and sets the value of age to default
Explanation / Answer
#include<iostream> #include<conio> #include<string> using namespace std; class person { char name[50]; int age; char CNIC_No[7]; public: person(char name1[50]="no name",int age1=18,char CNIC[7]="000-000") //default constrctor { strcpy(name,name1); if(age1>=18) age=age1; else { cout<<" Age is Less Than 18 "; age=18; } strcpy(CNIC_No,CNIC); } char* Getname() { return name; } int Getage() ^Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.