Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Need code in C++. For this assignment we will begin working on the \"Library Inv

ID: 3751312 • Letter: N

Question

Need code in C++.

For this assignment we will begin working on the "Library Inventory System." It is a piece of software that keeps tracks of books in a library's inventory. Including the ability to check-in/check-out books as well as add and remove books from the system. We will be building on this system throughout the semester.

Your software needs to do the following:

Load the inventory from and save the inventory to a file.

Keep track of the author and title of each book, as well as an ID number for each book.

Be able to check in and out books in the inventory based on the book's ID number.

Be able to add and remove books to/from the inventory based on the book's ID number.

You will have some freedom in how you implement the code, but it must meet those requirements

Quitting should save the inventory to the same file it was loaded from.

Bonus 50XP: cin can't deal with spaces very easily, so it is best to separate words with underscores for the title and author. Learn how to use getline and use that instead!

Bonus 140XP: Keep the array sorted by ID number. Create a binary search function and use that to find books!

Explanation / Answer


Source Code:-
-------------
#include<iostream>
#include<iomanip>
#include<string.h>
#include<stdlib.h>
#include<fstream>
using namespace std;
struct Inventary
{
char Book_Title[100];
char AuthorName[100];
char PublishDate[100];
double Bookprice;
struct Inventary *next;
};//Structure Maintaining list of Books
struct Inventary *first=NULL,*last=NULL,*swapping ,*temp1=NULL,*head;
class Inventary_record
{
public:
void ReadFile()
{
ifstream myfile;
myfile.open("InventaryBook.txt");//read Inventary of Books from the file.
   for(int i=1;i<=3;i++)
   {
   head=(struct Inventary*)malloc(sizeof(struct Inventary));
   myfile>>head->Book_Title;
   myfile>>head->AuthorName;
   myfile>>head->PublishDate;
   myfile>>head->Bookprice;
head->next=swapping;
   swapping=head;
}
myfile.close();
reverse(&head);
}
public:
void Print_data()
{
struct Inventary *temp;
   temp=head;
   if(temp!=NULL)
   {
   cout<<" BookTitle AuthorName PublishDate BookPrice"<<endl;
   cout<<"---------------------------------------------------"<<endl;
   while(temp!=NULL)
   {
   cout<<temp->Book_Title<<" "<<temp->AuthorName<<" "<<temp->PublishDate<<" "<<temp->Bookprice<<endl;
   temp=temp->next;
   }
   }
   else
   {
   cout<<"The list is Empty: "<<endl;
   }
}
public:
void reverse(struct Inventary** head)
{
   struct Inventary* prev = NULL;
   struct Inventary* current = *head;
   struct Inventary* next = NULL;
   while (current != NULL)
   {
   next=current->next;  
   current->next = prev;
   prev = current;
   current = next;
}
   *head = prev;
}
public:
void BuyBook(struct Inventary **head, int position)
{
if (*head == NULL)
   return;
struct Inventary* temp = *head;
   if (position == 0)
   {
   *head = temp->next;
   free(temp);
   return;
   }
   for(int i=0; temp!=NULL && i<position-1; i++)
   temp = temp->next;
   if(temp == NULL || temp->next == NULL)
   return;
   last = temp->next->next;
   free(temp->next);
   temp->next = last;
   cout<<" The Book Buyed Successfully"<<endl;
}
public:
int search(char Title[])
{
int index=0;
struct Inventary *temp=head;
while(temp!=NULL)
{
if(!(strcmp(Title,temp->Book_Title)))
{
cout<<" Book Found:"<<endl;
   cout<<temp->Book_Title<<" "<<temp->AuthorName<<" "<<temp->PublishDate<<" "<<temp->Bookprice<<endl;
return index;
}
temp=temp->next;
index++;   
}
return -1;
}
public:
void AddNewBook(char Title[],char Date[],char Author[],double Price)
{
head=(struct Inventary*)malloc(sizeof(struct Inventary));
strcpy(head->Book_Title,Title);
strcpy(head->AuthorName,Author);
strcpy(head->PublishDate,Date);
head->Bookprice=Price;
head->next=swapping;
swapping=head;
reverse(&head);
cout<<" New Book Added Successfully"<<endl;
}
};
int main()
{
Inventary_record obj;
obj.ReadFile();
int option;
char Title[100],Author[100],PublishDate[100];
double Price;
int retval;
cout<<" -------------------------------"<<endl;
cout<<" ***The Inventary Records are ***"<<endl;
cout<<" -------------------------------"<<endl;
obj.Print_data();
while(true)
{
cout<<" **** MENU ****"<<endl;
cout<<" 1: Add a book to inventory ."<<endl;
cout<<" 2: Find a book from inventory "<<endl;
cout<<" 3: Sell a book "<<endl;
cout<<" 4: Display the inventory list"<<endl;
cout<<" 5: Genre summary "<<endl;
cout<<" 6: Show this Menu "<<endl;
cout<<" 7: eXit the program "<<endl;
cout<<" Please select any Option: " <<endl;
cin>>option;
switch(option)
{
case 1:
cout<<" Please Enter New Book title:"<<endl;
cin>>Title;
cout<<" Please Enter Book AuthorName:"<<endl;
cin>>Author;
cout<<" Publish Date:"<<endl;
cin>>PublishDate;
cout<<" Book Price:"<<endl;
cin>>Price;
obj.AddNewBook(Title,PublishDate,Author,Price);
break;
case 2:
cout<<" Please Enter Book Title"<<endl;
cin>>Title;
retval=obj.search(Title);
if(retval==-1)
cout<<" Sorry Item Details are Not Found"<<endl;
break;
case 3:
cout<<" Please Enter Name"<<endl;
cin>>Title;
retval=obj.search(Title);
if(retval==-1)
cout<<" Sorry Item Details are Not Found"<<endl;
else
obj.BuyBook(&head,retval);
break;
case 4:
obj.Print_data();
break;
case 7:
cout<<" End"<<endl;
exit(0);
default:
cout<<" Invalid Option"<<endl;
}
}
}

Sample Output:-
===============
-------------------------------
***The Inventary Records are ***
-------------------------------
BookTitle AuthorName PublishDate BookPrice
---------------------------------------------------
Cprogramming BalaguruSwamy 12/12/2000 550
JavaProgram Viswanath 01/03/2004 1000
PHPProgramm Bhatt 03/03/2005 2000
**** MENU ****
1: Add a book to inventory .
2: Find a book from inventory
3: Sell a book
4: Display the inventory list
5: Genre summary
6: Show this Menu
7: eXit the program
Please select any Option:
4
BookTitle AuthorName PublishDate BookPrice
---------------------------------------------------
Cprogramming BalaguruSwamy 12/12/2000 550
JavaProgram Viswanath 01/03/2004 1000
PHPProgramm Bhatt 03/03/2005 2000
**** MENU ****
1: Add a book to inventory .
2: Find a book from inventory
3: Sell a book
4: Display the inventory list
5: Genre summary
6: Show this Menu
7: eXit the program
Please select any Option:
2
Please Enter Book Title
JavaProgram
Book Found:
JavaProgram Viswanath 01/03/2004 1000
**** MENU ****
1: Add a book to inventory .
2: Find a book from inventory
3: Sell a book
4: Display the inventory list
5: Genre summary
6: Show this Menu
7: eXit the program
Please select any Option:
1
Please Enter New Book title:
Python
Please Enter Book AuthorName:
venkanna
Publish Date:
27/06/2018
Book Price:
2500
New Book Added Successfully
**** MENU ****
1: Add a book to inventory .
2: Find a book from inventory
3: Sell a book
4: Display the inventory list
5: Genre summary
6: Show this Menu
7: eXit the program
Please select any Option:
4
BookTitle AuthorName PublishDate BookPrice
---------------------------------------------------
PHPProgramm Bhatt 03/03/2005 2000
Python venkanna 27/06/2018 2500
**** MENU ****
1: Add a book to inventory .
2: Find a book from inventory
3: Sell a book
4: Display the inventory list
5: Genre summary
6: Show this Menu
7: eXit the program
Please select any Option:
3
Please Enter Name
Python
Book Found:
Python venkanna 27/06/2018 2500
The Book Buyed Successfully
**** MENU ****
1: Add a book to inventory .
2: Find a book from inventory
3: Sell a book
4: Display the inventory list
5: Genre summary
6: Show this Menu
7: eXit the program
Please select any Option:
4
BookTitle AuthorName PublishDate BookPrice
---------------------------------------------------
PHPProgramm Bhatt 03/03/2005 2000
**** MENU ****
1: Add a book to inventory .
2: Find a book from inventory
3: Sell a book
4: Display the inventory list
5: Genre summary
6: Show this Menu
7: eXit the program
Please select any Option:
7
End
--------------------------------
Process exited after 75.97 seconds with return value 0
Press any key to continue . . .

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote