Library Server
kaziamir
c_cpp
a year ago
2.4 kB
5
Indexable
Never
#include<bits/stdc++.h> #include<string.h> using namespace std; /****************Coding Starts from here****************/ typedef struct book{ string title, author, genre; int ISBN, avail; struct book *next; }book; typedef struct user{ string name, contact; int id; struct user *next; }user; book *frnt = NULL, *rear = NULL; void add(int ISBN, string title, string author, string genre){ book *node = (book *)malloc(sizeof(book)); if(node!=NULL){ node->title.assign(title); node->author.assign(author); node->genre.assign(genre); node->ISBN = ISBN; node->next = NULL; book *p = frnt; while(p!=NULL){ if(p->ISBN==node->ISBN){ p->avail += 1; cout<<"Book added successfully"<<endl; return; } p = p->next; } node->avail = 1; if(frnt==NULL && rear==NULL){ rear = node; frnt = node; } else{ rear->next = node; rear = node; } cout<<"Book added successfully"<<endl; } } void remov(int ISBN){ book *temp; book *p = frnt; if(frnt->ISBN==ISBN){ temp = frnt; frnt=frnt->next; free(temp); if(frnt==NULL){ rear = NULL; } cout<<"Book Removed of ISBN: "<<ISBN<<endl; return; } while(p!=NULL){ if(p->next->ISBN == ISBN){ temp = p->next; p->next = p->next->next; free(temp); cout<<"Book Removed of ISBN: "<<ISBN<<endl; return; } p = p->next; } cout<<"Book "<<ISBN<<" Not Found"<<endl; } void print(){ book *p = frnt; while(p!=NULL){ cout<<"ISBN: "<<p->ISBN<<endl; cout<<"\tTitle: "<<p->title<<endl; cout<<"\tAuthor: "<<p->author<<endl; cout<<"\tGenre: "<<p->genre<<endl; cout<<"\tAvailable: "<<p->avail<<" Copies"<<endl; p = p->next; } } void solution(){ add(101, "English", "Amir", "Academic"); add(102, "Bangla", "Soikot", "Academic"); add(103, "Math", "Moushi", "Academic"); add(105, "Biology", "Shovon", "Academic"); add(101, "English", "Amir", "Academic"); print(); remov(106); } int main(){ //test solution(); return 0; }