联系方式

  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-23:00
  • 微信:codinghelp2

您当前位置:首页 >> CS作业CS作业

日期:2018-06-07 08:39


Summary

This assignment will give you practise w/user and program interfaces, and unit testing.

Create a cash register program called assn4 .

You will write a cash register,

assn4 will initialise the register, accept purchases, make change, and provide a report on the total of goods

sold at the end of the day, the total of cash in the register, and the number of each type of bill.

Provide a bash script of test cases, of transactions, checking expected output.

The Assignment

Write a command-line utility called assn4 which will process operations init, purchase, change, and

report. Your program will store the drawer's state in a local file, format of your choosing.

The cash register only works with $1's, $5's, $10's, $20's.

Change should always be made with the largest available denominations, and your program should handle

the problems with running out of various denomination.

The major consideration with this assignment is to develop the unit tests to prove your software is robust

and correct. Especially around the edge cases where the till is out of specific denominations.

Make sure the change command returns the correct total. Don't return three tens in exchange for a twenty.

Return Codes

0 SUCCESS (drawer was successfully changed)

1 Bad arguments (format/number)

2 Amounts don't jibe. E.g., left- and right-hand side of change aren't equal, or amount tendered is less

than purchase price

3 Drawer has insufficient money or denominations to make proper change

4 Unable to read/write data file

Note: For any non-zero (unsuccessful) return value, the state of the register will remain unchanged.

Descriptions of Subcommands

init amt = ones [fives [tens [twenties]]]

Initialise drawer, using counts of bills provided

If a drawer already exists, this will overwrite it. (Essentially, start a new shift.)

Output: None

purchase price = amount_tendered

price

Integer

amount_tendered

Number and type of bills given to register

ones [fives [tens [twenties]]], where amounts are integers (counts)

Output will be a single line, if successful:

change returned , where change returned has the same format: ones fives tens

twenties

change tendered = bills_requested

tendered and bills_requested

ones [fives [tens [twenties]]], where amounts are integers (counts)

Output will be a single line, if successful:

change returned , where change returned has the same format: ones fives tens

twenties

report

Output a single line, the total of the drawer, and a breakdown of the bills

sales : total = ones fives tens twenties

sales is the total of sales on the register, total is the total amount of money in the drawer,

followed by the breakdown.

All ammounts are USD.

NOTE: Do not decorate the output, with units, labels, etc. Follow the specs.

If no argument is supplied, print a usage message and exit.

Program defensively. We be looking to slip you something you won't expect.

Example Output

Here is an example of using this. The comments are there for your benefit, and *not* part of the output.

Note: This is a *nix file, with newlines. Use IE or Notepad at your own peril.

$ # Initialize the till with a two five dollar bills and five ones.

$ assn4 init 15 = 10 1 0 0

$ # Verify input for init (that amounts match):

$ # Purchase $38 with two $20s:

$ assn4 purchase 38 = 0 0 0 2

2 0 0 0

$ # Change a five for 5 ones

$ assn4 change 0 1 = 5

5 0 0 0

$ # Change a 20 for a ten, five and five ones:

$ assn4 change 0 0 0 1 = 5 1 1 0

$ # Report the contents of the till

$ assn4 report

38 : 28 = 3 2 0 2

Hints (maybe)

When modifying your data file, write to a tmp file, then move it to the data file. That is, write a

separate file, then replace the old file with the new one in one move.

To parse up the variable # of arguments, shift off the commands, split over the '=', then parse each

side up, using the same algorithm.

If you are using Java, you can't return a status to the caller. Decorate your output with OK and FAIL

1, FAIL 2, etc, have your wrapper script parse up the output, remove the decorations, so it can

return a success code.

Update: You can use System.exit( int i ) to return a status to the caller. Thank you, Justin.

Target Language

You can do this in any language you choose, including Bash or AWK. The language must be currently

hosted on the tux machines.

If you, e.g., do this in Java, then you'll need to supply a shell script called assn4 that invokes your

program, the JRE, whatever, w/the arguments.

Required Unit Tests

Provide a file containing a script of calls initialising and testing a register. For each test, provide a single

line describing the expected output, inside a comment.

Submission

Since you can do this in a number of languages, submit a makefile . We will call make build before

testing your scripts. I've provided templates:

sample Python makefile

sample Java makefile

sample C++ makefile

See my notes on makefiles for help.

Submit the following files via the submit_cliBlackboard Learn utility.

makefile - your makefile, with the folowing targets:

build — compile your code, whatever, get it ready to run

clean — cleans up all intermediate and resulting files

view — display any source code that you wrote, in a pager

all of your source files. Binaries and other compiled code (.class, .o, executables) will be deleted

before I start, so, must be built from source.

test.script - Your test script

README optional - anything you want to say to me before I grade.

Please note: You will use the filenames as listed here, and submit them all to the proper assignment. If

this is not clear, then see me in class. If I get programs submitted to the wrong directories, I will be irate,

which may, in some subconscious way, affect your grades. Adversely.


版权所有:留学生编程辅导网 2020 All Rights Reserved 联系方式:QQ:99515681 微信:codinghelp 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。 站长地图

python代写
微信客服:codinghelp