Question: I need help with these problems! please help #include #include #include #include Container.h #include Book.h #include Buy.h using namespace std; // forward declarations void flush();

I need help with these problems! please help

#include

#include

#include

#include "Container.h"

#include "Book.h"

#include "Buy.h"

using namespace std;

// forward declarations

void flush();

void branching(char);

void helper(char);

void add_book(string, string, float);

void change_price(Book *);

Book* search_book(string,string);

void remove_book(string,string);

void print_all(Container*);

Container* list = NULL; // global list

int main()

{

char ch = 'i';

do {

cout << "Please enter your selection ";

cout << "\ta: add a new book to the list ";

cout << "\tc: change the price of a book ";

cout << "\tb: buy a book ";

cout << "\tr: remove a book from the list ";

cout << "\tp: print all books on the list ";

cout << "\tq: quit ";

cin >> ch;

flush();

branching(ch);

} while (ch != 'q');

list = NULL;

return 0;

}

void flush()

{

int c;

do c = getchar(); while (c != ' ' && c != EOF);

}

void branching(char c)

{

switch (c) {

case 'a':

case 'b':

case 'c':

case 'r':

case 'p':

helper(c);

break;

case 'q':

break;

default:

printf(" Invalid input! ");

}

}

// The helper function is used to determine how much data is needed and which function to send that data to.

// It uses pointers and values that are returned from some functions to produce the correct ouput.

// There is no implementation needed here, but you should study this function and know how it works.

// It is always helpful to understand how the code works before implementing new features.

// Do not change anything in this function or you risk failing the automated test cases.

void helper(char c)

{

string title, author;

float price;

if (c == 'p')

print_all(list);

else

{

cout << endl << "Please enter the books's title: " << endl;

cin >> title;

cout << "Please enter the books's author: " << endl;

cin >> author;

cout << "Please enter the price of the book: " << endl;

cin >> price;

flush();

Book* book_result = search_book(title,author);

if (c == 'a') // add book

{

if (book_result == NULL)

{

add_book(title, author,price);

cout << endl << "Book was added." << endl << endl;

}

else

cout << endl << "Book is already on the list." << endl << endl;

}

else if (c == 'c')

{

if (book_result == NULL)

{

cout << endl << "Book was not found." << endl << endl;

return;

}

change_price(book_result);

}

else if (c == 'b') // buy book

{

if (book_result == NULL)

{

cout << endl << "Book was not found." << endl << endl;

return;

}

string date;

cout << "Please enter the date of the buying: " << endl;

cin >> date; flush();

book_result->buyBook(date);

cout << endl << "Date of buying is added." << endl << endl;

}

else if (c == 'r') // remove book

{

if (book_result == NULL)

{

cout << endl << "Book was not found." << endl << endl;

return;

}

remove_book(title,author);

cout << endl << "Book is removed from the list." << endl << endl;

}

}

}

// Q3: Add Book (5 points)

// This function will be used to add a new book to the head of you linked list of containers, no need for sorting.

// The search function is called before this function, therefore you can assume the book is not already on the list.

void add_book(string title, string author, float price)

{

// code here

}

// Q4: Search Book (5 points)

// This function will be used to search for a book on the list.

// You must traverse the list and return a pointer to a 'Book' with the desired title AND author.

// If the book does not exist on the list, return NULL. (See helper function for use of this function).

Book* search_book(string title,string author)

{

// code here

}

// Q5: Change price (5 points)

// This function will be used to change the price of a book.

// The function gets a pointer to the book and change the value of price using the set function inside the book class.

void change_price(Book * book)

{

// code here

}

// Q6: Remove Book (15 points)

// This function will be used to remove a book from the list.

// Traverse the list and use the parameters to remove the book.

// You must remove all the elements in the buys linked list.

void remove_book(string title, string author)

{

// code here

}

// Question 7. Print_all (10 points for this question)

// Write a recursive function to implement the print_all function.

// You will not receive any point if you use a while loop.

// Please use comments to indicate the four steps (1 point each step):

// (1) size-n problem, (2) stopping condition and return value,

// (3) size-(n-1) problem, (4) construct the solution of size-n problem

// You should print out the information of a book and also the number of times a book has been bought.

// For each time that a book has been bought, you should print out the date.

// You should use the methods inside the book.cpp file to print.

void print_all(Container* top)

{

// code here

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!