Sie sind auf Seite 1von 8

-------------------------------------------------Assignment No.

7
Title:-Student-Database by using Pointer & Virtual
Functions.
Roll No.256
Batch:-C
-------------------------------------------------#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
#include<string.h>
class base
{
char name[10];
char sub[10];
public:
int roll_no;
virtual void getdata()
{
cout<<"\nEnter the roll no.of student=> ";
cin>>roll_no;
cout<<"\nEnter the name of student=> ";
cin>>name;
cout<<"\nEnter the name of subject=> ";
cin>>sub;
}
virtual void putdata()
{
cout<<"\n"<<roll_no<<"\t"<<name<<"\t"<<sub;
}
};

class derived:public base


{
int subcode,intr_mar ,ex_mar ;
public:
void getdata()
{
cout<<"\nEnter the code of subject=> ";
cin>>subcode;
cout<<"\nEnter the internal mar s of student=> ";
cin>>intr_mar ;
cout<<"\nEnter the University Exam Mar s=> ";
cin>>ex_mar ;
}
void putdata()
{
cout<<"\t"<<subcode<<"\t"<<intr_mar <<"\t"<<ex_mar ;
}
};

void main()
{
int ch,n,x,flag=0;
base b[20];
base *bptr[20];
derived d[20];
do
{
clrscr();
cout<<"\n----------MENU----------";
cout<<"\n1.Insert.";
cout<<"\n2.Search.";
cout<<"\n3.Edit.";
cout<<"\n4.Delete.";
cout<<"\n5.Build Master Table.";
cout<<"\n6.Exit.";
cout<<"\n------------------------\n";
cout<<"\nEnter ur choice=> ";
cin>>ch;
switch(ch)
{
case 1:
cout<<"\nHow many records u wants 2 insert=>";
cin>>n;
for(int i=0;i<n;i++)
{
cout<<"\n\n\tSTUDENT:["<<i+1<<"]\n";
bptr[i]=&b[i];
bptr[i]->getdata();
bptr[i]=&d[i];
bptr[i]->getdata();
}
getch();
brea ;
case 2:
cout<<"\nEnter the roll no.of student to
search record=>"
;
cin>>x;
for(i=0;i<n;i++)
{
bptr[i]=&b[i];
if(x==bptr[i]->roll_no)
{
flag=1;
cout<<"\nRecord get found as=>\n\n";
cout<<"\n-----------MASTER-TABLE-------";
cout<<"\nRollNo\tName\tSubName\tSubCode\tTW\tExMar s";
cout<<"\n--------------------------";
bptr[i]->putdata();
bptr[i]=&d[i];
bptr[i]->putdata();
cout<<"\n---------------------------------------";
}
}
if(flag==0)

cout<<"\nRecord is not found....!";


getch();
brea ;
case 3:
cout<<"\nEnter the roll no.of student to
update record=>"
;
cin>>x;
for(i=0;i<n;i++)
{
bptr[i]=&b[i];
if(x==bptr[i]->roll_no)
{
cout<<"\nEnter new record=>\n";
bptr[i]->getdata();
bptr[i]=&d[i];
bptr[i]->getdata();
goto ll1;
}
}
getch();
brea ;
case 4:
cout<<"\nEnter the roll no.of student to
delete record=>";
cin>>x;
for(i=0;i<n;i++)
{
if(x==b[i].roll_no)
{
b[i]=b[i+1];
bptr[i]=&b[i];
d[i]=d[i+1];
bptr[i]=&d[i];
n--;
cout<<"\nRecord delete successfully.....!";
goto ll1;
}
}
getch();
brea ;
case 5:
cout<<"\nMaster Table Is Get Builted As=>\n\n";
ll1:
cout<<"\n--------MASTER-TABLE--------";
cout<<"\nRollNo\tName\tSubName\tSubCode\tTW\tExMar s";
cout<<"\n-------------------------------------------";
for(i=0;i<n;i++)
{
bptr[i]=&b[i];
bptr[i]->putdata();
bptr[i]=&d[i];
bptr[i]->putdata();
}
cout<<"\n--------------------------------------";
getch();
brea ;
case 6:

exit(0);
brea ;
default:
cout<<"\nPlz enter correct
choice........!"
;
getch();
}
}while(ch!=6);
}

--------------------OUTPUT-------------------------------MENU---------1.Insert.
2.Search.
3.Edit.
4.Delete.
5.Build Master Table.
6.Exit.
-----------------------Enter ur choice=> 1
How many records u wants 2 insert=> 3
STUDENT:[1]
Enter the roll no.of student=> 1
Enter the name of student=> Neha
Enter the name of subject=> OOPS
Enter the code of subject=> 123
Enter the internal mar s of student=> 40
Enter the University Exam Mar s=> 82

STUDENT:[2]

Enter the roll no.of student=> 2


Enter the name of student=> Amruta
Enter the name of subject=> MIT
Enter the code of subject=> 35
Enter the internal mar s of student=> 30
Enter the University Exam Mar s=> 90
STUDENT:[3]
Enter the roll no.of student=> 3
Enter the name of student=> Rajani
Enter the name of subject=> DS
Enter the code of subject=> 100
Enter the internal mar s of student=> 45
Enter the University Exam Mar s=> 70
----------MENU---------1.Insert.
2.Search.
3.Edit.
4.Delete.
5.Build Master Table.
6.Exit.
-----------------------Enter ur choice=> 5
Master Table Is Get Builted As=>
-----------------MASTER-TABLE------------------RollNo Name
SubName SubCode TW
ExMar s
-----------------------------------------------1
Neha
OOPS
123
40
82
2
Amruta
MIT
35
30
90
3
Rajani
DS
100
45
70
---------------------------------------------------------MENU---------1.Insert.
2.Search.
3.Edit.
4.Delete.
5.Build Master Table.
6.Exit.
-----------------------Enter ur choice=> 2

Enter the roll no.of student to search record=> 2


Record get found as=>
-----------------MASTER-TABLE------------------RollNo Name
SubName SubCode TW
ExMar s
-----------------------------------------------2
Amruta
MIT
35
30
90
------------------------------------------------

----------MENU---------1.Insert.
2.Search.
3.Edit.
4.Delete.
5.Build Master Table.
6.Exit.
-----------------------Enter ur choice=> 3
Enter the roll no.of student to update record=> 3
Enter new record=>
Enter the roll no.of student=> 4
Enter the name of student=> Riya
Enter the name of subject=> DIS
Enter the code of subject=> 102
Enter the internal mar s of student=> 25
Enter the University Exam Mar s=> 85
-----------------MASTER-TABLE------------------RollNo Name
SubName SubCode TW
ExMar s
-----------------------------------------------1
Neha
OOPS
123
40
82
2
Amruta
MIT
35
30
90
4
Riya
DIS
102
25
85
------------------------------------------------

----------MENU---------1.Insert.
2.Search.

3.Edit.
4.Delete.
5.Build Master Table.
6.Exit.
-----------------------Enter ur choice=> 4
Enter the roll no.of student to delete record=> 4
Record deleted successfully.....!
-----------------MASTER-TABLE------------------RollNo Name
SubName SubCode TW
ExMar s
-----------------------------------------------1
Neha
OOPS
123
40
82
2
Amruta
MIT
35
30
90
---------------------------------------------------------MENU---------1.Insert.
2.Search.
3.Edit.
4.Delete.
5.Build Master Table.
6.Exit.
-----------------------Enter ur choice=> 5

Master Table Is Get Builted As=>


-----------------MASTER-TABLE------------------RollNo Name
SubName SubCode TW
ExMar s
-----------------------------------------------1
Neha
OOPS
123
40
82
2
Amruta
MIT
35
30
90
---------------------------------------------------------MENU---------1.Insert.
2.Search.
3.Edit.
4.Delete.
5.Build Master Table.
6.Exit.
------------------------

Enter ur choice=> 6

Das könnte Ihnen auch gefallen