1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
|
#include <iostream>
#include<string.h>
#include<fstream>
#include<conio.h>
#include<iomanip>
using namespace std;
class student{
char admno[6];
char name[20];
char stbno[6];
int token;
public:
void create_student()
{
cout<<"\nNEW STUDENT ENTRY...\n";
cout<<"\nEnter The admission no. ";
cin.getline(admno,6);
cout<<"\n\nEnter The Name of The Student ";
cin.getline(name,20);
token=0;
stbno[0]='/0';
getch();
}
void show_student()
{
cout<<"\nAdmission no. : ";
cout.write(admno,'\n');
cout<<"\nStudent Name : ";
cout.write(name,'\n');
cout<<"\nNo of Book issued : "<<token;
if(token!=0)
{
cout<<"\nBook No: ";
cout.write(stbno,'\n');
}
}
void report()
{
int l=strlen(admno), m=strlen(name);
cout<<"\t";
cout.write(admno, l);
cout<<"\t\t";
cout.write(name, m);
cout<<setw(10)<<token<<endl;
}
char* retadmno()
{
return admno;
}
};
student st;
fstream fp, f;
void write_student()
{
char ch;
fp.open("student.txt",ios::out|ios::app);
do
{
st.create_student();
fp.write((char*)&st,sizeof(st));
cout<<"\n\ndo you want to add more record..(y/n?)";
ch=getch();
cout<<endl;
}while(ch=='y'||ch=='Y');
fp.close();
}
void display_alls()
{
fp.open("student.txt",ios::in);
if(!fp)
{
cout<<"ERROR!!! FILE COULD NOT BE OPEN ";
getch();
return;
}
cout<<"\n\n\t\tSTUDENT LIST\n\n";
cout<<"==================================================================\n";
cout<<"\tAdmission No."<<setw(10)<<"Name"<<setw(20)<<"Book Issued\n";
cout<<"==================================================================\n";
while(fp.read((char*)&st,sizeof(student)))
{
st.report();
}
fp.close();
getch();
}
void admin_menu()
{
int ch2;
cout<<"\n\n\n\tADMINISTRATOR MENU";
cout<<"\n\n\t1.CREATE STUDENT RECORD";
cout<<"\n\n\t2.DISPLAY ALL STUDENTS RECORD";
cin>>ch2;
cin.ignore();
switch(ch2)
{
case 1: write_student();break;
case 2: display_alls();break;
}
}
int main()
{
admin_menu();
return 0;
}
|