February 09, 2014

OOMP Assignment#3

/*
Aim: Develop an object oriented program in C++ to create a database of the personnel
information system containing the following information: Name, Date of Birth, Blood
group, Height, Weight, Insurance Policy, number, Contact address, telephone number,
driving license no. etc Construct the database with suitable member functions for
initializing and destroying the data viz constructor, default constructor, copy, constructor,
destructor, static member functions, friend class, this pointer, inline code and dynamic
memory allocation operators-new and delete.
*/

#include <iostream>
#define MAX_RECORDS 50
using namespace std;

class Information{
 friend class Records;
 private:
   string name, dateOfBirth, bloodGroup, contactAddress;
   float height, weight;
   double policyNumber, telephoneNumber, licenseNumber;
 public:
   Information(string n, string dob, string bg, string ca, int h, int w, double pn, double tn, double ln){
     this->name = string(n);
     this->dateOfBirth = string(dob);
     this->bloodGroup = string(bg);
     this->contactAddress = string(ca);
     this->height = h;
     this->weight = w;
     this->policyNumber = pn;
     this->telephoneNumber = tn;
     this->licenseNumber = ln;
   }
   Information(){
     Information("", "", "", "", 0, 0, 0, 0, 0);
   }
   Information(const Information& otherInfo){
     this->name = otherInfo.name;
     this->dateOfBirth = otherInfo.dateOfBirth;
     this->bloodGroup = otherInfo.bloodGroup;
     this->contactAddress = otherInfo.contactAddress;
     this->height = otherInfo.height;
     this->weight = otherInfo.weight;
     this->policyNumber = otherInfo.policyNumber;
     this->telephoneNumber = otherInfo.telephoneNumber;
     this->licenseNumber = otherInfo.licenseNumber;
   }
   inline void acceptValues(){
     cout << endl << "Enter personal details: ";
     cout << endl << "Name: ";
     cin >> this->name;
     cout << endl << "Date Of Birth: ";
     cin >> this->dateOfBirth;
     cout << endl << "Blood Group: ";
     cin >> this->bloodGroup;
     cout << endl << "Contact Address: ";
     cin >> this->contactAddress;
     cout << endl << "Height: ";
     cin >> this->height;
     cout << endl << "Weight: ";
     cin >> this->weight;
     cout << endl << "Policy Number: ";
     cin >> this->policyNumber;
     cout << endl << "Telephone Number: ";
     cin >> this->telephoneNumber;
     cout << endl << "License Number: ";
     cin >> this->licenseNumber;
   }
   inline void display(){
     cout << endl << "Personal details: " << endl;
     cout << endl << "Name: " << this->name;
     cout << endl << "Date Of Birth: " << this->dateOfBirth;
     cout << endl << "Blood Group: " << this->bloodGroup;
     cout << endl << "Contact Address: " << this->contactAddress;
     cout << endl << "Height: " << this->height;
     cout << endl << "Weight: " << this->weight;
     cout << endl << "Policy Number: " << this->policyNumber;
     cout << endl << "Telephone Number: " << this->telephoneNumber;
     cout << endl << "License Number: " << this->licenseNumber << endl;
   }
};

class Records{
 private:
   Information * records[MAX_RECORDS];
 public:
   static int COUNT;
   static int getCount(){
     return COUNT;
   }
   static void incCount(){
     COUNT++;
   }
   void add(){
     records[Records::getCount()] = new Information();
     records[Records::getCount()]->acceptValues();
     Records::incCount();
   }
   void display(){
     for(int i = 0; i < Records::getCount(); i++){
       records[i]->display();
     }
   }
   ~Records(){
     for(int i = 0; i < Records::getCount(); i++){
       delete records[i];
     }
   }
};

int Records::COUNT = 0;

int main(){
 int choice;
 Records * rs = new Records();
 do{
   cout << endl << "-- Personal Information --";
   cout << endl << "1. Add information";
   cout << endl << "2. Display information";
   cout << endl << "3. Exit";
   cout << endl << "Your choice: ";
   cin >> choice;
   switch(choice){
     case 1 : rs->add(); break;
     case 2 : rs->display(); break;
   }
 }while(choice != 3);
 delete rs;
 return 0;
}

/*
---------------------------------------
             OUTPUT
---------------------------------------

-- Personal Information --
1. Add information
2. Display information
3. Exit
Your choice: 1

Enter personal details:
Name: Man

Date Of Birth: 4/4/1994

Blood Group: O+

Contact Address: Pune

Height: 160

Weight: 65

Policy Number: 7766554433

Telephone Number: 9988776655

License Number: 123456890

-- Personal Information --
1. Add information
2. Display information
3. Exit
Your choice: 1

Enter personal details:
Name: Tau

Date Of Birth: 5/5/1995

Blood Group: AB-

Contact Address: Mumbai

Height: 160

Weight: 45

Policy Number: 1234554321

Telephone Number: 9988006677

License Number: 0987654321

-- Personal Information --
1. Add information
2. Display information
3. Exit
Your choice: 2

Personal details:

Name: Man
Date Of Birth: 4/4/1994
Blood Group: O+
Contact Address: Pune
Height: 160
Weight: 65
Policy Number: 7.76655e+009
Telephone Number: 9.98878e+009
License Number: 1.23457e+008

Personal details:

Name: Tau
Date Of Birth: 5/5/1995
Blood Group: AB-
Contact Address: Mumbai
Height: 160
Weight: 45
Policy Number: 1.23455e+009
Telephone Number: 9.98801e+009
License Number: 9.87654e+008

-- Personal Information --
1. Add information
2. Display information
3. Exit
Your choice: 3
*/

1 comment:

  1. u have defined a copy constructor but haven't called it.
    then whats the use of defining it in the first place?

    ReplyDelete