WELCOME

Welcome to KoDes4U

Pages

Wednesday, March 9, 2011

Static member functions, friend class, this pointer, inline code and dynamic memory allocation(C++ program)

/*Develop an object oriented program in C++ to create a database of the
personal information system containing the following information:
Name, Date of Birth, Blood group, Height, Weight, Insurance policy number,
Contact address, driving licence 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 clas, this pointer,inline code and dynamic memory allocation
operators-new and delete. coded for KoDes4U.blogspot.com*/


#include
#include
#include
class database
{
char name[50],date_of_birth[11],cont_add[50],tel_no[10];
public:
database() //constructor
{
strcpy(name,"blank_name");
strcpy(date_of_birth,"00/00/00");
strcpy(cont_add,"-----");
strcpy(tel_no,"999");
}
~database() //destructor
{
}
void get_info()
{
cout<<"Enter the name:"; cin>>name;
cout<<"\nEnter the Date of Birth:"; cin>>date_of_birth;
cout<<"\nEnter the contact address:"; cin>>cont_add;
cout<<"\nEnter the telephone no(please mention your STD code also):"; cin>>tel_no;
}
friend class extra;
friend void show(database a,extra b);
};
class extra
{
int height,weight;
char blood_group[3],in_pol_no[10],drvng_lic_no[10];
public:
extra()
{
height=180;
weight=60;
strcpy(blood_group,"---");
strcpy(in_pol_no,"---");
strcpy(drvng_lic_no,"----");
}
void get_extra_info()
{
cout<<"Enter the height(in cms):"; cin>>height;
cout<<"\nEnter the weight(in kg):"; cin>>weight;
cout<<"\nEnter the blood group:"; cin>>blood_group;
cout<<"\nEnter the insurance policy number:"; cin>>in_pol_no;
cout<<"\nEnter the driving license number(may be alphanumeric:"; cin>>drvng_lic_no;
}
~extra()
{
}
friend void show(database a,extra b);
};
void main()
{
int cnt,num;
clrscr();
cout<<"Enter the no of entries:"; cin>>num;
database *d[10];
extra *e[10];
for(cnt=0;cntget_info();
e[cnt]=new extra;
e[cnt]->get_extra_info();
}
for(cnt=0;cnt cout<<"\n"< }

No comments:

Post a Comment