Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<fstream.h>
- #include<conio.h>
- #include<stdlib.h>
- #include<stdio.h>
- #include<string.h>
- #include<iomanip.h>
- #include<ctype.h>
- class practical
- {
- int adno;
- char name[100];
- char projname[100];
- float projmark;
- float vivamark;
- float progmark;
- float assignmark;
- float totmark;
- public:
- void input()
- {
- cout<<"\n\t\t\tEnter Admission Number: ";
- cin>>adno;
- cout<<"\t\t\tEnter Name of Student: ";
- gets(name);
- cout<<"\t\t\tEnter Name of Project: ";
- gets(projname);
- cout<<"\t\t\tEnter Marks obtained in VIVA: ";
- cin>>vivamark;
- cout<<"\t\t\tEnter Marks obtained from Project: ";
- cin>>projmark;
- cout<<"\t\t\tEnter Marks obtained from Program: ";
- cin>>progmark;
- cout<<"\t\t\tEnter Marks obtained from Assignment: ";
- cin>>assignmark;
- totmark=vivamark+projmark+progmark+assignmark;
- }
- void output()
- {
- cout<<setw(5)<<adno<<setw(10)<<name<<setw(15)<<projname<<setw(10)<<vivamark<<setw(10)<<projmark<<setw(10)<<progmark<<setw(10)<<assignmark<<setw(10)<<totmark<<endl;
- }
- int getad()
- {
- return adno;
- }
- char* getname()
- {
- return name;
- }
- char* getproj()
- {
- return projname;
- }
- float getviva()
- {
- return vivamark;
- }
- float getprojmk()
- {
- return projmark;
- }
- float getprogmk()
- {
- return progmark;
- }
- float getassign()
- {
- return assignmark;
- }
- float gettotal()
- {
- return totmark;
- }
- void modify()
- {
- cout<<"\t\t\tEnter Name of Student: ";
- gets(name);
- cout<<"\t\t\tEnter Name of Project: ";
- gets(projname);
- cout<<"\t\t\tEnter Marks obtained in VIVA: ";
- cin>>vivamark;
- cout<<"\t\t\tEnter Marks obtained from Project: ";
- cin>>projmark;
- cout<<"\t\t\tEnter Marks obtained from Program: ";
- cin>>progmark;
- cout<<"\t\t\tEnter Marks obtained from Assignment: ";
- cin>>assignmark;
- totmark=vivamark+projmark+progmark+assignmark;
- }
- };
- void header()
- {
- clrscr();
- cout<<"******************************** Display Details *****************************\n";
- cout<<"\n"<<setw(5)<<"Ad NO"<<setw(10)<<"Name"<<setw(15)<<"Proj.Name"<<setw(10)<<"VivaMark"<<setw(10)<<"Proj.Mark"<<setw(10)<<"Prog.Mark"<<setw(10)<<"Ass.Mark"<<setw(10)<<"Tot.Mark"<<endl;
- }
- void addrec()
- {
- clrscr();
- fstream f1;
- f1.open("practical.dat",ios::app|ios::binary);
- practical p1;
- p1.input();
- f1.write((char*)&p1,sizeof(p1));
- f1.close();
- }
- void disprec()
- {
- clrscr();
- fstream f1;
- f1.open("practical.dat",ios::in|ios::binary);
- practical p1;
- header();
- if(f1==NULL)
- cout<<"Error in Loading"<<endl;
- else
- {
- int x=0;
- while(f1.read((char*)&p1,sizeof(p1)))
- {
- p1.output();
- x++;
- }
- cout<<"\n\n\n\t\t\tTotal Number of Students: "<<x<<endl;
- }
- f1.close();
- }
- void sadno()
- {
- clrscr();
- fstream f1;
- practical p1;
- f1.open("practical.dat",ios::in|ios::binary);
- if(f1==NULL)
- cout<<"\t\t\tError in Loading"<<endl;
- else
- {
- int a,x=0;
- cout<<"\t\t\tEnter Admission Number to search for: ";
- cin>>a;
- header();
- while(f1.read((char*)&p1,sizeof(p1)))
- {
- if(p1.getad()==a)
- {
- p1.output();
- x=1;
- }
- }
- if(x==0)
- cout<<"\n\n\n\t\t\tAdmission Number does not exist"<<endl;
- }
- f1.close();
- }
- void sname()
- {
- clrscr();
- fstream f1;
- practical p1;
- f1.open("practical.dat",ios::in|ios::binary);
- if(f1==NULL)
- cout<<"\t\t\tError in Loading"<<endl;
- else
- {
- int x=0;
- char name[100];
- cout<<"\t\t\tEnter Name to search for: ";
- gets(name);
- header();
- while(f1.read((char*)&p1,sizeof(p1)))
- {
- if(strcmpi(p1.getname(),name)==0)
- {
- p1.output();
- x=1;
- }
- }
- if(x==0)
- cout<<"\n\n\t\t\tName does not exist"<<endl;
- }
- f1.close();
- }
- void sproj()
- {
- clrscr();
- fstream f1;
- practical p1;
- f1.open("practical.dat",ios::in|ios::binary);
- if(f1==NULL)
- cout<<"\t\t\tError in Loading"<<endl;
- else
- {
- int x=0;
- char proj[100];
- cout<<"\t\t\tEnter Project Name to search for: ";
- gets(proj);
- header();
- while(f1.read((char*)&p1,sizeof(p1)))
- {
- if(strcmpi(p1.getproj(),proj)==0)
- {
- p1.output();
- x=1;
- }
- }
- if(x==0)
- cout<<"\n\n\t\t\tProject Name does not exist"<<endl;
- }
- f1.close();
- }
- void rangemark()
- {
- clrscr();
- fstream f1;
- practical p1;
- f1.open("practical.dat",ios::in|ios::binary);
- if(f1==NULL)
- cout<<"\t\t\tError in Loading"<<endl;
- else
- {
- int x=0;
- int minmk,maxmk;
- cout<<"\t\t\tEnter Minimum Mark: ";
- cin>>minmk;
- cout<<"\t\t\tEnter Maximum Mark: ";
- cin>>maxmk;
- header();
- while(f1.read((char*)&p1,sizeof(p1)))
- {
- if(p1.gettotal()>=minmk && p1.gettotal()<=maxmk)
- {
- p1.output();
- ++x;
- }
- }
- if(x==0)
- cout<<"\n\n\t\t\tNo Student in Range"<<endl;
- else
- cout<<"\n\n\t\t\t"<<x<<" is the no. of Students who secured within "<<minmk<<" - "<<maxmk<<endl;
- }
- f1.close();
- }
- void topper_lower()
- {
- clrscr();
- fstream f1;
- practical p1,min,max;
- f1.open("practical.dat",ios::in|ios::binary);
- if(f1==NULL)
- cout<<"\t\t\tError in Loading"<<endl;
- else
- {
- f1.read((char*)&p1,sizeof(p1)) ;
- min=max=p1;
- while(f1.read((char*)&p1,sizeof(p1)))
- {
- if(p1.gettotal()>max.gettotal())
- {
- max=p1;
- }
- if(p1.gettotal()<min.gettotal())
- {
- min=p1;
- }
- }
- cout<<"\n\n\t\t\tHighest Scorer: "<<endl;
- header();
- max.output();
- cout<<"\n\n\n\n\t\t\tLowest Scorer: "<<endl;
- header();
- min.output();
- }
- f1.close();
- }
- void fail()
- {
- clrscr();
- fstream f1;
- practical p1;
- f1.open("practical.dat",ios::in|ios::binary);
- if(f1==NULL)
- cout<<"\t\t\tError in Loading"<<endl;
- else
- {
- int x=0;
- header();
- while(f1.read((char*)&p1,sizeof(p1)))
- {
- if(p1.gettotal()<=10)
- {
- p1.output();
- ++x;
- }
- }
- if(x==0)
- cout<<"\n\n\t\t\tNo Student Failed"<<endl;
- else
- cout<<"\n\n\t\t\t"<<x<<" number of Students failed"<<endl;
- }
- f1.close();
- }
- void removerec()
- {
- clrscr();
- fstream f1,f2;
- practical p1;
- f1.open("practical.dat",ios::in|ios::binary);
- f2.open("temp.dat",ios::out|ios::binary);
- if(f1==NULL)
- cout<<"\t\t\tError in Loading"<<endl;
- else
- {
- int a,x=0;
- cout<<"\t\t\tEnter Admission Number to Delete: ";
- cin>>a;
- while(f1.read((char*)&p1,sizeof(p1)))
- {
- if(p1.getad()!=a)
- {
- f2.write((char *)&p1,sizeof(p1));
- }
- else
- {
- clrscr();
- char ch;
- x=1;
- header();
- p1.output();
- cout<<"\n\n\t\t\tConfirm Delete (Y/N): ";
- cin>>ch;
- if(ch!='y'&&ch!='Y')
- {
- f2.write((char *)&p1,sizeof(p1));
- cout<<"\n\n\t\t\tRecord Not Deleted ";
- }
- else
- cout<<"\n\n\t\t\tRecord Deleted ";
- }
- }
- if(x==0)
- cout<<"\n\n\t\t\tAdmission Number does not exist."<<endl;
- f1.close();
- f2.close();
- remove("practical.dat");
- rename("temp.dat","practical.dat");
- }
- f1.close();
- }
- void modifyrec()
- {
- clrscr();
- fstream f1;
- practical p1;
- f1.open("practical.dat",ios::in|ios::out|ios::binary);
- if(f1==NULL)
- cout<<"\t\t\tError in Loading"<<endl;
- else
- {
- int a,x=0,pos;
- cout<<"\t\t\tEnter Admission Number for Edit : ";
- cin>>a;
- while(f1.read((char*)&p1,sizeof(p1)))
- {
- if(p1.getad()==a)
- {
- cout<<"\n\t\t\tDetails of "<<a<<" are follows "<<endl;
- header();
- p1.output();
- cout<<"\n\t\t\tEnter new value for "<<endl;
- p1.modify();
- pos=f1.tellp();
- f1.seekp(pos-sizeof(p1));
- f1.write((char *)&p1,sizeof(p1));
- x=1;
- }
- }
- if(x==0)
- cout<<"\n\n\t\t\tAdmission Number does not exist"<<endl;
- }
- f1.close();
- }
- void mainmenu()
- {
- clrscr();
- int a;
- clrscr();
- do
- {
- clrscr();
- cout<<endl<<endl<<endl<<endl<<endl<<endl<<"\t\t";
- for(int i=1;i<50;i++)
- cout<<"*";
- cout<<endl;
- cout<<"\t\t*\t1-Add Record\t\t\t\t*"<<endl;
- cout<<"\t\t*\t2-Display Record\t\t\t*"<<endl;
- cout<<"\t\t*\t3-Search by Admission Number\t\t*"<<endl;
- cout<<"\t\t*\t4-Search by Student Name\t\t*"<<endl;
- cout<<"\t\t*\t5-Search by Project Name\t\t*"<<endl;
- cout<<"\t\t*\t6-Search by Mark Range\t\t\t*"<<endl;
- cout<<"\t\t*\t7-Display Highest & Lowest Records\t*"<<endl;
- cout<<"\t\t*\t8-Display Records of Failed Students\t*"<<endl;
- cout<<"\t\t*\t9-Delete Record\t\t\t\t*"<<endl;
- cout<<"\t\t*\t10-Modify Record\t\t\t*"<<endl;
- cout<<"\t\t";
- for(i=1;i<50;i++)
- cout<<"*";
- cout<<endl;
- cout<<"\t\t\t\tEnter your option:\n\t\t\t\t";
- cin>>a;
- switch(a)
- {
- case 1:
- addrec();
- break;
- case 2:
- header();
- disprec();
- break;
- case 3:
- sadno();
- break;
- case 4:
- sname();
- break;
- case 5:
- sproj();
- break;
- case 6:
- rangemark();
- break;
- case 7:
- topper_lower();
- break;
- case 8:
- fail();
- break;
- case 9:
- removerec();
- break;
- case 10:
- modifyrec();
- break;
- case 0:
- cout<<"\n\t\t\t\tThank You.";
- getch();
- exit(0);
- }
- cout<<"\n\n\t\t\tPress any key to continue ";
- getch();
- }while(a!=0);
- }
- char *getpass()
- {
- char pass[200],ch;
- int i=0;
- ch=getch();
- while(ch!=13)
- {
- cout<<"*";
- pass[i++]=ch;
- ch=getch();
- }
- pass[i]=NULL;
- return pass;
- }
- class login
- {
- int id;
- char name[100],pass[100];
- public:
- int registration(int);
- void show();
- void change();
- int retid()
- {
- return id;
- }
- char *retpass()
- {
- return pass;
- }
- };
- int lastid()
- {
- int x=0;
- login l1;
- fstream f1("login.dat",ios::in|ios::binary);
- if(f1!=NULL)
- {
- while(f1.read((char *)&l1,sizeof(l1)))
- {
- x=l1.retid();
- }
- }
- return x+1;
- }
- int login::registration(int x)
- {
- clrscr();
- int f=0;
- id=x;
- char p1[100],p2[100];
- cout<<"\n\n\n\n\n\t\t\tEnter Username:";
- cin>>name;
- cout<<"\n\n\n\t\t\tEnter Password:";
- strcpy(p1,getpass());
- cout<<"\n\n\n\n\t\t\tConfirm Password:";
- strcpy(p2,getpass());
- if(strcmp(p1,p2)==0)
- {
- f=1;
- strcpy(pass,p1);
- clrscr();
- cout<<"\n\n\n\n\n\n\n\t\t\tLogin ID:"<<id<<endl<<"\t\t\tUsername:"<<name<<endl;
- }
- else
- {
- clrscr();
- cout<<"\n\n\n\tInvalid Password ";
- }
- return f;
- }
- void login::show()
- {
- clrscr();
- cout<<"\n\n\t\t\tID:"<<id;
- cout<<"\n\t\t\tUserName:"<<name;
- cout<<"\n\t\t\tPassword:"<<pass<<endl;
- }
- void login::change()
- {
- clrscr();
- cout<<"\n\n\t\t\tUsername:"<<name<<"\n\t\t\tEnter New Name:";
- cin>>name;
- cout<<"\n\t\t\tPassword:"<<pass<<"\n\t\t\tEnter New Password:";
- strcpy(pass,getpass());
- }
- void addlogin()
- {
- clrscr();
- fstream f1;
- f1.open("login.dat",ios::app|ios::binary);
- login l1;
- if(l1.registration(lastid())==1)
- {
- f1.write((char *)&l1,sizeof(l1));
- }
- f1.close();
- }
- void displaylogin()
- {
- clrscr();
- fstream f1;
- int id,x=0;
- char pass[100];
- f1.open("login.dat",ios::in|ios::binary);
- login l1;
- cout<<"\n\n\n\n\t\t\tEnter ID:";
- cin>>id;
- cout<<"\n\n\n\t\t\tEnter Password:";
- strcpy(pass,getpass());
- while(f1.read((char *)&l1,sizeof(l1)))
- {
- if(l1.retid()==id && strcmp(l1.retpass(),pass)==0)
- {
- l1.show();
- cout<<"\n\n\n\n\n\n\t\t\tPress any key for Main Menu ";
- getch();
- mainmenu();
- x=1;
- }
- }
- if(x==0)
- {
- clrscr();
- cout<<"\n\n\n\n\t\t\tInvalid Id ";
- }
- f1.close();
- }
- void modifylogin()
- {
- clrscr();
- fstream f1;
- int id,x=0;
- char pass[100];
- f1.open("login.dat",ios::in|ios::out|ios::binary);
- login l1;
- cout<<"\n\n\n\n\t\t\tEnter ID:";
- cin>>id;
- cout<<"\n\n\n\t\t\tEnter Password:";
- strcpy(pass,getpass());
- while(f1.read((char *)&l1,sizeof(l1)))
- {
- if(l1.retid()==id && strcmp(l1.retpass(),pass)==0)
- {
- l1.change();
- f1.seekp(f1.tellp()-sizeof(l1));
- f1.write((char *)&l1,sizeof(l1));
- x=1;
- }
- }
- if(x==0)
- cout<<"\n\t\t\tInvalid Id ";
- f1.close();
- }
- void deletelogin()
- {
- clrscr();
- fstream f1,f2;
- login l1;
- char pass[100];
- f1.open("login.dat",ios::in|ios::binary);
- f2.open("temp.dat",ios::out|ios::binary);
- if(f1==NULL)
- cout<<"Error in Loading"<<endl;
- else
- {
- int a,x=0;
- cout<<"\n\t\t\tEnter Login ID for Deletion:";
- cin>>a;
- cout<<"\n\t\t\tEnter Password:";
- cin>>pass;
- while(f1.read((char*)&l1,sizeof(l1)))
- {
- if(l1.retid()!=a && strcmp(l1.retpass(),pass)!=0)
- {
- f2.write((char *)&l1,sizeof(l1));
- }
- else
- {
- clrscr();
- char ch;
- x=1;
- l1.show();
- cout<<"\n\n\t\t\tConfirm Delete (Y/N): ";
- cin>>ch;
- if(ch!='y'&&ch!='Y')
- {
- f2.write((char *)&l1,sizeof(l1));
- cout<<"\n\n\t\t\tRecord Not Deleted";
- }
- else
- cout<<"\n\n\t\t\tRecord Deleted";
- }
- }
- if(x==0)
- cout<<"\n\n\t\t\tID does not exist."<<endl;
- f1.close();
- f2.close();
- remove("login.dat");
- rename("temp.dat","login.dat");
- }
- f1.close();
- }
- void main()
- {
- int a;
- clrscr();
- do
- {
- clrscr();
- cout<<endl<<endl<<endl<<endl<<endl<<endl<<"\t\t";
- for(int i=1;i<50;i++)
- cout<<"*";
- cout<<endl;
- cout<<"\t\t*\t\t1-New User\t\t\t*"<<endl;
- cout<<"\t\t*\t\t2-Log In\t\t\t*"<<endl;
- cout<<"\t\t*\t\t3-Modify User\t\t\t*"<<endl;
- cout<<"\t\t*\t\t4-Delete User\t\t\t*"<<endl;
- cout<<"\t\t*\t\t0-Exit\t\t\t\t*"<<endl;
- cout<<"\t\t";
- for(i=1;i<50;i++)
- cout<<"*";
- cout<<endl;
- cout<<"\t\t\t\tEnter your option:\n\t\t\t\t";
- cin>>a;
- switch(a)
- {
- case 1:
- addlogin();
- break;
- case 2:
- displaylogin();
- break;
- case 3:
- modifylogin();
- break;
- case 4:
- deletelogin();
- break;
- case 0:
- cout<<"\n\t\t\t\tThank You.";
- getch();
- exit(0);
- }
- cout<<"\n\n\n\n\t\t\tPress any key to continue ";
- getch();
- }while(a!=0);
- getch();
- }
Add Comment
Please, Sign In to add comment