Oop2 PDF
Oop2 PDF
class person_additional_info {
char address[20], license[20], insurance[20];
long int contact;
public:
person_additional_info() {
strcpy(address, "XYZ");
strcpy(license, "XY-0000000000");
strcpy(insurance, "XY00000000X");
contact = 000000000;
}
class person {
char name[20], dob[10], blood[10];
float ht, wt;
static int count;
person_additional_info* pai;
public:
person() {
strcpy(name, "XYZ");
strcpy(dob, "dd/mm/yy");
strcpy(blood, "A +");
ht = 0;
wt = 0;
pai = new person_additional_info;
}
~person() {
cout << "I am in Destructor of person" << endl;
delete pai; // Free dynamically allocated memory
}
int person::count = 0;
int main() {
person *p1, *p2;
int ch;
p1 = new person; // Call default constructor & dynamic memory allocation
p2 = new person(p1); // Call copy constructor
int n;
cout << "\nEnter how many records you want? ";
cin >> n;
person* p3 = new person[n]; // Array of objects
char name[20];
int x = 0;
do {
cout << "\nWelcome to Personal database system";
cout << "\n1. Enter the record";
cout << "\n2. Display the record";
cout << "\n3. Exit";
cin >> ch;
switch (ch) {
case 1:
cout << "\nEnter the Name: ";
cin >> name;
p3[x].getdata(name);
person::showcount(); // Calls static function
x++;
break;
case 2:
cout << "\tName\tDob\tBlood\tHt\tWt\tAddress\tLicense\tInsurance\tContact" << endl;
for (int i = 0; i < x; i++) {
p3[i].display(); // Calls inline function
}
break;
}
} while (ch != 3);
No of records count = 1