diff --git a/LMSCode_vscode_updated.cpp b/LMSCode_vscode_updated.cpp new file mode 100644 index 0000000..0382eb3 --- /dev/null +++ b/LMSCode_vscode_updated.cpp @@ -0,0 +1,617 @@ +#include +#include +#include//input-output manipulator +#include +#include +#include +#include +#include +using namespace std; + +void gotoxy(int x, int y) +{ + static HANDLE h = NULL; + if(!h) + h = GetStdHandle(STD_OUTPUT_HANDLE); + COORD c = { x, y }; + SetConsoleCursorPosition(h,c); +} + +class book +{ + char bno[6];//bookno. + char bname[50];//bookname + char aname[20];//authorname + public: + void createbook() + { + cout<<"\nNEW BOOK ENTRY...\n"; + cout<<"\nENTER BOOK NO."; + cin>>bno; + cout<<"\nENTER BOOK NAME"; + gets(bname);//enables enter with space + cout<<"\nENTER AUTHOR NAME"; + gets(aname); + cout<<"\n\n\nBook Created.."; + } + void showbook() + { + cout<<"\nBook Number: "<>admno; + cout<<"Enter The Student Name "; + gets(name); + token=0; + stbno[0]='\0'; + cout<<"\n\nStudent Record Created..."; + } + void showstudent() + { + cout<<"\nAdmission Number : "<>ch; + }while(ch=='y'||ch=='Y'); + fp.close(); +} + +void writestudent() +{ + char ch; + fp.open("student.dat",ios::out|ios::app);//write and append data + do{ + system("cls"); + st.createstudent(); + fp.write((char*)&st,sizeof(student));//size of class + cout<<"\n\nDo you want to add more record...(y/n?) "; + cin>>ch; + }while(ch=='y'||ch=='Y'); + fp.close(); +} + void displayspb(char n[]) + { + cout<<"\nBOOK DETAILS\n"; + int flag=0;//book not found + fp.open("book.dat",ios::in);//read data + while(fp.read((char *)&bk,sizeof(book))) + { + if(strcmpi(bk.retbno(),n)==0)//not case sensitive + { + bk.showbook(); + flag=1; + } + } + fp.close(); + if(flag==0)//book not found + { + cout<<"\n\nBook does not exist"; + + } + getch(); +} + void displaysps(char n[]) + { + cout<<"\nSTUDENT DETAILS\n"; + int flag=0;//student not found + fp.open("student.dat", ios::in);//read data + while(fp.read((char *)&st,sizeof(student))) + { + if(strcmpi(st.retadmno(),n)==0)//not case sensitive + { + st.showstudent(); + flag=1; + } + } + fp.close(); + if(flag==0)//student not found + { + cout<<"\n\nStudent does not exist"; + + } + getch(); +} +void modifybook() +{ + char n[6]; + int found=0;//seach book of given data + system("cls"); + cout<<"\n\nMODIFY BOOK RECORD..."; + cout<<"\n\nEnter the book no. "; + cin>>n; + fp.open("book.dat",ios::in|ios::out); + while(fp.read((char*)&bk,sizeof(book)) && found==0) + { + if(strcmpi(bk.retbno(),n)==0) + { + bk.showbook(); + cout<<"\nEnter the new details book"; + bk.modifybook(); + int pos=-1*sizeof(bk); + fp.seekp(pos,ios::cur);//back from current position + fp.write((char *)&bk,sizeof(book)); + cout<<"\n\nRecord Updated"; + found=1; + } + + } + fp.close(); + if(found==0) + { + cout<<"\n\nRecord Not Found"; + + } + getch();//press key to get out +} + void modifystudent() +{ + char n[6]; + int found=0;//seach book of given data + system("cls"); + cout<<"\n\nMODIFY STUDENT RECORD..."; + cout<<"\n\nEnter the Admission no. "; + cin>>n; + fp.open("student.dat",ios::in|ios::out); + while(fp.read((char*)&st,sizeof(student)) && found==0) + { + if(strcmpi(st.retadmno(),n)==0) + { + st.showstudent(); + cout<<"\nEnter the new details of student"; + st.modifystudent(); + int pos=-1*sizeof(st); + fp.seekp(pos,ios::cur);//back from current position + fp.write((char *)&st,sizeof(student)); + cout<<"\n\nRecord Updated"; + found=1; + } + + } + fp.close(); + if(found==0) + { + cout<<"\n\nRecord Not Found"; + + } + getch();//press key to get out +} + + void deletestudent() + { + char n[6]; + int flag=0; + system("cls"); + cout<<"\n\n\n\tDELETE STUDENT..."; + cout<<"\n\nEnter the Admission no> : "; + cin>>n; + fp.open("student.dat",ios::in|ios::out); + fstream fp2; + fp2.open("temp.dat",ios::out); + fp.seekg(0,ios::beg); + while(fp.read((char*)&st,sizeof(student))) + { + if(strcmpi(st.retadmno(),n)!=0) + { + fp2.write((char*)&st,sizeof(student)); + } + else{ + flag=1;//student found + } + } + fp2.close(); + fp.close(); + remove("student.dat"); + rename("temp.dat","student.dat");//data after deletion moved to temp + if(flag==1) + { + cout<<"\n\n\tRecord Deleted.."; + } + else + { + cout<<"\n\nRecord not Found"; + } + getch(); + } + void deletebook() + { + char n[6];//book no. + int flag=0; + system("cls"); + cout<<"\n\n\n\tDELETE BOOK..."; + cout<<"\n\nEnter the Book no> : "; + cin>>n; + fp.open("book.dat",ios::in|ios::out); + fstream fp2;//New onject + fp2.open("Temp.dat",ios::out);//temp having data else than that to be deleted + fp.seekg(0,ios::beg); + while(fp.read((char*)&bk,sizeof(book))) + { + if(strcmpi(bk.retbno(),n)!=0) + { + fp2.write((char*)&st,sizeof(book)); + } + else{ + flag=1;//student found + } + } + fp2.close(); + fp.close(); + remove("book.dat"); + rename("Temp.dat","book.dat");//data after deletion moved to temp + if(flag==1) + { + cout<<"\n\n\tRecord Deleted... "; + } + else + { + cout<<"\n\nRecord not Found"; + } + getch(); + } + void displayalls() + { + system("cls"); + fp.open("student.dat",ios::in);//read mode + if(!fp) + { + cout<<"File Could Not Be Open"; + getch(); + return;//press any key and return + } + cout<<"\n\n\t\tStudent List\n\n"; + cout<<"==================================================================\n"; + cout<<"\tAdmission No."<>sn; + fp.open("student.dat",ios::in|ios::out); + fp1.open("book.dat",ios::in|ios::out); + while(fp.read((char*)&st,sizeof(student))&& found==0) + { + if(strcmpi(st.retadmno(),sn)==0)//compare admsn no. + { + found=1; + if(st.rettoken()==0)//if book not issued + { + cout<<"\n\n\tEnter The Book No."; + cin>>bn; + while(fp1.read((char*)&bk,sizeof(book))&& flag==0) + { + if(strcmpi(bk.retbno(),bn)==0)//compare book no. + { + flag=1; + st.addtoken(); + st.getstbno(bk.retbno());//pass book no. + int pos=-1*sizeof(st); + fp.seekg(pos,ios::cur); + fp.write((char*)&st,sizeof(student)); + cout<<"\n\n\tBook Issued Successfully\n\n Please Note The Book Issue Date On Backside Of Your Book And Return Book Within 15 Days, Otherwise Fine Of 15 Rs Per Day"; + + + } + } + if(flag==0) + { + cout<<"Book No. Does Not Exists"; + } + + } + + else + { + + cout<<"You Have Not Returned The Last Book"; + + } + + + + } + + } + if(found==0) + { + cout<<"Student Record Not Exists..."; + + } + getch(); + fp.close(); + fp1.close(); + } + + void bookdeposit() + { + char sn[6],bn[6]; + int found=0,flag=0,day,fine; + system("cls"); + cout<<"\n\nBOOK DEPOSIT..."; + cout<<"\n\n\tEnter Admission no. Of Student"; + cin>>sn; + fp.open("student.dat",ios::in|ios::out); + fp1.open("book.dat",ios::in|ios::out); + while(fp.read((char*)&st,sizeof(student))&& found==0) + { + if(strcmpi(st.retadmno(),sn)==0)//compare admsn no. + { + found=1; + if(st.rettoken()==1)//if book issued + { + while(fp1.read((char*)&bk,sizeof(book))&& flag==0) + { + if(strcmpi(bk.retbno(),st.retstbno())==0) + { + flag=1; + bk.showbook(); + cout<<"\n\n Book Deposited In No. Of Days"; + cin>>day; + if(day>15) + { + fine=(day-15)*1; + cout<<"\n\n Fine = "<>ch2; + switch(ch2) + { + case 1: writestudent(); + break; + case 2: displayalls(); + break; + case 3: char num[6]; + system("cls"); + cout<<"\n\n\t Please enter admission no."; + cin>>num; + displaysps(num); + break; + case 4: modifystudent(); + break; + case 5:deletestudent(); + break; + case 6:writebook(); + break; + case 7:displayallb(); + break; + case 8: + {char num[6]; + system("cls"); + cout<<"\n\n\tPlease enter book no."; + cin>>num; + displayspb(num); + break; + } + case 9:modifybook(); + break; + case 10:deletebook(); + break; + case 11: + return; + default: + cout<<"Invalid choice"; + } + adminmenu(); +} +int main() + +{ +char ch; +system("cls"); +start(); +do{ + system("cls"); + cout<<"\n\n\n\t MAIN MENU"; + cout<<"\n\n\n\t1 BOOK ISSUE"; + cout<<"\n\n\n\t2 BOOK DEPOSIT"; + cout<<"\n\n\n\t3 ADMINISTRATOR MENU"; + cout<<"\n\n\n\t4 EXIT"; + cout<<"\n\n\n\t PLEASE SELECT YOUR OPTION(1-4)"; + ch=getche(); + switch(ch) + { case '1': bookissue(); + break; + case '2': bookdeposit(); + break; + case '3': + adminmenu(); + break; + case '4': + exit(0); + break; + default: + cout<<"INVALID CHOICE"; + + } +}while(ch!=4 ); + + +}