Beruflich Dokumente
Kultur Dokumente
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;
}
};
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)
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]
----------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
Enter ur choice=> 6