Question

In: Computer Science

Create initializer/constructor functions for book. Declare and implement functions like insert book(insert at End, InsertAtFirst), retrieve...

Create initializer/constructor functions for book. Declare and implement functions like insert book(insert at End, InsertAtFirst), retrieve book, update book information book using ISBN number in Library. Declare another function named Search to find a specific book from catalogue.

#include<iostream.h>
#include<conio.h>

struct book{
   char name[50];
   int ISBN;
   char authorname[50];
   char publishername[50];
   int issuedate;
   int issuemonth;
   int issueyear;
   int retdate;
   int retmonth;
   int retyear;
   struct book *next=NULL;
}

void insert(struct book *head){
    if *head.next==NULL{
       struct book node;
       cout<<"enter the name of book";
 
       gets(node.name)
       cout<<"enter the author name of book";
       gets(node.authorname)
       cout<<"enter the publisher name of book";
       gets(node.publishername)
       cout<<"enter isbn no.";
       cin>>node.ISBN;
       cout<<"enter the issue date month and year";
       cin>>node.issuedate;
       cin>>node.issuemonth;
       cin>>node.issueyear;
       cout<<"enter the return date month and year";
       cin>>node.retdate;
       cin>>node.retmonth;
       cin>>node.retyear;
       *head.next=&node;
    }
   else{
       insert(*head.next);
}
}
void main(){

//the pile of the books will be stored in a linked list where ISBN no. can be a searching key 
struct book library;//first book in library

insert(library);//inserting a book in library
insert(library);//inserting a book in library
getch();
}

Solutions

Expert Solution

Create initializer/constructor functions for book. Declare and implement functions like insert book(insert at End, InsertAtFirst),
retrieve book, update book information book using ISBN number in Library. Declare another function named Search to find a specific book from catalogue.

#include<iostream.h>
#include<conio.h>

struct book
{
    book()
    {
        int i=0;
    }
    char name[50];
    int ISBN;
    char authorname[50];
    char publishername[50];
    int issuedate;
    int issuemonth;
    int issueyear;
    int retdate;
    int retmonth;
    int retyear;
    struct book *next=NULL;
};
struct book *Library;
int count;
void InsertAtFirst (struct book B)
{
    struct book *node;
    if(count==0)
    {
        Library=(struct book *)(malloc(sizeof(struct book)));
        node=Library;
    }
    else
    {
        node=(struct book *)(malloc(sizeof(book)));
    }
    cout<<"enter the name of book";
    gets(node->name)
    cout<<"enter the author name of book";
    gets(node->authorname)
    cout<<"enter the publisher name of book";
    gets(node->publishername)
    cout<<"enter isbn no.";
    cin>>node->ISBN;
    cout<<"enter the issue date month and year";
    cin>>node->issuedate;
    cin>>node->issuemonth;
    cin>>node->issueyear;
    cout<<"enter the return date month and year";
    cin>>node->retdate;
    cin>>node->retmonth;
    cin>>node->retyear;
    if(count==0)
    {
        count+=1;
        Library->next=NULL;
    }
    else
    {
       node->next=Library;
       count+=1;
       Library=node;
    }
}
void InsertAtEnd(struct book B)
{
  
    struct book *node,*ptr;
    ptr=Library;
    while(ptr->next!=NULL)
    {
        ptr=ptr->next;
    }
    node=(struct book *)malloc(sizeof(struct book));
    cout<<"enter the name of book";
    gets(node->name);
    cout<<"enter the author name of book";
    gets(node->authorname);
    cout<<"enter the publisher name of book";
    gets(node->publishername);
    cout<<"enter isbn no.";
    cin>>node->ISBN;
    cout<<"enter the issue date month and year";
    cin>>node->issuedate;
    cin>>node->issuemonth;
    cin>>node->issueyear;
    cout<<"enter the return date month and year";
    cin>>node->retdate;
    cin>>node->retmonth;
    cin>>node->retyear;
    node->next=NULL;
    ptr->next=node;
    count+=1;
}
void searchbook(int num)
{
    struct book *ptr;
    ptr=Library;
    while(ptr!=NULL)
    {
        if(ptr->ISBN==num)
        {
            cout<<"Name "<<ptr-name<<endl;
            cout<<"Author name "<<ptr->authorname<<endl;
            cout<<"Issue date "<<ptr->issuedate<<"/"<<ptr->issuemonth<<"/"<<ptr->issueyear<<endl;
            cout<<"Rent date "<<ptr->retdate<<"/"<<ptr->retmonth<<"/"<<ptr->retyear<<endl;
            return ;  
        }
        ptr=ptr->next;
    }
    cout<<"Not found in Library"<<endl;
}
void retrievebook(int num)
{
    struct book *ptr;
    ptr=Library;
    while(ptr!=NULL)
    {
        if(ptr->ISBN==num)
        {
            cout<<"Name "<<ptr-name<<endl;
            cout<<"Author name "<<ptr->authorname<<endl;
            cout<<"Issue date "<<ptr->issuedate<<"/"<<ptr->issuemonth<<"/"<<ptr->issueyear<<endl;
            cout<<"Rent date "<<ptr->retdate<<"/"<<ptr->retmonth<<"/"<<ptr->retyear<<endl;
            return ;  
        }
        ptr=ptr->next;
    }
}
void updatebook(int num)
{
    struct book *ptr;
    ptr=Library;
    while(ptr!=NULL)
    {
        if(ptr->ISBN==num)
        {
            cout<<"Enter number to update info "<<endl;
            cout<<"Enter 1 for update book name '\n' 2 for update ISBN '\n' 3 for update author name '\n' 4 for updating issue date '\n' 5 for ret date"<<endl;
            switch(a)
            {
                case 1:
                        char str[50];
                        cout<<"Enter new book name"<<endl;
                        cin>>str;
                        ptr->name=str;
                case 2:
                        cout<<"enter new ISBN number"<<endl;
                        int isbn;
                        cin>>isbn;
                        ptr->ISBN=isbn;
                case 3:
                        char s[50];
                        cout<<"Enter new Author name"<<endl;
                        cin>>s;
                        ptr->authorname=s;
                case 4:
                        cout<<"enter new issue date"<<endl;
                        int a,b,c;
                        cin>>a;
                        cin>>b;
                        cin>>c;
                        ptr->issuedate=a;
                        ptr->issuemonth=b;
                        ptr->issueyear=c;
                case 5:
                        cout<<"enter new return date"<<endl;
                        int a,b,c;
                        cin>>a;
                        cin>>b;
                        cin>>c;
                        ptr->retdate=a;
                        ptr->retmonth=b;
                        ptr->retyear=c;
            }
            return;
        }
        ptr=ptr->next;
    }
}
void main()
{
    count=0;
    //the pile of the books will be stored in a linked list where ISBN no. can be a searching key
    struct book library;    //first book in library
    InsertAtFirst(library);   //inserting a book in library
    InsertAtEnd(library);        //inserting a book in library
    getch();
}


Related Solutions

C language Write a program in C to implement Queue and its operation (like create, insert,...
C language Write a program in C to implement Queue and its operation (like create, insert, delete, search) using array data structure.
Create “New Class…” named Book to store the details of a book Declare 3 fields for...
Create “New Class…” named Book to store the details of a book Declare 3 fields for the details of the book: field named author of type String field named title of type String field named callNumber of type String Add overloaded constructors with the following headers and make sure each constructor has only 1 statement in the body that makes an internal method call to setBookDetails: public Book(String author, String title, String callNumber) public Book(String author, String title) HINT: Initialize...
Implement one of the hashing procedures that we have discussed, and the following related functions: INSERT...
Implement one of the hashing procedures that we have discussed, and the following related functions: INSERT (item) DELETE (item) FIND (item) Make sure that your program correctly handles collisions and full hash table!
JAVA Programming ECLIPSE IDE 1. Create an abstract class called Book. The class should declare the...
JAVA Programming ECLIPSE IDE 1. Create an abstract class called Book. The class should declare the following variables: an instance variable that describes the title - String an instance variable that describes the ISBN - String an instance variable that describes the publisher - String an instance variable that describes the price - double an instance variable that describes the year – integer Provide a toString() method that returns the information stored in the above variables. Create the getter and...
JAVA Programming ECLIPSE IDE 1. Create an abstract class called Book. The class should declare the...
JAVA Programming ECLIPSE IDE 1. Create an abstract class called Book. The class should declare the following variables: an instance variable that describes the title - String an instance variable that describes the ISBN - String an instance variable that describes the publisher - String an instance variable that describes the price - double an instance variable that describes the year – integer Provide a toString() method that returns the information stored in the above variables. Create the getter and...
create "bitty.c" that uses bitwise operators and return statements to implement the functions in "bitty.h". "bitty.c"...
create "bitty.c" that uses bitwise operators and return statements to implement the functions in "bitty.h". "bitty.c" that can only implement "bitty.h" _____________________________________________________________ bitty.h: // Returns 1 if v is an even number, otherwise returns 0 unsigned char isEven(unsigned char v); // Returns 1 if v is zero, otherwise returns 0 unsigned char isZero(unsigned char v); // Returns 1 if a and b have the same value, otherwise 0 unsigned char equals(unsigned int a, unsigned int b); // Returns a if...
Create a windows form application in C# that looks and functions like a basic calculator. It...
Create a windows form application in C# that looks and functions like a basic calculator. It must do the following: Add, subtract, multiply, and divide. Account for division by zero. Show at least two decimal places. Retain the last number on the window so that, when the user opens the calculator the next time, the number that was in the window at the last close appears. Have a memory, so that users can store values and recall them. Operate with...
In C++ language implement an end of the world simulation. Create 3 global variables earthquake =...
In C++ language implement an end of the world simulation. Create 3 global variables earthquake = 30%, hurricane = 35%, volcano = 35% Implement a class named World. Class World inherited Class CRandom In class World create three methods Earthquakes, Hurricanes and Volcanoes. These methods return death toll in numbers and percentage up to their global percentage. This percentage is calculated using CRandom.
Im trying to create a book list. I started off like this but idk how to...
Im trying to create a book list. I started off like this but idk how to continue? public static int [] BookList (String title, String author, int price, int copies, String category) { } I don't know what to do next in order to list a set of (lets say 5 ) books and how to call it in the main (public static void main(String[] args))method
Please C++ create a program that will do one of two functions using a menu, like...
Please C++ create a program that will do one of two functions using a menu, like so: 1. Do Catalan numbers 2. Do Fibonacci numbers (recursive) 0. Quit Enter selection: 1 Enter Catalan number to calculate: 3 Catalan number at 3 is 5 1. Do Catalan numbers 2. Do Fibonacci numbers (recursive) 0. Quit Enter selection: 2 Enter Fibonacci number to calculate: 6 Fibonacci number 6 is 8 Create a function of catalan that will take a parameter and return...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT