这是一篇来自美国的关于编写一个程序来存储和处理数据,以管理库存,并为一家经营“经典”图书名称的书店保存商业记录的代码代写作业案例分享,您的代码必须在stdlinux上构建(编译到可执行文件,使用如下显示的命令),并在stdlinux上执行,而不会崩溃、冻结或导致分段错误。您必须使用以下命令将源代码构建到可执行文件(分级程序将使用这些命令)
LAB DESCRIPTION
A source code file with the code which is not straightforward to write is provided to you on Carmen. To get the source code file, lab2.c, provided on Carmen:
First, go to your cse3430 directory. Then, create a lab2 directory using the cd command
in Linux: $ mkdir lab2
Now, move to the lab2 directory:
$ cd lab2
After creating a lab2 directory, get the lab2.c source code file which is posted on Carmen in the Labs folder, and copy it as a lab2.c file on stdlinux. You can do this by downloading the lab2.c file from the Labs folder on Carmen after starting a firefox web browser in stdlinux, with the following command:
$ firefox https://carmen.osu.edu/#
After the web browser starts and the Carmen page is reached, enter your login information, and go to our course page in Carmen. The lab2.c source code is in the Labs folder, in the Lab2 subfolder. You should also download the lab2in file, which you can use to test your code, as described below.
After you download the lab2.c source file and the lab2in file, you should copy them from your Downloads folder to your ~/cse3430/lab2 folder as follows:
$ cd
$ cd ~/cse3430/lab2
$ cp ~/Downloads/lab2.c ./
$ cp ~/Downloads/lab2in ./
NOTE: There must be a space before ./ in the above commands ( ./ is your current directory, that is, the directory you are in when you run the command, so these commands will copy the files from your Downloads directory/folder to your cse3430/lab2 directory/folder).
CLASSIC BOOKSTORE INVENTORY SYSTEM: Mandatory file name: lab2.c (This is the required file name. Do not change it! If you submit more than once, Carmen will change the name of the file, but you will not be penalized for any change in the file name made by Carmen). I ask, however, that you avoid resubmitting; be sure to test your code THOROUGHLY before submitting, and you should not need to resubmit!
For this lab, you will write a program to store and process data in order to manage inventory and to keep business records for a bookstore which deals in “classic” book titles.
The user will enter data about the book titles to be stored in the inventory system, and will select options related to what to do with the data. You do not know the number of different book titles which will be entered by the user when you are writing the program, so your code must be able to deal with an indeterminate number of different books (up to the limits of available memory. This means that dynamic allocation must be used to allocate memory to store the Nodes in the linked list which the program creates). First, your program should prompt the user to enter data about the books in the inventory (you are given the code to do this). The data will be entered in the following format, with each item of data listed entered on a separate line:
Book title (We will assume the title may possibly contain white spaces – that is, multiple words; see the sample data posted on Carmen)
Author’s name (We will assume there will be a single author for each book, with the name possibly containing white spaces – that is, it may be a name consisting of multiple “words”; see the sample data posted on Carmen, as described below)
Book stock number (An integer from 1 – 10000)
Wholesale price in dollars (a floating point value)
Retail price in dollars (a floating point value)
Wholesale quantity purchased by bookstore (a whole number greater than or equal to zero)
Retail quantity purchased by customers (a whole number greater than or equal to zero)
Data about each book will not be separated from the data for the following book by any separation marker; that is, the first line of input for the next book will immediately follow the book which precedes it, but the data for the following book will be on the following line.
All of the book data for the initial inventory will be followed by the string “END_DATA” (without quotation marks) on the line following the last line of input for the initial inventory [The code you are given to read the input file will deal with all of this].
Please see the sample input data in the file lab2in which is available on Carmen. You should download this input data file into your Downloads directory, and then copy it to your lab2 directory (as explained above) and use it to test your program using redirection of the input, as described in class, and in the directions for lab 1.
You have been provided with a source code file, lab2.c, on Carmen, in the Labs folder,which has some very important code in it already. You need to add code as directed below.
Ultimately, it is your responsibility to make sure that the program performs the functionality described in these instructions. You have been given main, and also a function to read the input, as well as a function to print out the titles of the books in the book list after you implement an insertNode function to add books to the list. There is also a function to deallocate the memory for the nodes in the list, once the user of the program enters the number of the exit operation, as described below.
The linked list which your program uses to store data for the books should store them in order of increasing book stock number (we will assume no two books have the same stock number; that is, all book stock numbers are unique). After reading the input data about the books, and storing the structures with the book data in the dynamic linked list by calling an insertNode function, which you need to write, your program should prompt the user to select from the following options for processing of the data (You have been provided most of the code for this function also, which utilizes a separate function to prompt the user, get a user choice, and call the appropriate function; a switch-case has been used to do this):
- Print book list (you have been given this function): This function should print “Book List” on one line, and then print a list of all the book titles in the inventory, in order of increasing stock number (which is the order in which the books are stored in the linked list).
- Determine and print total revenue (from all books): This is the sum of (retail price * retail quantity) for all books in the list;
- Determine and print total wholesale cost (for all books): This is the sum of (wholesale price * wholesale quantity) for all books in the list;
- Determine and print investment in inventory: this is ((Wholesale Quantity – Retail Quantity) * Wholesale Price) for all books in the list;
- Determine and print total profit (for all books): This is (total revenue (above) – total wholesale cost) + investment in inventory (above);
- Determine and print total number of sales (total number of books sold): This is the sum of the retail quantities for all books in the list;
- Determine and print average profit per sale: This is total profit (above) divided by total number of sales (above);
- Add a new book to the inventory (insert a book into the pre-existing linked list). This function should prompt the user to enter the book data in the same format given above (but no “END_DATA” string will appear at the end of the book input).
You should use the insertNode function to implement this. (You have been provided the code for this operation.)
- Delete a book from the linked list with the inventory (This will be done with a deleteNode function, which you need to write code for). Prompt the user to enter the stock number of the book they wish to delete, and then delete the node with that stock number, if found. After the book is deleted, a message “Book stock number (stockNumber) deleted from the inventory.” If not found, print an error message (such as: “Book stock number (stockNumber) not found in the inventory.”). NOTE: You should call printf to print all the the messages mentioned above inside the code for the deleteNode function.
10.Exit the program (You have been provided the code to implement this operation; it calls a function to free all of the dynamically allocated storage for the nodes first).
The user will enter a choice of one of these ten options by entering a single number, 1 – 10, immediately followed by enter (new line). If the user enters a choice outside the range 1 to 10, the code catches that, and prints an error message, and asks for the user to try again.
You can assume that all user input will be correct. You should write code for the functions which the comments in the source code file indicate. These functions are the insertNode() function, the functions to calculate for user choices 2 to 7, and choice 9 (deleteNode); you should write and test the functions in this order, one by one (do not write the next function in this list till you have written and tested the function before it!
Be sure, for each of the functions above which is required to print output, to print a label which describes the output (the code you have been provided handles this), along with the appropriate output on the same line (except for the function to print the book list, where all the books should be printed on separate lines; the function provided to print the book list does this).
GUIDANCE
– Declare the struct type for a book at file scope (before main), as follows (you have been given this declaration, at file scope):
–
struct Data{
char title[45];
char author[45];
int stockNumber;
float wholesalePrice;
float retailPrice;
int wholesaleQuantity;
int retailQuantity;
};
typedef struct Node{
struct Data book;
struct Node *next;
} Node; /* Now, Node is a type, and you can declare Nodes in the rest of the program without using the struct keyword */
– Code for lab2.c posted on Carmen contains a function to allocate memory for a node,and then call a function to read data for one node from input, and store it in the memory allocated for the node.
– You should write, test, and debug the insertNode() function insertNode FIRST, to add a structure with a book to the inventory linked list. Use the input file lab2in provided on Carmen (download it to stdlinux by starting a firefox web browser, as explained above) to make sure this function works correctly before writing other functions.
– CRITICAL WARNING: DO NOT WRITE THE CODE FOR OTHER FUNCTIONS UNTIL THE insert FUNCTION IS WORKING AND THOROUGHLY TESTED using the lab2in file with redirection!!!
– Until you are ready to write the code for the other functions, you can write functions with empty parameters and empty blocks for the other functions in the program (these are called “stub” functions); if these functions are called in the program, they will do nothing, so this will create no problems for testing and debugging. You have been provided stub functions for the other functions in the lab2.c source file provided.
– After insertNode() is working, then, write the remaining functions (calculation functions 2-7), except for deleteNode (the basic algorithm for the remaining functions is similar to the function to print the books in the list), and test them, one by one, by running the program with redirection of the input to the file lab2in.
– Finally, write the deleteNode function, and test it using the lab2in file and debug it.
– Also, a function is needed to free the memory allocated for all of the nodes in the list before the program terminates; you have been provided code for this function.
CONSTRAINTS
– The book data must be stored in a dynamic linked list of structures, with each structure in the linked list containing the data for one book title.
-You are not permitted to declare any variables at file scope (this means you cannot declare any variables outside of functions – all variables must be declared inside of some function); you should, however, declare the Data type and Node type used to store the data for the linked list at file scope (but no variables can be declared as part of this declaration). As stated above, you have been given these declarations as part of the lab2.c source file provided; see the description of the declaration of the Data type and Node type above.
– All floating point data will be entered with two digits of precision, and should also be output with two digits of precision.
– You must allocate the storage for the linked list to store the book structures dynamically (this has been done by the part of the code provided to you in lab2.c).
– The book name and author’s name should each be stored in strings declared to be of type array of char of size 45; you have been given these declarations as part of the declaration of the type Node.
– When the user decides to exit the program, you should call free() to free the storage for the list. There is code for a function provided for such a function.
See the lab2in file on Carmen in the Labs folder with sample input; use this to test your code.
程序辅导定制C/C++/JAVA/安卓/PYTHON/留学生/PHP/APP开发/MATLAB

本网站支持 Alipay WeChatPay PayPal等支付方式
E-mail: vipdue@outlook.com 微信号:vipnxx
如果您使用手机请先保存二维码,微信识别。如果用电脑,直接掏出手机果断扫描。
