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

Write a Cpp program with the following functionality, features, and description

ID: 3888053 • Letter: W

Question

Write a Cpp program with the following functionality, features, and description

This program is going to define a preparatory class that you will be using for linked list. You are going to write this class and use it so that you will be ready to use it for the linked list class. The class is going to be the Node class.

Structure

Book title – must hold the title of a book including spaces.

Author – must hold the author’s name including spaces

Date read – must be able to contain numerical mo, day, year (digits)

Node class data:

declaration of the structure class

Pointer to class Node

Node class member functions

Default constructor

Constructor that takes book title, author, and date

Mutator function to set pointer

Accessor function to return pointer

Accessor function to return structure

compare_data function that will compare a given book title against the one in the class

process_data function that will print the data to the screen.

Specific information for class:

Define a class called Node. The Node class will hold a declaration of the structure and a pointer to a Node.

The default constructor will set the book title to your favorite book, author to the author of the book, and the date read to some default date that you chose. The pointer will be set to NULL.

There will another constructor that will accept the book title, author, and the date. The pointer will be set to NULL.

Define a mutator function that will allow the pointer to be changed.

Write an accessor function that will allow the pointer to be returned.

Write another accessor function that will return the structure.

The class will have a compare_data function that will compare the title of a book passed to the function against the book in the class. It will return true if the title is the same and false otherwise.

Write a member function called process_data that will print the data to the screen.

Requirements for main:

In the main program, declare 5 pointers for the Node class.

Create dynamic memory for 5 different books and initialize them to book titles and dates that you choose. You will now have 5 Nodes with book titles and dates and each of the pointers set to NULL.

Create a Node pointer called head. Next, you are going to create a linked list with the 5 pointers. You are going to do this by setting up the head pointer to point to the first book. Each of the rest of the books will be linked together with the last book pointer being equal to NULL. Do this by setting the pointer of the first book (Node *) equal to the pointer of the second book. Set the pointer of the second book equal to the pointer of the third book. Set the pointer of the third book to the pointer of the fourth book and the pointer of the fourth book to the pointer of the fifth book. The fifth book pointer should remain set to NULL. Do not ask the user for input. Generate all of the data in your program.

For each object that you created, test each function in the class. (You should already have used the pointer mutator.)

Using a loop starting with the head pointer, traverse the list and execute the process_data in the Node class.

There will be no user input.

Sample output:

The Great Divorce   C. S. Lewis    2/17/2016

Explanation / Answer

I have already worked on it you can just copy the code

Code

class LinkedList

{

private:

Node *_pHead;

Node *_pTail;

public:

LinkedList(void);

LinkedList(int val);

LinkedList(void);

}

#include <iostream.h>

#include <conio.h>

#include <iomanip.h>

struct book

{

char booktitle [20], author [20], dateread [20];

int price;

book *next;

};

int sum=0;

void main()

{

clrscr();

book *head=NULL;

book *initial(void);

book *purchase(book *);

void search(book *);

int choice;

while(1)

{

cout<<"Choose your Choice ";

cout<<"1)    Initial Data Entry ";

cout<<"2)    Name of Book ";

cout<<"3)    Search of Book ";

cout<<"4)    Display Books ";

cout<<"7)    Exit ";

cout<<"Enter Your Choice:-";

cin>>choice;

    switch(choice)

   {

   case 1 : head=initial();

               getch();

               break;

   case 2 : head=purchase(head);

               getch();

               break;

// case 3 : head=sale(head);//             break;case 4 : stock(head);

               getch();

               break;

   case 4 : search(head);

               getch();

               break;

   case 5 : display(head);

               getch();

            break;

   case 6 : gotoout;

   default: cout<<" Invalid Choice TRY AGAIN ";

   }

clrscr();

}

out:

}

book *initial(void)

{

clrscr();

book *newl=NULL,*start=NULL,*end=newl;

char ch;

    while(1)

   {

   cout<<" Type y or Y for yes ";

   cout<<"Are you Interested in Entering Entry:-";

   cin>>ch;

   if(ch=='y' || ch=='Y')

   {

         newl=new book;

      cout<<" Enter Author of Book:-";

      cin>>newl->author;

      cout<<"Enter Title of Book:-";

      cin>>newl->booktitle;

      cout<<"Enter Publication of Book:-";

      cin>>newl->dateread;

      cout<<"Enter Price of Book:-";

      cin>>newl->price;

        sum=sum+newl->price;

      if(start==NULL)

          start=newl;

      else

          end->next=newl;

      end=newl;

      end->next=NULL;

   }

   elsebreak;

    }

return(start);

}

{

clrscr();

int pos,count=1,choice;

library *newl,*cnt=start,*head=start;

if(start==NULL)

    cout<<" LIST IS EMPTY ";

cout<<" Choose your Choice ";

cout<<"1)    Inserting At FIRST POSITION ";

cout<<"2)    Inserting In BETWEEN ";

cout<<"3)    Inserting At LAST POSITION ";

cout<<"4)    Exit ";

cout<<"Enter your choice:-";

cin>>choice;

if(choice >=1 && choice <=3)

{

    newl=new book;

   cout<<"Enter Author Name :-";

   cin>>newl->author;

   cout<<"Enter Book Title :-";

   cin>>newl->booktitle;

   cout<<"Enter Publication :-";

   cin>>newl->dateread;

   cout<<"Enter Price of Book:-";

   cin>>newl->price;

   sum=sum+newl->price;

}

switch(choice)

{

    case 1 :

                       newl->next=head;

                          head=newl;

                          break;

   case 2 :          //for Middle position

                       read:

                       cout<<" At which position you want to insert Record:-";

                        cin>>pos;

                        while(cnt!=NULL)

                        {

                        count++;                   //cnt for counting variable of type node

                        cnt=cnt->next;

                        }

                        if(pos<1 || pos>count+1)

                     {

                        cout<<" Entered position is Invalid TRY AGAIN ";

                        goto read;

                  }

                  {                    //Extra Braces are used as case bypasses intialization of a local variableint c=1;

                        while(c<pos-1)

                        {   c++;

                            start=start->next;

                        }

                  }

                        newl->next=start->next;

                        start->next=newl;

                       break;

   case 3 :        //for Last position while(start->next!=NULL)

                            start=start->next;

                       start->next=newl;

                       newl->next=NULL;

                  break;

   case 4 :         gotoout;

   default:       cout<<" Entered Choice is Invalid Try again ";

                       break;

}

out:

return(head);

}

void stock(book *start)

{

clrscr();

int count=0;

    while(start!=NULL)

   {

        count++;

      start=start->next;

   }

cout<<" Total Number of Books in Stock is "<<count<<endl;

}

void search(book *start)

{

clrscr();

char author[20],booktitle[20];

cout<<"Enter Book title and its Author name respectively to Search in stock ";

cin>>title>>author;

    while(start!=NULL)

   {

        if(title==start->title)

{

          if(author==start->author)

         {

             cout<<" Book is In Stock ";

            cout<<"It Cost Rs"<<start->price;

            return;

         }

      }

    }

cout<<" SEARCH IS NOT IN STOCK ";

}

void display(book *start)

{

clrscr();

cout<<setw(10)<<"Book Title"<<setw(25)<<"Author of

for(int i=0;i<40;i++)

cout<<"=*";

cout<<endl;

while(start!=NULL)

{

cout<<setw(10)<<start->title<<setw(25)<<start->author<<setw(25)<<start->pub<<setw(20)<<start->price<<endl;

start=start->next;

}

}

THANK YOU

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