C++ program to implement concept of inheritance and perform basic operations on it
Design a base class with name,date of birth,blood group and another base class consisting of the data members such as height and weight.Design one more base class consisting of the insurance policy number and contact address.The derived class contains the data members telephone numbers and driving license number. Write a menu driven program to carry out the following things: i) Build a master table ii) Display iii) Insert a new entry iv) Delete entry v) Edit vi) Search for a record
#include<iostream.h>
#include<conio.h>
#include<string.h>
class a
{
private:
char *name,*date,*bg;
int len;
public:
a();
a(char*name1);
void create_a();
void display_a();
};
a::a()
{
this->name='\0';
this->date='\0';
this->bg='\0';
}
a::a(char * name1)
{
len=strlen(name1);
name=new char[len+1];
strcpy(name,name1);
cout<<"Parametrized const......";
}
void a::create_a()
{
char name1[20];
int len;
if(name=='\0')
{
cout<<"\nEnter name=> ";
cin>>name1;
len=strlen(name1);
name=new char[len+1];
strcpy(name,name1);
}
cout<<"\nEnter Date of Birth => ";
cin>>name1;
len=strlen(name1);
date=new char[len+1];
strcpy(date,name1);
cout<<"\nEnter Blood Group => ";
cin>>name1;
len=strlen(name1);
bg=new char[len+1];
strcpy(bg,name1);
}
void a::display_a()
{
cout<<"\n"<<name<<"\t"<<date<<" "<<bg;
}
class b
{
private:
float ht,wt;
public:
b();
void create_b();
void display_b();
};
b::b()
{
ht=wt=0.0;
}
void b::create_b()
{
cout<<"\nEnter Height => ";
cin>>ht;
cout<<"\nEnter Weight => ";
cin>>wt;
}
void b::display_b()
{
cout<<"\t\t"<<ht<<"\t"<<wt;
}
class c
{
private:
long int incno,telno,licno,len;
public:
c();
void create_c();
void display_c();
};
c::c()
{
incno=telno=len=0;
}
void c::create_c()
{
cout<<"\nEnter Liscence no => ";
cin>>licno;
cout<<"\nEnter Incumtax no => ";
cin>>incno;
}
void c::display_c()
{
cout<<"\t"<<licno<<"\t"<<incno;
}
class info:public a,b,c
{
public:
info()
{
a();
b();
c();
}
void create();
void display();
inline void disp()
{
cout<<"\nEnter Record...";
}
friend void show()
{
cout<<"\nName\t\tBirth\tBloog group";
cout<<" Height Weight LICno INC";
}
};
void info::create()
{
create_a();
create_b();
create_c();
}
void info::display()
{
display_a();
display_b();
display_c();
}
void main()
{
clrscr();
int ch,no,del,src;
info obj[20];
do
{
cout<<"\n1.Built Table\n2.Display\n3.Insert new\n4.Delete entry";
cout<<"\n5.Edit\n6.Search record\n7.Exit\nEnter choice no=";
cin>>ch;
switch(ch)
{
case 1:
cout<<"\nEnter how many records ?= ";
cin>>no;
for(int i=0;i<no;i++)
{
obj[i].disp();cout<<i+1;
obj[i].create();
}
break;
case 2:
show();
for(i=0;i<no;i++)
obj[i].display();
break;
case 3:
obj[no].disp();cout<<"To insert at= "<<no+1;
obj[no].create();
no++;
break;
case 4:
cout<<"\nEnter record which to delete = ";
cin>>del;
for(i=del-1;i<no;i++)
{
obj[i]=obj[i+1];
}
no--;
break;
case 5:
cout<<"\nEnter record no to be modify : - ";
cin>>src;
cout<<"\nEnter new record with modification-> ";
obj[src-1].create();
break;
case 6:
cout<<"\nEnter enter search record no:- ";
cin>>src;
if(src<=no)
{
cout<<"\nSearch record :- ";
show();obj[src-1].display();
}
else
cout<<"\nNot present......";
break;
}
}while(ch!=7);
getch();
}
/*
OUTPUT
1.Built Table
2.Display
3.Insert new
4.Delete entry
5.Edit
6.Search record
7.Exit
Enter choice no=1
Enter how many records ?= 2
Enter Record...1
Enter name=> Prashant
Enter Date of Birth => 17\02\92
Enter Blood Group => B+ve
Enter Height => 5.6
Enter Weight => 57
Enter Liscence no => 1234
Enter Incumtax no => 3456
Enter Record...2
Enter name=> Rameshwar
Enter Date of Birth => 12\12\92
Enter Blood Group => O+ve
Enter Height => 6
Enter Weight => 60
Enter Liscence no => 1234
Enter Incumtax no =>2345
1.Built Table
2.Display
3.Insert new
4.Delete entry
5.Edit
6.Search record
7.Exit
Enter choice no=2
Name Birth Bloog group Height Weight LICno INC
Prashant 17\02\92 B+ve 5.6 57 1234 3456
Rameshwar 12\12\92 O+ve 6 60 1234 2345
1.Built Table
2.Display
3.Insert new
4.Delete entry
5.Edit
6.Search record
7.Exit
Enter choice no=3
Enter Record...To insert at= 3
Enter name=> Ramakant
Enter Date of Birth => 13\05\91
Enter Blood Group => O-ve
Enter Height => 6
Enter Weight => 80
Enter Liscence no => 5678
Enter Incumtax no => 5678
1.Built Table
2.Display
3.Insert new
4.Delete entry
5.Edit
6.Search record
7.Exit
Enter choice no=2
Name Birth Bloog group Height Weight LICno INC
Prashant 17\02\92 B+ve 5.6 57 1234 3456
Rameshwar 12\12\92 O+ve 6 60 1234 2345
Ramakant 13\05\91 O-ve 6 80 5678 5678
1.Built Table
2.Display
3.Insert new
4.Delete entry
5.Edit
6.Search record
7.Exit
Enter choice no=4
Enter record which to delete = 2
1.Built Table
2.Display
3.Insert new
4.Delete entry
5.Edit
6.Search record
7.Exit
Enter choice no=2
Name Birth Bloog group Height Weight LICno INC
Prashant 17\02\92 B+ve 5.6 57 1234 3456
Ramakant 13\05\91 O-ve 6 80 5678 5678
1.Built Table
2.Display
3.Insert new
4.Delete entry
5.Edit
6.Search record
7.Exit
Enter choice no=5
Enter record no to be modify : - 2
Enter new record with modification->
Enter Date of Birth => 12\12\92
Enter Blood Group => O+ve
Enter Height => 5.2
Enter Weight => 60
Enter Liscence no => 1100
Enter Incumtax no => 2222
1.Built Table
2.Display
3.Insert new
4.Delete entry
5.Edit
6.Search record
7.Exit
Enter choice no=2
Name Birth Bloog group Height Weight LICno INC
Prashant 17\02\92 B+ve 5.6 57 1234 3456
Ramakant 12\12\92 O+ve 5.2 60 1100 2222
1.Built Table
2.Display
3.Insert new
4.Delete entry
5.Edit
6.Search record
7.Exit
Enter choice no=6
Enter enter search record no:- 3
Not present......
1.Built Table
2.Display
3.Insert new
4.Delete entry
5.Edit
6.Search record
7.Exit
Enter choice no=6
Enter enter search record no:- 2
Search record :-
Name Birth Bloog group Height Weight LICno INC
Ramakant 12\12\92 O+ve 5.2 60 1100 2222
1.Built Table
2.Display
3.Insert new
4.Delete entry
5.Edit
6.Search record
7.Exit
Enter choice no=7
*/
0 comments:
Post a Comment