0% found this document useful (0 votes)
20 views4 pages

Oop2 PDF

Uploaded by

gameralexander61
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views4 pages

Oop2 PDF

Uploaded by

gameralexander61
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

#include <iostream>

#include <cstring> // Changed from string.h for C++ compatibility


using namespace std;

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;
}

friend class person;


};

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(const person* p1) {


strcpy(name, p1->name);
strcpy(dob, p1->dob);
strcpy(blood, p1->blood);
ht = p1->ht;
wt = p1->wt;
pai = new person_additional_info;
strcpy(pai->address, p1->pai->address);
strcpy(pai->license, p1->pai->license);
strcpy(pai->insurance, p1->pai->insurance);
pai->contact = p1->pai->contact;
}
static void showcount() {
cout << "\nNo of records count = " << count << "\n";
}

~person() {
cout << "I am in Destructor of person" << endl;
delete pai; // Free dynamically allocated memory
}

void getdata(const char* name);


inline void display() const;
};

int person::count = 0;

void person::getdata(const char* name) {


strcpy(this->name, name);
cout << "\nEnter date of birth: ";
cin >> dob;
cout << "\nEnter blood group: ";
cin >> blood;
cout << "\nEnter height: ";
cin >> ht;
cout << "\nEnter weight: ";
cin >> wt;
cout << "\nEnter address: ";
cin >> pai->address;
cout << "\nEnter Licence number: ";
cin >> pai->license;
cout << "\nEnter Insurance policy number: ";
cin >> pai->insurance;
cout << "\nEnter Contact number: ";
cin >> pai->contact;
count++;
}

void person::display() const {


cout << "\t" << name
<< "\t" << dob
<< "\t" << blood
<< "\t" << ht
<< "\t" << wt
<< "\t" << pai->address
<< "\t" << pai->license
<< "\t" << pai->insurance
<< "\t" << pai->contact << endl;
}

int main() {
person *p1, *p2;
int ch;
p1 = new person; // Call default constructor & dynamic memory allocation
p2 = new person(p1); // Call copy constructor

cout << "\tName\tDob\tBlood\tHt\tWt\tAddress\tLicense\tInsurance\tContact" << endl;


cout << "Default Constructor Value:\n";
p1->display();
cout << "Copy Constructor Value:\n";
p2->display();

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);

delete p1; // Dynamic memory de-allocation


delete p2;
delete[] p3; // Free array of objects
return 0;
}
OUTPUT:-
Name Dob Blood Ht Wt Address License Insurance Contact
Default Constructor Value:
XYZ dd/mm/yy A+ 0 0 XYZ XY-0000000000 XY00000000X 0
Copy Constructor Value:
XYZ dd/mm/yy A+ 0 0 XYZ XY-0000000000 XY00000000X 0

Enter how many records you want? 1

Welcome to Personal database system


1. Enter the record
2. Display the record
3. Exit1

Enter the Name: PRAJWAL

Enter date of birth: 08/10/2005

Enter blood group: O+

Enter height: 122

Enter weight: 1222

Enter address: PUNE

Enter Licence number: MH12PN2322

Enter Insurance policy number: DE222

Enter Contact number: 8999768417

No of records count = 1

Welcome to Personal database system


1. Enter the record
2. Display the record
3. Exit2
Name Dob Blood Ht Wt Address License Insurance Contact
PRAJWAL 08/10/2005O+ O+ 122 1222 PUNE MH12PN2322 DE222 8999768417

Welcome to Personal database system


1. Enter the record
2. Display the record
3. Exit

=== Code Execution Successful ===

You might also like