0% found this document useful (0 votes)
16 views

Computer

The document contains C++ code for classes book and student to manage a library. The book class stores book details like number, name, author. The student class stores admission number, name, issued book details. Functions are defined to create, display, modify records and write/read from a data file.

Uploaded by

Janhavi Misra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

Computer

The document contains C++ code for classes book and student to manage a library. The book class stores book details like number, name, author. The student class stores admission number, name, issued book details. Functions are defined to create, display, modify records and write/read from a data file.

Uploaded by

Janhavi Misra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

#include<fstream.

h>
#include<conio.h>
#include<stdio.h>
#include<process.h>
#include<string.h>
#include<iomanip.h>
class book{char bno[6];
char bname[50];
char aname[20];
public:
void create_book()
{
cout<<"\nNEW BOOK ENTRY...\n";
cout<<"\nEnter The book no.";
cin>>bno;
cout<<"\n\nEnter The Name of The Book
";
gets(bname);
cout<<"\n\nEnter The Author's Name ";
gets(aname);
cout<<"\n\n\nBook Created..";}

void show_book()
{
cout<<"\nBook no. : "<<bno;
cout<<"\nBook Name : ";
puts(bname);
cout<<"Author Name : ";
puts(aname);
}
void modify_book()
{
cout<<"\nBook no. : "<<bno;
cout<<"\nModify Book Name : ";
gets(bname);
cout<<"\nModify Author's Name of Book :
";
gets(aname);
}
char* retbno()
{
return bno;
}
Void report()
{

cout<<bno<<setw(30)<<bname<<setw(30)<<ana
me<<endl;
}
};
//class ends hereclass student{char
admno[6];
char name[20];
char stbno[6];
int token;
public:
void create_student()
{
clrscr();
cout<<"\nNEW STUDENT ENTRY...\n";
cout<<"\nEnter The admission no. ";
cin>>admno;
cout<<"\n\nEnter The Name of The
Student ";
gets(name);
token=0;
stbno[0]='/0';
cout<<"\n\nStudent Record Created..";
}
void show_student()
{
cout<<"\nAdmission no. :
"<<admno;cout<<"\nStudent Name : ";
puts(name);
cout<<"\nNo of Book issued :
"<<token;
if(token==1)cout<<"\nBook No
"<<stbno;
}
void modify_student()
{
cout<<"\nAdmission no. : "<<admno;
cout<<"\nModify Student Name : ";
gets(name);
}
char* retadmno()
{
return admno;
}
char* retstbno()
{
return stbno;
}
int rettoken()
{
return token;
}
Voidaddtoken()
{
token=1;
}
void resettoken()
{
token=0;
}
void getstbno(char t[]){strcpy(stbno
,t);}void
report(){cout<<"\t"<<admno<<setw(20)<
<name<<setw(10)<<token<<endl;}}; //cl
ass ends herefstream fp,fp1;book
bk;student
st;//********************************
*******************************// fun
ction to write in file//*************
*************************************
**************void write_book(){char
ch;fp.open("book.dat",ios::out|ios::a
pp);do{clrscr();bk.create_book();fp.w
rite((char*)&bk,sizeof(book));cout<<"
\n\nDo you want to add more
record..(y/n?)";cin>>ch;}while(ch=='y
'||ch=='Y');fp.close();}void
write_student(){char
ch;fp.open("student.dat",ios::out|ios
::app);do{st.create_student();fp.writ
e((char*)&st,sizeof(student));cout<<"
\n\ndo you want to add more
record..(y/n?)";cin>>ch;}while(ch=='y
'||ch=='Y');fp.close();}//***********
*************************************
***************// function to read sp
ecific record from file//************
*************************************
***************void display_spb(char
n[]){cout<<"\nBOOK DETAILS\n";int
flag=0;fp.open("book.dat",ios::in);wh
ile(fp.read((char*)&bk,sizeof(book)))
{if(strcmpi(bk.retbno(),n)==0)

You might also like