300580 – Programming Fundamentals ANOTHER SAMPLE ASSIGNMENT Post of Sale Terminal PART-I: Point of Sale Terminal (12 marks) You are required to design a program post.cpp (point of sale terminal) that will be used to calculate the total cost for a list of purchased items against a list of product prices. Each purchased item will be presented by its productId, the price per item, and the corresponding quantity. The program is expected to be interactive and the user can enter everything line by line and generate such as an invoice at the end. We note that such an application usage can be alternatively illustrated by piping all the data to the program. Suppose all the program control commands and the data for the products and purchased items are stored in a plain text file datafile.txt in the form similar to the following sample /rawprices P010001 QX-35 DVD-player5 P010002 P010003 24.99 19.99 58.95 8.85 35.00 /items P010001 DVD-player5 P010002 2 1 20 /invoice /quit where in a typical data line (blank lines are ignored), the first column represents the product ID which will be alphanumeric without white spaces, the second column represents the product price in Australian dollars when inputing product prices, and will represent the quantity of the corresponding purchased item when inputing purchased items. Your program post.exe compiled from post.cpp will then be able to generate an invoice via post.exe < datafile.txt > invoice.txt whose output invoice.txt could look like PHANTOM COMPANY INVOICE PRODUCT ID P010001 DVD-player5 QUANTITY 2 1 PRICE ($) 24.99 58.95 COST ($) 49.98 58.95 P010002 ... 20 8.85 177.00 TOTAL COST = $xxxxx.xx When the post program is executed, it will process commands and data records entered by the user. If a word read into the program starts with the character "/", possibly when the programming is attempting to read in a product ID, then the word is deemed a program command. This program should support at least the following commands o o o o o o o o /rawprices: this indicates that the data records to follow, if any, will be for the product pricing in the form of productId price /items: this indicates that the data records to follow, if any, will be for the purchased items in the form of productId quantity /invoice: this generates the invoice on the purchased items already read into the program /quit: this terminates the program and any other words that start with the character '/' will be considered an invalid command. For the convenience and uniformity of the program design, we assume that the total number of different products will not exceed 2000, and the total number of purchased items for each invoice will not exceed 1000. The program should be designed in such a way that piping can also be used to properly generate an invoice output as in the example at the beginning of this document. Any explicit use of file inside the C++ program for this part will not be considered a proper or complete solution in this particular assessment. We note that if you are using prompts for interactive data input, you need to make sure that the prompts are sent to standard error device using cerr (instead of cout), i.e. using cerr in place of cout. This way, the prompts will not be piped into the output file, say, statement.txt. For the solution of this part, the students are required to provide o o o o o o o the defining diagram (IPO chart) - 2 marks the structure chart (hierarchy chart) - 2 marks solution algorithm in pseudocode (don't use the C++ constructs: no break, no return statements for instance) - 2 marks complete program in C++ (including naming, style etc) - 3 marks proposed testing cases with expected results for checking - 1 mark desk checking a typical case - 1 mark general design quality, error reporting, feel and robustness - 1 mark NOTE: For this part, students may assume that the data records are line based, as described in Part-II below, if they so wish. For the pseudocode part, students may assume that all data that are fed to the program will be in correct format. For the C++ program, however, some kind of additional error reporting is required. PART-II: Extended Post of Sale Terminal (3 marks) This part is merely an extension of the program described in Part I. The functionality of this extended C++ program, xPost.cpp, should support the following additional commands o o o o o Data records and commands to the program are always line based. More precisely, each command and every record will be in the form of exactly 1 textual line, in that any extra bits outside the data fields will be ignored. For instance, if the user enters the following 3 lines when reading purchased items P010001 P010002 1 2 whatever the "whatever" bits there will be ignored because a purchased item record just needs the first 2 fields, the productId P010001 and the quantity 2, so the rest of the same line is ignored. The next 2 lines actually contain 2 bad item records because each single line contains an incomplete record and is thus considered an invalid record. The xPost program should skip such bad records with a warning message. o o /newprices: this does the same as /rawprices but is smarter in that after obtaining a product pricing record from the user it first check if a pricing record for the product ID already exists or not. If it already exists, the new pricing record replaces the existing one; otherwise it simply gets stored. /read inputfile: this reads into the program all the lines from the file named inputfile (the inputfile can be any file name in the form of a single word, i.e. no white spaces are allowed in the file name) as if they were directly entered by the user. For this part, only the complete C++ program needs to be submitted by the students. The program will be assessed not only for the correct functionality, but also for the good design and proper module decomposition. It also takes into consideration of the program robustness at handling unexpected situations. If this part is only partially completed for certain relevant individual modules (functions), then the driver program (the main( ) function) should be designed to illustrate these modules properly. Note on Submission o o o o o o o o All C++ programs must be compilable under Dev-C++ ver 4.9.9.2, or more precisely, under g++ 3.4.2 (mingw-special). For top marks, good programming style and program design will also be considered. This assignment must be submitted electronically via WebCT before the due date. No email submissions will be accepted. Submitted files may be zipped together as a single zip file, if a student wishes to do so. However, no other file compression or file archiving formats will be accepted for the submission. The electronic submission should contain the paper work in plain text or in Microsoft Word format, and the C++ source code (the .cpp file(s)) as well as other relevant files if any. Please do not include the compiled executables as the markers will generate them for you independently anyway. Each submission must be accompanied by a declaration of the ownership of the submitted work as described in the unit outline. Please note that an examiner or lecturer/tutor has the right not to mark this assignment if a pertinent declaration is not present in your submission. Late submissions will attract a daily incremented late penalty of 20% per day. Please note that if your C++ program does not compile, you automatically lose 50% of the marks in the C++ coding part. Electronic submission on the due date after 5pm before 12 midnight will still be accepted without penalty. However, any submission failure in that period due to either the student faults or the fault or malfunction of the School's or UWS' servers will not be accepted as the legitimate reasons for a late submission. Beware that School's servers often need to be shut down for maintenance from late Fridays.
© Copyright 2024