📄 http:^^www.cs.wisc.edu^~milo^cs302^program3.html
字号:
Date: Mon, 11 Nov 1996 17:13:11 GMTServer: NCSA/1.5Content-type: text/htmlLast-modified: Fri, 27 Sep 1996 07:29:26 GMTContent-length: 8189<HTML><HEAD><TITLE>Program 3 - CS 302 Fall 1996 - Section 4</TITLE></HEAD><BODY><H1 ALIGN=CENTER> <!WA0><!WA0><!WA0><!WA0><!WA0><!WA0><A HREF="http://www.cs.wisc.edu/~cs302">CS 302</A> Fall 1996 - <!WA1><!WA1><!WA1><!WA1><!WA1><!WA1><A HREF="http://www.cs.wisc.edu/~milo/cs302.html">Section 4</A></H1> <H2 ALIGN=CENTER>Algebraic Language Programming in C++</H2><H4 ALIGN=CENTER>Instructor: <!WA2><!WA2><!WA2><!WA2><!WA2><!WA2><A HREF="http://www.cs.wisc.edu/~milo">Milo M. Martin</A> (milo@cs.wisc.edu)</H4><hr><br><H1 ALIGN=CENTER>Program 3</H1><H3 ALIGN=CENTER>Due Friday, October 4, 1996</H3> <hr><br><b>Objective</B>: Give the student experience working with and writingfunctions.<p><H3>Program Description</H3>Due to the great cash register program that you wrote for therestaurant, you have earned quite a reputation and your skills are inhigh demand. A large hardware distributor, We 'R Nails, hascontracted you to write a program to replace an old cash register. <p>This program will be an even greater challenge than the restaurantbecause of a number of added complications. First, the price acustomer pays for each nail decreases as the quantity orderedincreases. This is described in detail below. Second, the warehousehas a finite number of nails in stock, and your program must not allowthe operator to place an order for more of one type of nail than is instock. <p>The cost of ordering some number of one type of nail can be calculatedfrom the quantity ordered and the base price of each nail. The morenails that a customer orders, the less the customer pays per nail.The discount schedule is as follows:<pre> First 1000: regular price Next 1000: 10% discount Next 1000: 15% discount After that: 25% discount</pre>For example, the price of 1300 items at 10 cents a piece would be(1000*10) + (300*9) cents = $127.00, <em>not</em> (1300 * 9) cents.Note that if the user orders 800 of a particular item at one point,and later orders 500 more of the same item, she should be given thediscount as if she ordered all 1300 at once. <p>We 'R Nails sells four types of nails. Below is a chart of theitem number, description, base cost per nail, and quantity on hand inthe warehouse.<pre> Item # Item Description Cost per Nail Number in Warehouse==================================================================== 315 2.0" Nails $0.025 15000 426 3.0" Nails $0.030 20000 537 4.0" Nails $0.035 25000 648 9.0" Nails $0.050 30000</pre>Customers can only order by the box (there are 100 nails to the box,regardless of size). <p>Similar to the last program, you need prompt the user for the order,keep track of how many of each item have been ordered, loop until theuser asks for the bill, display the final bill. However, this programrequires that you prompt the user for the item number and quantityordered. You may design the menu and bill formats yourself, but, asin your previous assignment, all dollar amounts must be formatted to 2decimal places. <p><b> Constants variables should be used where appropriate and all inputshould be checked to make sure it is valid. If the input is notvalid, tell the user, and re-prompt the user for input</B>. (Thesestatements apply to all programs from now on.)<H3>Code Provided</H3>Since the object of this assignment is to give you practice usingfunctions, I have provided the basic framework and <tt>main</tt>function for you to build the other functions upon. It is your job tocomplete the functions which "fill-in" the program and perform thedesired operations. <b>You must use the following code as your<tt>main</tt> function with no modifications to the code:</b><pre>// Your header comments go here#include <iostream.h>const int TRUE = 1;const int FALSE = 0;// Your function prototypes go hereint main() { int choice; // item number int quantity; // quantity ordered int num_ord1 = 0, num_ord2 = 0; // cumulative number of each item ordered int num_ord3 = 0, num_ord4 = 0; do { // Prompt the user and get the input print_menu(num_ord1, num_ord2, num_ord3, num_ord4); choice = get_choice(); quantity = get_quantity(); // Process the order place_order(choice, quantity, num_ord1, num_ord2, num_ord3, num_ord4); } while (keep_going() == TRUE); // Ask the user if they want to continue // Display the bill summarizing the items ordered. print_bill(num_ord1, num_ord2, num_ord3, num_ord4);}</pre><p><h3>Functions To Write</h3><p>The following is a list of functions that you <b>must</b> write forthe assignment. Some of these procedures will only requirecall-by-value parameters, others will need to use call-by-referenceparameters. It is up to you to figure out how many and what types theparameters are.<ul> <p><p><li> <b>print_menu</b> - This function should print the menu and thecurrent subtotal (not including tax).<p><li> <b>calculate_subtotal</b> - This function should compute the subtotal(not including tax) of the items ordered so far.<p><li> <b>calculate_price</b> - This function (which will be called bycalculate_subtotal) should take two arguments: quantity ordered of aparticular item, and the price of the item. It then computes the costusing the rules in the above program description.<p><li> <b>get_choice</b> - This function should prompt the user for anitem number. You must ensure that the return value is a legitimateitem number. If the user enters an invalid choice, an error messageshould be printed, and the user should be reprompted for a new number.<p><li> <b>get_quantity</b> - This function should prompt the user for thequantity of the order. You must ensure that the return value is alegitimate quantity (remember, if you have the user enter the number ofnails desired, the number must be divisible by 100 to be valid, sincenails come in 100 item packages). If the user enters an invalidchoice, an error message should be printed, and the user should bereprompted for a new number.<p><li> <b>place_order</b> - This function will attempt to place theorder, adjusting the appropriate <tt>num_ord</tt><em>x</em>. If thetotal quantity of the item requested is greater than the stock on-hand,as much as possible of the order should be filled, and an informativeout of stock message should be displayed. This message should displaywhich item was out of stock and the quantity to which the order wasreduced.<p> If the ordering of an item causes the available stock to dropbelow 10,000 items, a descriptive "low on item" message should beprinted, along with the appropriate item number.<p><li> <b>keep_going</b> - This function should ask the user whetherthey would like to continue ordering items (or, it could ask the userif they want to print the bill.) Either way, it should return TRUE ifthe loop is to be executed again, and FALSE otherwise. (TRUE andFALSE are integer constants that are included in the code for<tt>main</tt>.)<p><li> <b>print_bill</b> - This function should print the number ofeach item ordered (only the items which the customer ordered more thanzero of), the subtotal, and the final total (adding in 5% tax) in away that is similar to the last program.</ul><p> <H3>What To Turn In</H3>Once you have your program working, you should print sample runs ofthe program. Your output file should demonstrate ordering quantitiesof the items such that various discount levels are calculated, ordersthat exceed the available items in stock, orders that cause a stocklow message to be displayed, and an example where two requests for thesame item are handled properly. (as one large request.)As always, submit print-outs of both your source code and your sampleprogram runs, and an submit an electronic copy of your source code andexecutable as described previously. <p><hr><address>Created by <!WA3><!WA3><!WA3><!WA3><!WA3><!WA3><A HREF="http://www.cs.wisc.edu/~burnett">Dave Burnett</A>, <!WA4><!WA4><!WA4><!WA4><!WA4><!WA4><A HREF="http://www.cs.wisc.edu/~milo">Milo Martin</A>, and <!WA5><!WA5><!WA5><!WA5><!WA5><!WA5><A HREF="http://www.cs.wisc.edu/~dyao">Dan Yao</A>.</Address></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -