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

// Please read the given Word document for the project description with an illus

ID: 3733280 • Letter: #

Question

// Please read the given Word document for the project description with an illustrartive diagram.

// You are given a partially completed program that creates a list of books.

// Each book has the corresponding information: title, author, price and a linked list of frequently bought books.

// Please read the instructions above each required function and follow the directions carefully.

// If you modify any of the given code, return types, or parameters, you risk failing test cases.

// The following will be accepted as input in the following format: "title:author:price"

// Example Input: "ProgrammingLanguages:Chen:45"

// Valid title: String containing alphabetical letters beginning with a capital letter

// Valid author: String containing alphabetical letters beginning with a capital letter

// Valid price: A float variable

#include

#include

#include

#include

#pragma warning(disable: 4996)

// used to create a linked list of containers, each contaning a "book"

struct container {

struct book *book;

struct container *next;

} *list = NULL;

// used to hold book information and linked list of "frequently bought together (fbt)"

struct book {

char title[30];

char author[30];

float price;

struct fbt *fbts;

};

// used to create a linked list of frequently bought together (fbt)

struct fbt {

struct book *book;

struct fbt *next;

};

// forward declaration of functions that have already been implemented

void flush();

void branching(char);

void registration(char);

// the following forward declarations are for functions that require implementation

// HW07

// Total: 50 points for hw07

// return type // name and parameters // points

void add_book(char*, char*,float); // 15

struct book* search_book(char*); // 10

void remove_book(char*); // 15

void print_all_books(); // 10

// HW08

// Total: 50 points for hw08

struct container * buy_book(); // 15

struct container * setfbt(struct container *); // 25

void display_fbt(struct container*); // 10

int main()

{

char ch = 'i';

printf("Book Information ");

do

{

printf("Please enter your selection: ");

printf(" a: add a new book to the list ");

printf(" s: search for a book on the list ");

printf(" r: remove a book from the list ");

printf(" l: print the list of all books ");

printf(" b: buy a book ");

printf(" q: quit ");

ch = tolower(getchar());

flush();

branching(ch);

} while (ch != 'q');

return 0;

}

// consume leftover ' ' characters

void flush()

{

int c;

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

}

// branch to different tasks

void branching(char c)

{

switch (c)

{

case 'a':

case 's':

case 'r':

case 'l':registration(c); break;

case 'b':{

struct container * buy = buy_book();

buy = setfbt(buy);

display_fbt(buy);

break;

}

case 'q': break;

default: printf("Invalid input! ");

}

}

//

// This function will determine what info is needed and which function to send that info to.

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

// There is no implementation needed here, but you should trace the code 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 registration(char c)

{

if (c == 'a')

{

char input[100];

printf(" Please enter the book's info in the following format: ");

printf("title:author:price ");

fgets(input, sizeof(input), stdin);

// discard ' ' chars attached to input

input[strlen(input) - 1] = '';

char* title = strtok(input, ":"); // strtok used to parse string

char * author = strtok(NULL, ":");

float price = atof(strtok(NULL, ":"));

struct book* result = search_book(title);

if (result == NULL)

{

add_book(title, author, price);

printf(" Book added to list successfully ");

}

else

printf(" That book is already on the list ");

}

else if (c == 's' || c == 'r' )

{

char title[30];

printf(" Please enter the book's title: ");

fgets(title, sizeof(title), stdin);

// discard ' ' chars attached to input

title[strlen(title) - 1] = '';

struct book* result = search_book(title);

if (result == NULL)

printf(" That book is not on the list ");

else if (c == 's'){

printf(" Title: %s ", result->title);

printf("Author: %s ", result->author);

printf("Price: %.2f ", result->price);

}

else

{

remove_book(title);

printf(" Book removed from the list ");

}

}

else

{

print_all_books();

}

}

// hw08 Q3: display_fbt (10)
// This function prints the list of books for a given container.
// It should both print the details of each book and the fbt for that book.  
// This function is used to print the book list in the buy option.
void display_fbt(struct container* books)
{

}

a: dd a new book to the 113t 3: earch for a book on the 11st r: remove a book trom the 11at 1: print the 11at of all books b: buy a book a: quit Do you want to buy a book? y for YEs and n for NO:y Please enter the book's title: Do you want to buy a book? y for YES and n for NO:y Please enter the book's title: Do you want to buy a book? y for YES and n for NO:y Please enter the bok's title: Do you want to buy a book? y for YES and n for NO:n Thanks for your shopping Title: E Author: F Price: 300.00 Frequently Bought Together Book: Title: C Author: D Price: 200.00 Frequently Bought Together Book: Title: A uthor: B Price: 100.00 Title: C Author: D Price: 200.00 Frequently Bought Together Book: Title: E Author: F Price: 300.00 Frequently Bought Together Book: Title: A Author: B Price: 100.00 1tle: A Autho: B Price: 100.00 Frequently Bought Together Book: 1tle: E Author: F Price: 300.00 Frequently Bought Together Book: 1tle: C Author: D Price: 200.00

Explanation / Answer

#include<iostream.h>

#include<stdio.h>

struct books {

    char Book Title[20], author Name[20];

   int Price[5];

} a[50];

int main() {

    int i, n,a;

    cout << "Enter the Book Title:";

    cin>>n;

    cout << "Enter the book details ";

    cout << "---------------------- ";

    for (i = 0; i < n; i++) {

        cout << "Author Name " << i + 1 << " ";

       cout << "Book Name :";

        cin >> a[i].name;

        cout << "Book Author :";

        cin >> a[i].author;

        cout << "---------------------- ";

    }

    cout << "================================================ ";

    cout << " S.No | Book Name |author ";

    cout << "=====================================================";

    for (i = 0; i < n; i++) {

        cout << " " << i + 1 << " |" << a[i].name << " | " << a[i].author;

    }

    cout << " =================================================";

    return 0;

}