From fa8c0ea98db897a0e09bac10d426c61cd09791fb Mon Sep 17 00:00:00 2001 From: Shreya Pawaskar <55914007+shraiyya@users.noreply.github.com> Date: Fri, 25 Oct 2019 09:48:48 +0530 Subject: [PATCH 1/2] Books_management_linkedlist.cpp --- library_linkedlist.cpp | 168 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 168 insertions(+) create mode 100644 library_linkedlist.cpp diff --git a/library_linkedlist.cpp b/library_linkedlist.cpp new file mode 100644 index 0000000..4361f2a --- /dev/null +++ b/library_linkedlist.cpp @@ -0,0 +1,168 @@ +//============================================================================ +// Name        : library.cpp +// Author      : +// Version     : +// Copyright   : Your copyright notice +// Description : Hello World in C++, Ansi-style +//============================================================================ + +#include +using namespace std; +class node { + friend class list; + string author ; + string name; + int no; + node*next; +public: + node(string na, string a, int n) { + author = a; + name = na; + no = n; + next = NULL; + } +}; +class list { +private: + node*head; +public: + list() { + head = NULL; + } + void add() { + int n = 0; + string na,a; + char choice = ' '; + do { + cout << "enter details" << endl; + cout << "enter name of the book " << endl; + cin >> na; + cout<<"enter the name of the author"<>a; + cout << "enter isbn number" << endl; + cin >> n; + node*temp; + node*ptr; + temp = new node(na, a, n); + if (head == NULL) { + head = temp; + } else { + ptr = head; + while (ptr->next != NULL) { + ptr = ptr->next; + } + ptr->next = temp; + } + cout << "do u want to add more?" << endl; + cout << "press y to continue." << endl; + cout << "press n to stop ." << endl; + cin >> choice; + } while (choice != 'n'); + } + + void display() { + node *ptr; + for (ptr = head; ptr != NULL; ptr = ptr->next) { + cout << "the name of the book is :" << ptr->name << endl; + cout << "the  author name is :" << ptr->author << endl; + cout << "the isbn no is :" << ptr->no << endl; + cout << endl; + } + } + + + + void insert(int pos) { + + string na,a; + int n; + int i = 0; + node*ptr; + node*temp; + temp = new node(na, a, n); + cout << "enter the new details to be inserted  " << endl; + cout << "enter name " << endl; + cin >> na; + cout << "enter author name " << endl; + cin >> a; + cout << "enter isbn no " << endl; + cin >> n; + temp = new node(na, a, n); + if (head == NULL) { + head = temp; + } else if (pos == 1) { + temp->next = head; + head = temp; + } else { + for (i = 0, ptr = head; i < pos - 1, ptr != NULL; + i++, ptr = ptr->next) { + temp->next = ptr->next; + ptr->next = temp; + } + } + } + void search() { + + cout << "enter the book name to be searched" << endl; +    string m; + + cin >> m; + if (head == NULL) { + cout << "the list is empty" << endl; + } else { + + node * ptr; + for (ptr = head; ptr != NULL; ptr = ptr->next) { + if (ptr->name==m) { + + cout << "the name is :" << ptr->name << endl; + cout << "the author name is :" << ptr->author<< endl; + cout << "the isbn no is :" << ptr->no<< endl; + + + } + } + } + + + } + + void sort() + { + + } +}; +int main() { + int p; + list l; + int choice; + l.add(); + do { + cout << "enter your choice "; + cout << "enter 1 for display" << endl; + cout << "enter 2 for sort according to isbn number" << endl; + cout << "enter 3 for search the book" << endl; + cout << "enter 4 for insert" << endl; + + cout << "enter 0 for exit" << endl; + cin >> choice; + switch (choice) { + case 1: + l.display(); + break; + + + case 3: + l.search(); + break; + case 4: + cout << "enter position" << endl; + cin >> p; + l.insert(p); + l.display(); + break; + + } + } while (choice != 0); +} + From 39938c6cd682fb161649a1ad2d04e224a60c3185 Mon Sep 17 00:00:00 2001 From: Shreya Pawaskar <55914007+shraiyya@users.noreply.github.com> Date: Fri, 25 Oct 2019 09:59:36 +0530 Subject: [PATCH 2/2] Update library_linkedlist.cpp --- library_linkedlist.cpp | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/library_linkedlist.cpp b/library_linkedlist.cpp index 4361f2a..f291393 100644 --- a/library_linkedlist.cpp +++ b/library_linkedlist.cpp @@ -1,10 +1,3 @@ -//============================================================================ -// Name        : library.cpp -// Author      : -// Version     : -// Copyright   : Your copyright notice -// Description : Hello World in C++, Ansi-style -//============================================================================ #include using namespace std; @@ -127,10 +120,7 @@ class list { } - void sort() - { - - } + }; int main() { int p; @@ -140,9 +130,8 @@ int main() { do { cout << "enter your choice "; cout << "enter 1 for display" << endl; - cout << "enter 2 for sort according to isbn number" << endl; - cout << "enter 3 for search the book" << endl; - cout << "enter 4 for insert" << endl; + cout << "enter 2 for search the book" << endl; + cout << "enter 3 for insert" << endl; cout << "enter 0 for exit" << endl; cin >> choice; @@ -152,10 +141,10 @@ int main() { break; - case 3: + case 2: l.search(); break; - case 4: + case 3: cout << "enter position" << endl; cin >> p; l.insert(p);