联系方式

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

您当前位置:首页 >> C/C++编程C/C++编程

日期:2019-11-26 10:48

ENGG1110 — Problem Solving by Programming

2019–2020 Term 1

Project Specification — A Vending Machine Simulator

1. Introduction

Vending machines are automated machines that provide different products to consumers after payment

is accepted. For simplicity, we will be focusing on vending machines that take coins (available in Hong

Kong) and provide beverages. A functional vending machine should also allow service personnel to

collect revenue and refill inventory.

In this project, your task is to use C language to write a vending machine simulator that mimics its real

counterpart.

2. Functionalities

Similar to a real vending machine, the simulator should provide the following functions.

For normal consumers:

(a) Display product names and prices

(b) Indicate if a product is out-of-stock

(c) Take inserted coins

(d) Indicate if inserted coin is sufficient for a product

(e) Dispense product

(f) Return inserted coins and change

For service personnel:

(g) Allow withdrawal of all inserted coins

(h) Allow a product to be refilled

(i) Allow a different product to be displayed

4. Detailed Program Flow

When the program starts, it should print the following front of the vending machine. Then a Main

Menu with available options should be shown.

Whenever an invalid choice is entered for any menu, the program should report and keep looping. For

example (input is underlined):

*---------------------------*

| Vending Machine |

*---------------------------*

| A B C D E |

| $10 $ 6 $ 5 $ 8 $ 7 |

| [ ] [ ] [ ] [ ] [ ] |

*---------------------------*

| [$ 0] |

| |

| [===] |

*---------------------------*

What would you like to do?

1. Read product information

2. Insert coin

3. Press product button

4. Press return button

9. Open service menu (code required)

0. Quit

Your choice:

What would you like to do?

1. Read product information

2. Insert coin

3. Press product button

4. Press return button

9. Open service menu (code required)

0. Quit

Your choice: 8

Invalid choice!

What would you like to do?

1. Read product information

2. Insert coin

3. Press product button

4. Press return button

9. Open service menu (code required)

0. Quit

Your choice:

(v1.1)

(1) Read product information

If option 1 is chosen, the product names and the corresponding price will be displayed. Then the Main

Menu is displayed again.

What would you like to do?

1. Read product information

2. Insert coin

3. Press product button

4. Press return button

9. Service menu (code required)

0. Quit

Your choice: 1

(1) The displayed products are:

A. Juice ($10)

B. Cola ($6)

C. Tea ($5)

D. Water ($8)

E. Coffee ($7)

What would you like to do?

1. Read product information

2. Insert coin

3. Press product button

4. Press return button

9. Service menu (code required)

0. Quit

Your choice:

(v1.1)

(2) Insert coin

If option 2 is chosen, a sub-menu with available coin options should be shown. After a coin is inserted,

the front of vending machine with correct value of deposited coins should be shown (maximum: $99),

then the sub-menu is shown again.

(Assume the machine has $0 deposited at the beginning.)

(2) Which coin would you like to insert?

1. $1

2. $2

3. $5

4. $10

0. Go back

Your choice: 2

You have inserted $2.

*---------------------------*

| Vending Machine |

*---------------------------*

| A B C D E |

| $10 $ 6 $ 5 $ 8 $ 7 |

| [ ] [ ] [ ] [ ] [ ] |

*---------------------------*

| [$ 2] |

| |

| [===] |

*---------------------------*

(2) Which coin would you like to insert?

1. $1

2. $2

3. $5

4. $10

0. Go back

Your choice:

(v1.1)

If the deposited money is sufficient to purchase a product, indicate it by “turning on the light” using a

capital “O”.

(Continuing from previous step.)

(2) Which coin would you like to insert?

1. $1

2. $2

3. $5

4. $10

0. Go back

Your choice: 3

You have inserted $5.

*---------------------------*

| Vending Machine |

*---------------------------*

| A B C D E |

| $10 $ 6 $ 5 $ 8 $ 7 |

| [ ] [O] [O] [ ] [O] |

*---------------------------*

| [$ 7] |

| |

| [===] |

*---------------------------*

(2) Which coin would you like to insert?

1. $1

2. $2

3. $5

4. $10

0. Go back

Your choice:

(v1.1)

Selecting option 0 (Go back) will show the vending machine, and then return to the Main Menu.

(Continuing from previous step.)

(2) Which coin would you like to insert?

1. $1

2. $2

3. $5

4. $10

0. Go back

Your choice: 0

Going back!

*---------------------------*

| Vending Machine |

*---------------------------*

| A B C D E |

| $10 $ 6 $ 5 $ 8 $ 7 |

| [ ] [O] [O] [ ] [O] |

*---------------------------*

| [$ 7] |

| |

| [===] |

*---------------------------*

What would you like to do?

1. Read product information

2. Insert coin

3. Press product button

4. Press return button

9. Open service menu (code required)

0. Quit

Your choice:

(v1.1)

(3) Press product button

If option 3 is chosen, a sub-menu with available product options should be shown. If the deposited

money is sufficient to purchase the product chosen, the product will be dispensed. The front of vending

machine with correct product dispensed, button lights and deposited value should be shown, then the

sub-menu is shown again.

(Assume that the machine has $7 deposited, and product B, C and E are affordable and available. And

there is only one product B left.)

Note that product B has just been sold out. There is an “X” on its button now. Also note that the

remaining deposited amount will not be returned automatically. The product dispensed is assumed to

be taken when available, so that future display will not show this dispensed product again.

(3) Which product button would you like to press?

1. A

2. B

3. C

4. D

5. E

0. Go back

Your choice: 2

You have pressed button B.

*---------------------------*

| Vending Machine |

*---------------------------*

| A B C D E |

| $10 $ 6 $ 5 $ 8 $ 7 |

| [ ] [X] [ ] [ ] [ ] |

*---------------------------*

| [$ 1] |

| |

| [=B=] |

*---------------------------*

(3) Which product button would you like press?

1. A

2. B

3. C

4. D

5. E

0. Go back

Your choice:

(v1.1)

If a button for an out-of-stock product or an unaffordable product is pressed, nothing will happen.

(Continuing from previous step.)

Selecting option 0 (Go back) will show the vending machine, and then return to the Main Menu (same

as before; not shown).

(3) Which product button would you like to press?

1. A

2. B

3. C

4. D

5. E

0. Go back

Your choice: 1

You have pressed button A.

*---------------------------*

| Vending Machine |

*---------------------------*

| A B C D E |

| $10 $ 6 $ 5 $ 8 $ 7 |

| [ ] [X] [ ] [ ] [ ] |

*---------------------------*

| [$ 1] |

| |

| [===] |

*---------------------------*

(3) Which product button would you like press?

1. A

2. B

3. C

4. D

5. E

0. Go back

Your choice:

(v1.1)

(4) Press return button

If option 4 is chosen, all the deposited money will be returned. The front of vending machine with

correct information should be shown, then the Main Menu is shown again.

(Continuing from previous step.)

(4) Return button is pressed.

$1 has been returned.

*---------------------------*

| Vending Machine |

*---------------------------*

| A B C D E |

| $10 $ 6 $ 5 $ 8 $ 7 |

| [ ] [X] [ ] [ ] [ ] |

*---------------------------*

| [$ 0] |

| |

| [===] |

*---------------------------*

What would you like to do?

1. Read product information

2. Insert coin

3. Press product button

4. Press return button

9. Open service menu (code required)

0. Quit

Your choice:

(v1.1)

(9) Service Menu

If option 9 is chosen, the user is required to enter an access code (default: 1110). Incorrect code will

cause the simulator to return to the Main Menu after showing an error message.

Correct access code will allow the Service Menu to be shown.

(9) Opening service menu. Access code is required.

Enter access code: 1234

Incorrect code!

*---------------------------*

| Vending Machine |

*---------------------------*

| A B C D E |

| $10 $ 6 $ 5 $ 8 $ 7 |

| [ ] [X] [ ] [ ] [ ] |

*---------------------------*

| [$ 0] |

| |

| [===] |

*---------------------------*

What would you like to do?

1. Read product information

2. Insert coin

3. Press product button

4. Press return button

9. Open service menu (code required)

0. Quit

Your choice:

(9) Opening service menu. Access code is required.

Enter access code: 1110

Correct code!

(9) What would you like to do?

1. Inspect machine status

2. Withdraw all money

3. Refill product

4. Change product

0. Go back

Your choice:

(v1.1)

(9-1) Inspect machine status

If option 1 is chosen in the Service Menu, the information about the revenue (money comes from

sales), inserted coins (money inserted but not used) and the products will be displayed. Then the

Service Menu is shown again.

Selecting option 0 (Go back) will show the vending machine, and then return to the Main Menu (same

as before; not shown).

(9) What would you like to do?

1. Inspect machine status

2. Withdraw all money

3. Refill product

4. Change product

0. Go back

Your choice: 1

(9-1) Machine status

Amount of revenue: $6

Amount of inserted coins: $0

Product information:

A. Juice ($10) (5 left)

B. Cola ($6) (sold out)

C. Tea ($5) (2 left)

D. Water ($8) (1 left)

E. Coffee ($7) (9 left)

(9) What would you like to do?

1. Inspect machine status

2. Withdraw all money

3. Refill product

4. Change product

0. Go back

Your choice:

(v1.1)

(9-2) Withdraw all money

If option 2 is chosen in the Service Menu, all money in the machine (including coins that are inserted

but not used) will be withdrawn. Then the Service Menu is shown again.

Selecting option 0 (Go back) will show the vending machine, and then return to the Main Menu (same

as before; not shown).

(Continuing from previous step.)

(9) What would you like to do?

1. Inspect machine status

2. Withdraw all money

3. Refill product

4. Change product

0. Go back

Your choice: 2

(9-2) All money is being withdrawn.

$6 is withdrawn.

(9) What would you like to do?

1. Inspect machine status

2. Withdraw all money

3. Refill product

4. Change product

0. Go back

Your choice: 2

(9-2) All Money is being withdrawn.

$0 is withdrawn.

(9) What would you like to do?

1. Inspect machine status

2. Withdraw all money

3. Refill product

4. Change product

0. Go back

Your choice:

(v1.1)

(9-3) Refill product

If option 3 is chosen in the Service Menu, a sub-menu will be shown for the user to select the product

to refill to the full quantity (fixed at 10 items). Then the Service Menu will be shown again.

Selecting option 0 (Go back) will show the vending machine, and then return to the Main Menu (same

as before; not shown).

(9) What would you like to do?

1. Inspect machine status

2. Withdraw all money

3. Refill product

4. Change product

0. Go back

Your choice: 3

(9-3) Which product would you like to refill?

1. A

2. B

3. C

4. D

5. E

0. Go back

Your choice: 2

You have refilled product B to full.

(9) What would you like to do?

1. Inspect machine status

2. Withdraw all money

3. Refill product

4. Change product

0. Go back

Your choice:

(v1.1)

(9-4) Change product

If option 4 is chosen in the Service Menu, a sub-menu will be shown for the user to select the product

to change.

Selecting option 0 (Go back) will show the vending machine, and then return to the Main Menu (same

as before; not shown).

(9-4-1) Changing product

After the product has been selected, the user is prompted to enter a new product name (maximum 20

characters with no space) and new product price ($1–$99 with one dollar increments). The quantity

will be filled to full. Then the Service Menu is shown again.

(9) What would you like to do?

1. Inspect machine status

2. Withdraw all money

3. Refill product

4. Change product

0. Go back

Your choice: 3

(9-4) Which product would you like to change?

1. A

2. B

3. C

4. D

5. E

0. Go back

Your choice: 5

You are changing product E.

(9-4-1) Changing product

Enter new product name: Milk

Enter new product price: 4

The new product E has been filled to full.

(9) What would you like to do?

1. Inspect machine status

2. Withdraw all money

3. Refill product

4. Change product

0. Go back

Your choice:

(v1.1)

5. Quit

If option 0 is chosen in the top menu, the program will terminate. No message is given.

*---------------------------*

| Vending Machine |

*---------------------------*

| A B C D E |

| $10 $ 6 $ 5 $ 8 $ 7 |

| [ ] [ ] [ ] [ ] [ ] |

*---------------------------*

| [$ 0] |

| |

| [===] |

*---------------------------*

What would you like to do?

1. Read product information

2. Insert coin

3. Press product button

4. Press return button

9. Open service menu (code required)

0. Quit

Your choice: 0

>

(v1.1)

6. Academic Honesty and Declaration Statement

Attention is drawn to University policy and regulations on honesty in academic work, and to the

disciplinary guidelines and procedures applicable to breaches of such policy and regulations. Details

may be found at https://www.cuhk.edu.hk/policy/academichonesty/.

Please put the following declaration statement as the comment in the beginning of your source code

and fill in your information.

/**

* ENGG1110 Problem Solving by Programming

*

* Course Project

*

* I declare that the project here submitted is original

* except for source material explicitly acknowledged,

* and that the same or closely related material has not been

* previously submitted for another course.

* I also acknowledge that I am aware of University policy and

* regulations on honesty in academic work, and of the disciplinary

* guidelines and procedures applicable to breaches of such

* policy and regulations, as contained in the website.

*

* University Guideline on Academic Honesty:

* https://www.cuhk.edu.hk/policy/academichonesty/

*

* Student Name : <your name>

* Student ID : <your student ID>

* Class/Section : <your class/section>

* Date : <date>

*/

7. Testing Platform

Your code will be tested on Repl.it platform. Modular testing will be provided to let you confirm the

correctness of certain parts of your program.

8. Code and Report Submission

Your code will be submitted on both Repl.it and Blackboard. You are also required to submit a flow

chart describing the flow of your program.

9. Schedule

Submission (code and flowchart) by 23:59, Sunday, December 8, 2019 on Blackboard

(v1.1)

10. Assumptions and Initial Conditions

You can safely assume the following conditions during program execution.

(1) All menu inputs from user are integers.

(2) All product names have maximum 20 characters and no spaces in between.

(3) All product prices are between $1 and $99.

(4) Maximum amount of inserted coins is $99. Behavior is not defined if more than $99 are

inserted.

(5) Access code for service menu (option 9) will be entered as integer and will be treated as

integer. So, both entered codes 1110 and 001110 will grant access.

(6) When changing product (action 9-4-1), newly entered product name and price will obey the

above assumptions (2) and (3).

(7) No need to preserve machine status (i.e., revenue, inserted coins, product names and prices)

between program executions. Every time the program starts, it should be reset to the initial

conditions (as described below).

Your vending machine should have the following initial conditions every time the program starts.

? Amount of revenue: $0

? Amount of inserted coins: $0

? Product information:

A. Juice ($10) (5 left)

B. Cola ($6) (1 left)

C. Tea ($5) (2 left)

D. Water ($8) (1 left)

E. Coffee ($7) (9 left)


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

python代写
微信客服:codinghelp