Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<string>
- using namespace std;
- string addRecord()
- {
- string info1, info2;
- cin>>info1; info2=info1; getline(cin,info1);
- info1 =info2+info1;
- return info1;
- }
- void displayRecord(string input[20][5],int j){
- int l;
- cout<<input [j][0]<<"\t\t"<<input[j][1]<<"\t";
- l = input[j][1].size();
- if(l<=15&&l>=8)
- cout<<"\t";
- else if(l<8)
- cout<<"\t\t";
- cout<<input [j][2]<<"\t";
- l = input[j][2].size();
- if(l<=15&&l>=8)
- cout<<"\t";
- else if(l<8)
- cout<<"\t\t";
- cout<<input [j][3];
- cout<<"\n";
- }
- void edit(string input[20][5], int record)
- {
- string pk;
- int z=-1,x;
- cout<<"Enter Book code: ";
- cin>>pk;
- do{
- z++;
- if(z > record)
- {
- cout<<"\nBook code not found\n";
- break;
- }
- } while(input[z][0] != pk);
- if(input[z][0] == pk)
- for(x=1;x<3;x++)
- {
- if(x==1)cout<<"\nNew Book Title: ";
- if(x==2)cout<<"New Book Author: ";
- input[z][x] = addRecord();
- }
- }
- int main(){
- int numRecord=0,i,z;
- string input[20][5], borrow;
- char ch,again;
- do{
- system("cls");
- cout<<"\t\t\t ****Simple Library System**** "<<endl;
- cout<<"\n--------------------------------------------------------------------------------";
- cout<<"\n[1] - Add Book"<<endl;
- cout<<"[2] - Display"<<endl;
- cout<<"[3] - Edit"<<endl;
- cout<<"[4] - Borrow"<<endl;
- cout<<"[5] - Delete"<<endl;
- cout<<"[6] - Quit"<<"\n\nChoice: ";
- cin>>ch;
- switch(ch){
- case '1':{
- do{
- numRecord++;
- system("cls");
- cout<<"--------------------------------------------------------------------------------\n\t\t\t\t Add Book\n--------------------------------------------------------------------------------";
- do{
- cout<<"\nBook Code: ";
- input[numRecord-1][0]=addRecord();
- z=-1;
- if(numRecord==1)
- break;
- do{
- z++;
- if(z > numRecord-3)
- break;
- }while(input[z][0] != input[numRecord-1][0]);
- if(input[z][0] == input[numRecord-1][0])
- cout<<"Book Code already exist";
- }while(input[z][0] == input[numRecord-1][0]);
- cout<<"Book Title: ";
- input[numRecord-1][1]=addRecord();
- cout<<"Author: ";
- input[numRecord-1][2]=addRecord();
- input[numRecord-1][3]="Available";
- do{
- cout<<"Enter Again? [Y][N]: ";
- cin>>again;
- }
- while (again!='y' &&
- again!='n');
- }
- while (again=='y');
- break;
- }
- case '2': {
- system("cls");
- cout<<"-----------------------------------------------";
- cout<<"\n\t\t +-+Display Book+-+";
- cout<<"\n-----------------------------------------------";
- cout<<"\nBook Code\tBook Title\t\tAuthor\t\t\tStatus"<<endl;
- for(int y=0;y<numRecord;y++)
- displayRecord(input,y);
- break;
- }
- case '3': {
- do{
- system("cls");
- cout<<"\t\t - - - - - - - Edit Book - - - - - - - -"<<endl<<endl;
- cout<<"Book Code\tBook Title\t\tAuthor\t\t\tStatus"<<endl;
- for(int y=0;y<numRecord;y++)
- {
- displayRecord(input,y);
- }
- cout<<endl;
- edit(input,numRecord);
- do{
- cout<<"\nEdit another.?(y/n): ";
- cin>>again;
- if(again!='y'&&again!='n') cout<<"\nInvalid Input\n\n";
- }while(again!='y'&&again!='n');
- }while(again=='y');
- break;
- }
- case '4': {
- do{
- system("cls");
- cout<<"\t\t - - - - - - - Borrow Book - - - - - - - -"<<endl;
- cout<<"Book Code\tBook Title\t\tAuthor\t\t\tStatus\t\t"<<endl;
- for(int y=0;y<numRecord;y++)
- displayRecord(input,y);
- z=-1;
- cout<<"\nBook Code: ";
- cin>>borrow;
- do{
- z++;
- if (z>numRecord){
- cout<<"\nBook Not Found"<<endl;
- break;
- }
- }while (input[z][0] != borrow);
- if (input[z][0] == borrow){
- if(input[z][3]!="Borrowed")
- {
- input[z][3] = "Borrowed";
- cout<<"\nBorrowing Successful! ^^"<<endl;
- }
- else
- cout<<"\nBook Already Borrowed! :("<<endl;
- }
- do{
- cout<<"Enter Again? [Y][N]: ";
- cin>>again;
- }
- while (again!='y' &&
- again!='n');
- }
- while (again=='y');
- break;
- }
- case '5': {
- system("pause");
- return 0;
- }
- default:cout<<"\nWhy are you trying to input what is not in the choice? ;)\nPlease enter again...\n"<<endl;
- }
- system("pause");
- }
- while (ch !=3);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement