#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
#include<stdio.h>
#include<fstream.h>
#include<string.h>
class stu
{
char roll[20],name[30];
public:
void getstu()
{
cout<<"\n\t Enter Roll and Name: ";
cout<<"\n\t Roll: ";
cin>>roll;
cout<<"\n\t Name: ";
gets(name);
}
void putstu()
{
cout<<"\n\t Details of Students";
cout<<"\n"<<setw(15)<<roll;
cout<<setw(25);
puts(name);
}
void editstu()
{
cout<<"\n\t Roll No: "<<roll;;
cout<<"\n\t Enter Roll and Name: ";
cout<<"\n\t Roll: ";
cin>>roll;
cout<<"\n\t Name: ";
gets(name);
}
void report()
{cout<<roll<<setw(20)<<name;}
char* retroll()
{return roll;}
};
/*************************************************************************
/*******************************************************************/
fstream f1,f2;
stu s;
//**********************************************************************
void getdata()
{
char ch;
f1.open("stu.dat",ios::out|ios::app);
do
{
clrscr();
s.getstu();
f1.write((char *)&s,sizeof(s));
cout<<"\n\t Do You want to add more record:\n";
cin>>ch;
}
while(ch=='y'||ch=='Y');
f1.close();
}
void putdata()
{
clrscr();
f1.open("stu.dat",ios::in);
if(!f1)
{
cout<<"\n\t\t********* Records Are Empty*************\n";
getch();
return;
}
cout<<"\n====================STUDENT DETAILS==========================";
cout<<"\n\t************************************************************";
cout<<"\n\t Roll No."<<setw(20)<<"Name";
while(f1.read((char *)&s,sizeof(s)));
{s.report();}
f1.close();
cout<<"\n\t Press any key to go back:";
getch();
}
void putsdata()
{ char n[15];
cout<<"\n\t Individual Student Details:\n";
int flag=0;
f1.open("stu.dat",ios::in);
while(f1.read((char*)&s,sizeof(s)))
{
if((strcmpi(s.retroll(),n)==0))
{
s.putstu();
flag=1;
}
}
f1.close();
if(flag==0)
cout<<"\n\nStudent does not exist";
getch();
}
void main()
{
clrscr();
char ch;
cout<<"\n\t\tMake Your Choice\n";
cout<<"\nPress 1 for Add student:";
cout<<"\nPress 2 for show all student details:";
cout<<"\npress 3 for show individual student data: ";
cout<<"\n\t press any option===> ";
cin>>ch;
switch(ch)
{
case '1': getdata(); break;
case '2': putdata(); break;
case '3': putsdata(); break;
default: cout<<"poor choice:";
getch();
}
}
No comments:
Post a Comment