Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#include #include void addBook(); void RemoveBook(); void searchforBook(); void uploadDatafile(); void updateDatafile(); int operation(); int main() { int i; printf(welcome to my book store management

#include #include

void addBook(); void RemoveBook(); void searchforBook(); void uploadDatafile(); void updateDatafile(); int operation();

int main() { int i;

printf("welcome to my book store management system "); uploadDatafile(); i= operation(); switch(i) { case 1: addBook(); operation();

case 2: RemoveBook(); operation();

case 3: searchforBook(); operation();

case 4:

updateDatafile(); break;

}

return 0; }

void addBook() { printf("book information has been added "); } void RemoveBook() { printf("book information has been removed "); } void searchforBook() { printf("book has been searched for "); } void uploadDatafile()

{ printf("uploading data files "); printf("data files uploaded "); } void updateDatafile() { printf("updating data files "); printf("data files updated "); } int operation(){ int operation; printf("please select an operation : "); printf("1-Add a book "); printf("2-Remove a book "); printf("3-Search for a book "); printf("4-Exit system "); scanf("%d",&operation);

return operation; }

Change the previous code (in C language) according to the following data (It is preferred to be using code blocks) :

In this phase, you first need to define:

1-constant called MAXSIZE ( max number of books stored) equal to 100.

2- global variable called size =0 ( current number of books stored )

The main function should define three arrays:

int bins[MAXSIZE] ;

double prices[MAXSIZE];

int publishYear[MAXSIZE];

you now need to implement the major parts of the functions you created in phase one as follows:

void displayMainMenu(); // displays the main menu shown above

This function will remain similar to that in phase one with one minor addition which is the option:

4- Print Book List which calls the function printBooksInformation()

void uploadDataFile ( int bins[], double prices[],int publishYear[]);

This function will receive the arrays containing the bin (id) numbers and the prices as parameters and the publish year of the book. The function will open a file called books.txt for reading and will read all the book bin numbers, prices and publish year and store them in the arrays. The global variable size should be set to the number of books read from the file and stored in the array.

void addBook( int bins[], double prices[],int publishYear[]);

This function will receive the arrays containing the bin numbers, the prices, and the publish year.

The function will check to see if the list is not full. If list is not full ( size

  1. if the bin number is already in the list ( the book with that bin exists) it will display an error message (book already exists).
  2. If the bin number does not exist, the function will add the books bin and price and the publish year to the end ( at index size ) of the bins and prices and publishYear arrays. The global variable size should be incremented (size++).

void removeBook(int bins[], double prices[], int publishYear[]);

This function will receive the arrays containing the bin numbers, the prices, and the publish year as parameters. The function will check if the list is not empty. If it is not empty (size > 0) then it will search for the bin number to be removed and if not found will display an error message. If the bin number exists, the function will remove it by deleting the bin number, price and publish year from bins, prices and pulishYear arrays and size will be decremented by 1.

void searchForBook(int bins [], double prices[], int publishYear[]);

This function will receive the arrays containing the bin numbers, the prices and the publish year as parameters. The function will check if the list is not empty. If it is not empty (size > 0) then it will ask the user to enter a bin number and will search for that bin number. If the bin number is not found it will display an error message.

If the bin number is found then it will be displayed along with the price in a suitable format on the screen.

void updateDataFile(int bins[], double prices[], int publishYear[]);

This function will receive the arrays containing the bin numbers, the prices, and the publishYear, as parameters. The function will open the file called books.txt for writing and will write to that file the bin number and price of each book in the array.

void printBooksInformation (int bins[], double prices[], int publishYear[]); //

NEW FUNCTION

This function will receive the arrays containing the bin numbers , the prices and the publish year as parameters. This function will print the information (bins and prices) currently stored in the arrays.

SAMPLE RUN:

Make sure your program works very similar to the following sample run:

Assuming that at the beginning of the run file books.txt has the following information stored:

1234

72.45

2002

2345

25.20

1990

image text in transcribed

image text in transcribed

image text in transcribed

Welcome to My BookStore Management System: Uploading data file Data File uploaded Please Select an Operation (1-4): 1- Add a Book: 2- Remove a Book: 3- Search for a Book: 4- Print Book List: 5- Exit System: 4 bin# = 1234 price = 72.45 bin# = 2345 price = 25.20 Please Select an Operation (1-4): 1- Add a Book: 2- Remove a Book: 3- Search for a Book: 4- Print Book List: 5- Exit System: 1 Enter bin number for book 1500 Enter price of book 100.0 Book with bin 1500 has been added Please Select an Operation (1-4): 1- Add a Book: 2- Remove a Book: 3- Search for a Book: 4- Print Book List: 5- Exit System: 4 bin# = 1234 price = 72.45 bin# = 1500 price = 100.00 bin# = 2345 price = 25.20 Please Select an Operation (1-4): 1- Add a Book: 2- Remove a Book: 3- Search for a Book: 4- Print Book List: 5- Exit System: 2 Enter bin number for book to remove 1700 Book with bin 1700 does not exist Please Select an Operation (1-4): 11- Add a Book: 2- Remove a Book: 3- Search for a Book: 4- Print Book List: 5- Exit System: 2 Enter bin number for book to remove 1234 Book with bin 1234 has been removed Please Select an Operation (1-4): 11- Add a Book: 2- Remove a Book: 3- Search for a Book: 4- Print Book List: 5- Exit System: 2 Enter bin number for book to remove 2345 Book with bin 2345 has been removed Please Select an Operation (1-4): 11- Add a Book: 2- Remove a Book: 3- Search for a Book: 4- Print Book List: 5- Exit System: i Enter bin number for book 1111 Enter price of book 50.9 Book with bin 1111 has been added Please Select an Operation (1-4): 1- Add a Book: 2- Remove a Book: 3- Search for a Book: 1- Print Book List: 5- Exit System: 3 Enter bin number for book to search for 11500 bin# = 1500 price = 100.00 Please Select an Operation (1-4): 1- Add a Book: 2- Remove a Book: 3- Search for a Book: 4- Print Book List: 5- Exit System: 4 bint - 1111 price - 60.90 bint = 1500 price = 100.00 Please Select an Operation (1-4): 1- Add a Book: 2- Remove a Book: 3- Search for a Book: 4- Print Book List: 5- Exit System: 1 Enter bin number for book 1444 Enter price of book 150.0 Book with bin 1444 has been added Please Select an Operation (1-4): 1- Add a Book: 2- Remove a Book: 3- Search for a Book: 4- Print Book List: 5- Exit System: 1 bint = 1111 price = 60.90 bint = 1444 price = 150.00 bin# = 1500 price = 100.00 Please Select an Operation (1-4): 1- Add a Book: 2- Remove a Book: 3- Search for a Book: 4- Print Book List: 5- Exit System 5 Updating data file Data File updated Thank you for using My BookStore Management System. GoodBye

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Analytics Systems Engineering Cybersecurity Project Management

Authors: Christopher Greco

1st Edition

168392648X, 978-1683926481

More Books

Students also viewed these Databases questions

Question

5. List the forces that shape a groups decisions

Answered: 1 week ago

Question

4. Identify how culture affects appropriate leadership behavior

Answered: 1 week ago