Sale!

Solved CCPS393 – Assignment #3

$30.00 $21.00

Original Work ?

Download Details:

  • Name: assignment_3-lizsfa.zip
  • Type: zip
  • Size: 723.03 KB

Category: Tags: , You will Instantly receive a download link upon Payment||Click Original Work Button for Custom work

Description

5/5 - (1 vote)

Write a C program called “pop” which simulates the operation of a soft drink vending machine. Your program should meet the following requirements. The user running the program will simulate both service and customer actions. You are operating in a country whose currency is in centimes.  Service/Maintenance Requirements o set the selling price (range 30 centimes to 105) from a command line argument (centimes only) provide a specific message (as in sample below) for the following error cases and return to the operating system: o command line argument is missing o prices out of range price not multiple of 5 o with a valid selling price, put machine in-service for continual sales (See Customer Requirements) as a maintenance action (hidden from menu), allow service person to shutdown (exit) the program altogether at the coin prompt by pressing E or e; refund any pending amount  Customer Requirements o First assume that there is only one flavour of pop, and that the machine won’t run out of pop (no need to track inventory or total sales) o display a welcome message stating the pop price, and what coins and commands are accepted o commands are accepted o prompt the user to insert coins (via keyboard entry) accept a nickel [N or n] (5 centime piece), dime [D or d] (10 centime piece) or pente [P or p] (20 centime piece); reject all other input except maintenance actions, then re-prompt for coin o after each coin, display how much the user has inserted in total and how much more the user needs to insert dispense product on collecting sufficient money (only one flavour) provide change for overpayment using only dimes and nickels (assume machine won’t run out) allow user to abort the transaction by pressing coin return (R or r). Refund using only dimes and nickels using the fewest number of coins. re-display selling price before new sale o continually prompt for additional sales — do not exit the program Example sequence (not exhaustive testing). (NB: The dollar sign ($) represents the command prompt): $ ./pop Please specify the selling price as a command line argument. Usage: ./a.out [price] $ ./pop 225 Price must be from 30 to 115 centimes inclusive. $ ./pop 35 Welcome to my C Pop Machine! Pop is 35 centimes. Please insert any combination of nickels [N or n], dimes [D or d] or Pentes [P or p]. You can also press R or r for coin return. Enter coin (NDPR): n Nickel detected. You have inserted a total of 5 centimes. Please insert 30 more centimes. Enter coin (NDPR): N Nickel detected. You have inserted a total of 10 centimes. Please insert 25 more centimes. Enter coin (NDPR): d Dime detected. You have inserted a total of 20 centimes. Please insert 15 more centimes. Enter coin (NDPR): p Pente detected. You have inserted a total of 40 centimes. Pop is dispensed. Thank you for your business! Please come again. Change given: 5 centimes as 0 dime(s) and 1 nickel(s). Pop is 35 centimes. Please insert any combination of nickels [N or n], dimes [D or d] or Pentes [P or p]. You can also press R or r for coin return. Enter coin (NDPR): p Pente detected. You have inserted a total of 20 centimes. Please insert 15 more centimes. Enter coin (NDPR): j Unknown coin rejected. You have inserted a total of 20 centimes. Please insert 15 more centimes. Enter coin (NDPR): R Change given: 20 centimes as 2 dime(s) and 0 nickel(s). Pop is 35 centimes. Please insert any combination of nickels [N or n], dimes [D or d] or Pentes [P or p]. You can also press R or r for coin return. Enter coin (NDPR): p Pente detected. You have inserted a total of 20 centimes. Please insert 15 more centimes. Enter coin (NDPR): k Change given: 20 centimes as 2 dime(s) and 0 nickel(s). Shutting down. Goodbye. $ Implementation Requirements All constants (any value which should not change during program execution) must be specified with a #define or const qualifier. Also, comments must match program behaviour. Never have hard-coded constants embedded within your code! Constants must not be stored in a program variable because a variable can be changed (unless using a const qualifier to make variable read-only) If program requirements change (e.g. price limit), and you would have to change a value in more than one place anywhere in your program, this is a red flag that you should be using a #define with the symbol in each instance (e.g. PI not 3.142). There must be no duplication of code. Consider the (similarity of) computation for returning change and providing a refund. If another denomination ever needed to be added to the change denominations, it should not require code changes in more than one place. There are penalties for each infraction above. See grading scheme/rubric for details. Notes on typical problems: Q: I am having problems with scanf/getchar; I have to hit enter twice, or it skips input. A1: If you use scanf, you need to put a space character inside the quotes before the placeholder, like this: A2: If you use getchar (or scanf(“%c”)), remember that this reads only a single character, but your program does not see it until the user presses adding the newline character. You have to add another getchar (or scanf(“%c”)) after each getchar to “swallow” the newline like this: letter=getchar(); /* OR scanf(“%c”); no space before %c */ while (getchar() != ‘\n’); /* eat newline */ Grading Scheme Guiding Principles This assignment will emphasize future software maintenance costs on par with functionality, hence the penalties for embedded hard-coded constants and code duplication (listed below). For functionality, imagine being the owner of pop machines to be deployed at locations across the country: If the code had a few minor mistakes which would not be fixed, how much would you still pay for the (mostly) working program? #include int main (void) { char command; do { printf(“Enter a command (X to exit): “); scanf(” %c”, &command); /* note SPACE before %c */ printf(“You entered: %c\n”, command); } while (command != ‘X’); printf(“Goodbye\n”); return (0); } Functionality & Design (8):  control flow (How accurately does it simulate the vending machine described?)  coin deposition (recognition, rejection)  accounting & arithmetic  compute & display amount tendered  compute & displace balance owing  perform sale  provide correct change/refund (only dimes & nickels;  fewest coins possible)  service actions (price limits, denomination restrictions, shut-down exit) Documentation & Style (2):  adheres to documentation guidelines (See Content -> Assignments -> Documentation Guidelines on course website)  self-describing variable names ($result, $operand, etc. NOT $a, $b, $c, etc.)  must pass Functionality section (>4/8) in order to count Penalties  multiple sales not supported (e.g. program exits to OS after sale) (-4)  incorrect change even sometimes (-4)  deficiencies in pricing, displaying of price or amount tendered, sale (-2 to -4)  embedded hard-coded constants (-1 each instance, max -3)  using program variables for values which should not vary (-1 each, max -3)  code duplication (-2)  fail to clean up temp files: -1 You will be given a provisional grade at time of Customer Presentation. As a option, you may make corrections and present again once and only once. If you choose to make this second presentation, your assignment mark will be an average of the first and second presentations. (Example: First presentation 4/10; Second presentation (with corrections) 8/10; therefore your assignment mark would be 6/10.)