/*
Problem Statement:
Design a base class consisting of the data members such
as name of the student,roll number and subject.The derived class
consists of the data members subject code ,internal assessment
and university examination marks.Construct a virtual base
class for the item name of the student and roll number.
The program should have these facilities:-
i) Build a master table
ii) List a table
iii) Insert a new entry
iv) Delete old entry
v) Edit an entry
vi) Search for a record
*/
Include:
iostream.h
conio.h
fstream.h
iomanip.h
class base1
{
public:
char name[10],sub[10];
int rno;
};
class derived: public base1
{
protected:
int subco,umark,iass;
public:
void getdata(derived );
void putdata(derived );
void insert(derived);
derived edit(derived);
void delet(derived);
int search(int,derived);
};
void derived::getdata(derived d)
{
fstream file;
file.open("ABC.text",ios::in|ios::out);
cout<<"\n*****Enter student information********";
cout<<"\n\nEnter name:";
cin>>name;
cout<<"\nEnter roll no:";
cin>>rno;
cout<<"\nEnter subject:";
cin>>sub;
cout<<"\nEnter subject code:";
cin>>subco;
cout<<"\nEnter university marks:";
cin>>umark;
cout<<"\nEnter internal assessment:";
cin>>iass;
file.write((char *)& d,sizeof(d));
file.close();
}
void derived::putdata(derived d)
{
fstream file;
file.open("ABC.text",ios::in|ios::out);
file.read((char *)&d,sizeof(d));
cout<<"\n\n"< file.close();
}
void derived::insert(derived d)
{
getdata(d);
}
void derived ::delet(derived d )
{
derived *p;
p=&d;
delete p;
}
derived derived ::edit(derived d)
{
int ch;
cout<<"\nWhich field you want to modify:";
do
{
cout<<"\n1 for name\n2 for Roll No\n3 for sub \n4 for sub code \n5 for mark \n6 for int ass\n7 for exit.\n";
cin>>ch;
switch(ch)
{
case 1:
cout<<"\nEnter name:";
cin>>d.name;
break;
case 2:
cout<<"\nEnter roll no:";
cin>>d.rno;
break;
case 3:
cout<<"\nEnter subject:";
cin>>d.sub;
break;
case 4:
cout<<"\nEnter subject code:";
cin>>d.subco;
break;
case 5:
cout<<"\nEnter marks:";
cin>>d.umark;
case 6:
cout<<"\nEnter internal assessnment:";
cin>>iass;
}
}while(ch<7);
return d;
}
int derived :: search(int key,derived d)
{
int flag;
if(key==d.rno)
{
flag=1;
return flag;
}
}
void main()
{
derived D[15];
int ch,n,key,flag=0;
clrscr();
do
{
cout<<"\n\nMENU:";
cout<<"\n1.Build master table";
cout<<"\n2.Display";
cout<<"\n3.Insert";
cout<<"\n4.Delete";
cout<<"\n5.Edit";
cout<<"\n6.Search";
cout<<"\n7.Exit";
cout<<"\nEnter your choice:";
cin>>ch;
switch(ch)
{
case 1:
cout<<"\nHow many records u want in this table:";
cin>>n;
for(int i=0;i {
D[i].getdata(D[i]);
}
break;
case 2:
clrscr();
cout<<"\nDATABASE:";
cout<<"\nName\tRollNo\tSub\tSubCode\tMarks\tInternalass";
for(i=0;i {
D[i].putdata(D[i]);
}
break;
case 3:
D[n].insert(D[n]);
n=n+1;
break;
case 4:
cout<<"\nEnter record that you want to delete (RollNo as key):";
cin>>key;
for(i=0;i {
if(key==D[i].rno)
{
flag=1;
if(flag==1)
{
while(i {
D[i]=D[i+1];
i++;
}
D[i].delet(D[i]);
cout<<"\nDeleted successfully";
break;
}
}
else
flag=0;
}
if(flag==0)
cout<<"\nRecord not found";
n=n-1;
break;
case 5:
cout<<"\nEnter record that you want to modify (Roll No as key):";
cin>>key;
for(i=0;i {
if(key==D[i].rno)
{
flag=1;
if(flag==1)
break;
}
}
if(flag==1)
{
D[i]=D[i].edit(D[i]);
}
else
cout<<"\nRecord is not found.";
break;
case 6:
cout<<"\nEnter record that you want to search (RollNo as key):";
cin>>key;
flag=0;
for(i=0;i {
flag=D[i].search(key,D[i]);
if(flag==1)
break;
}
if(flag==1)
cout<<"\nRecord is found";
else
cout<<"\nRecord is not found";
break;
}
}while(ch<7);
getch();
}
Problem Statement:
Design a base class consisting of the data members such
as name of the student,roll number and subject.The derived class
consists of the data members subject code ,internal assessment
and university examination marks.Construct a virtual base
class for the item name of the student and roll number.
The program should have these facilities:-
i) Build a master table
ii) List a table
iii) Insert a new entry
iv) Delete old entry
v) Edit an entry
vi) Search for a record
*/
Include:
iostream.h
conio.h
fstream.h
iomanip.h
class base1
{
public:
char name[10],sub[10];
int rno;
};
class derived: public base1
{
protected:
int subco,umark,iass;
public:
void getdata(derived );
void putdata(derived );
void insert(derived);
derived edit(derived);
void delet(derived);
int search(int,derived);
};
void derived::getdata(derived d)
{
fstream file;
file.open("ABC.text",ios::in|ios::out);
cout<<"\n*****Enter student information********";
cout<<"\n\nEnter name:";
cin>>name;
cout<<"\nEnter roll no:";
cin>>rno;
cout<<"\nEnter subject:";
cin>>sub;
cout<<"\nEnter subject code:";
cin>>subco;
cout<<"\nEnter university marks:";
cin>>umark;
cout<<"\nEnter internal assessment:";
cin>>iass;
file.write((char *)& d,sizeof(d));
file.close();
}
void derived::putdata(derived d)
{
fstream file;
file.open("ABC.text",ios::in|ios::out);
file.read((char *)&d,sizeof(d));
cout<<"\n\n"<
}
void derived::insert(derived d)
{
getdata(d);
}
void derived ::delet(derived d )
{
derived *p;
p=&d;
delete p;
}
derived derived ::edit(derived d)
{
int ch;
cout<<"\nWhich field you want to modify:";
do
{
cout<<"\n1 for name\n2 for Roll No\n3 for sub \n4 for sub code \n5 for mark \n6 for int ass\n7 for exit.\n";
cin>>ch;
switch(ch)
{
case 1:
cout<<"\nEnter name:";
cin>>d.name;
break;
case 2:
cout<<"\nEnter roll no:";
cin>>d.rno;
break;
case 3:
cout<<"\nEnter subject:";
cin>>d.sub;
break;
case 4:
cout<<"\nEnter subject code:";
cin>>d.subco;
break;
case 5:
cout<<"\nEnter marks:";
cin>>d.umark;
case 6:
cout<<"\nEnter internal assessnment:";
cin>>iass;
}
}while(ch<7);
return d;
}
int derived :: search(int key,derived d)
{
int flag;
if(key==d.rno)
{
flag=1;
return flag;
}
}
void main()
{
derived D[15];
int ch,n,key,flag=0;
clrscr();
do
{
cout<<"\n\nMENU:";
cout<<"\n1.Build master table";
cout<<"\n2.Display";
cout<<"\n3.Insert";
cout<<"\n4.Delete";
cout<<"\n5.Edit";
cout<<"\n6.Search";
cout<<"\n7.Exit";
cout<<"\nEnter your choice:";
cin>>ch;
switch(ch)
{
case 1:
cout<<"\nHow many records u want in this table:";
cin>>n;
for(int i=0;i
D[i].getdata(D[i]);
}
break;
case 2:
clrscr();
cout<<"\nDATABASE:";
cout<<"\nName\tRollNo\tSub\tSubCode\tMarks\tInternalass";
for(i=0;i
D[i].putdata(D[i]);
}
break;
case 3:
D[n].insert(D[n]);
n=n+1;
break;
case 4:
cout<<"\nEnter record that you want to delete (RollNo as key):";
cin>>key;
for(i=0;i
if(key==D[i].rno)
{
flag=1;
if(flag==1)
{
while(i
D[i]=D[i+1];
i++;
}
D[i].delet(D[i]);
cout<<"\nDeleted successfully";
break;
}
}
else
flag=0;
}
if(flag==0)
cout<<"\nRecord not found";
n=n-1;
break;
case 5:
cout<<"\nEnter record that you want to modify (Roll No as key):";
cin>>key;
for(i=0;i
if(key==D[i].rno)
{
flag=1;
if(flag==1)
break;
}
}
if(flag==1)
{
D[i]=D[i].edit(D[i]);
}
else
cout<<"\nRecord is not found.";
break;
case 6:
cout<<"\nEnter record that you want to search (RollNo as key):";
cin>>key;
flag=0;
for(i=0;i
flag=D[i].search(key,D[i]);
if(flag==1)
break;
}
if(flag==1)
cout<<"\nRecord is found";
else
cout<<"\nRecord is not found";
break;
}
}while(ch<7);
getch();
}
Comments
Post a Comment