算法task:Automated Teller Machine (ATM)作业

wx:help-assignment

access to me asap在这里插入图片描述

Homework Description

Study the material, design and implement your solution and test it before you submit it.
So, before submitting your work, make sure…
Your program compiles
There are no errors or warnings
The program works as required.
Table of contents

  1. General
    1.1. Grading
    1.2. Example material
  2. About the text file 12345.acc
    2.1. Storing the new balance to the file
  3. Required functionality
    3.1. Validating a client account
    3.2. Main menu of the ATM
    3.3. Query balance
    3.4. Withdraw money
    3.5. Deposit money
  4. General
    Design and implement a program that works like an Automated Teller Machine (ATM) – a program which enables clients to withdraw & deposit money to a given bank account and to query the balance of the given bank account. The program simulates the use of the atm with a “bank card” by utilizing a text file.
    You can use the example source file, exampleATM.c and the example text file 12345.acc as templates for your program. Study the program and its current functionality carefully (the example does not have all required functionality in place). Study the given text file, too. Then modify the program and implement the required functionality.
    Note, the user interface (UI) of your program may differ from the examples, but all functionalities must be in place, as required. Any wrong, incomplete or missing implementation will affect the grading. The submitted program must compile with no errors or warnings.
    Implement your solution one step at a time, do not try to complete everything at once. Make some minor changes and test those before you continue with your work.
    While working…
    Focus on learning - study the issues from the course content
    Design the functionality of the program & its logic before you start coding
    Give variables and functions descriptive names
    Use given utility functions for reading user input
    Create your own functions for the different functionalities of the program
    Initialize the variables
    Utilize conditional statements and loops where necessary
    Test your program - regularly! You are like a detective studying your own code to find the nasty bugs. Use printf-statements and/or utilize debugger to analyze the problems in your code.

Read the instructions carefully, study the material and focus on learning.

1.1. Grading
The source code must be written in C language.

The UI of the ATM does not have to be exactly the same as in the example (e.g., when asking for amount of money to deposit or withdraw, the instructions for the client do no not have to be as long as in the example), but the functionality of the program must be implemented according to the instructions.

Follow carefully the given instructions and the given deadline.

The program code must be syntactically correct, i.e., the program must compile. Otherwise, the points will almost without exception be zero.
User correct data types for the variables.
Name the variables and functions in a way that those are self-documenting (=code is easy to read and understand).
Use utility functions (given in the course material) for reading the user input.
Use functions for the user options in your program (points will be reduced all/most of the code is in the main function).
The program code must be clear and well structured. The points will be reduced for very confusing code.
Naturally, the implementation must follow the task description. Solutions not following the given description will lead to reduction of points, case by case.
The feedback provided by the compiler is valuable. Analyze possible errors, study your own code with care and fix all problems (both errors and warnings).
Always remember to test your program (to ensure it does what is required the way it is required).

1.2. Example material
Study the contents of and use it accordingly: Example bank account text file.
Study the source code and modify it as required: Example atm source file.

Video showing how a completed assignment should work.
The account number is given wrong first (the correct account number is 12345). Then, the pin code of that account is given wrong twice (the correct pin code is 1234). The initial balance of the account is 99.90. The user enters some invalid values for deposit and withdrawals. At the end of the program the new balance will be written to the account file, so next time the program would run, the initial balance would be 555.55.

  1. About the text file 12345.acc
    Save the account information text file (.acc) in the same directory where you have the executable program (.exe). Typically that is the same directory where you have the source code file (.c) of the program, too. That way, there is no need to write the full (absolute) file path into the program (remember, study how to handle a text file in C). Do not hard code your own file path into the program.
    Any account file must be named as “nnnnn.acc”, without quotation marks, where “nnnnn” is the name of the client’s account. For example, for the account 12345 the file name would be 12345.acc. The program can be tested with several account files.
    An account file (.acc) has two lines of text: in the first line there is the pin code, four characters e.g., 1122 and in the second line there is the amount of money (e.g., 2300.26).
    Format of the file content (just two lines of text in the file). Note, the shown below is not written in the file as such, but it is shown below as the end of file marker for clarity.
    PIN-code
    Balance

    For example, a file 12345.acc could have the following data = pin code 1122 and account balance 2300.26 = just two lines of text in the file. Note, the mark below just highlights the end of the file…

1122
2300.26

2.1. Storing the new balance to the file
When the client successfully “logs in” to the account the initial balance is read from the file. The balance is processed in the program until the client selects “end”.
There are two options for handling the file…
Option 1: The program does not modify the existing account file, i.e., no matter which actions have been selected on the account, the original initial balance will be in place when the program is re-run. For example, in the file 12345.acc, upon the program start, the balance for the account 12345 would always be 99.90 euros.
Option 2: The program, after the user has selected “end”, updates the account file to have the new value of the balance there, i.e., the modified balance will be used when the program is re-run. For example, if the original balance in the file 12345.acc for the account 12345 was 99.90 euros, and the client had deposited the sum of 220 euros and had withdrawn 150 euros before ending the processing of the account, the updated balance would be 169.90 euros. That updated balance 169.90 would be then saved into the account file and the next time the program would be run with the file, the initial balance for the account would be 169.90.
If the balance is saved to the file upon program exit (when the client selects “end”), the program must print the balance and the file name to the client, for example…
The balance 169.90 saved to the account file “12345.acc”.

Note - the “Option 2” will give a few extra points (provided the functionality is implemented correctly).
3. Required functionality
Create a C-program for simulating an ATM.
When the program starts, it will display a greeting to the client…
*** Welcome to use the ATM! ***
The client of the ATM is the user who “owns” the account file, e.g., knows the account number and its PIN-code.
Functionality of the ATM…

  1. The program must validate the client in order to let the client to use the ATM

The given account number must be validated (matches the name of a text file)
The given PIN-code for the account must be validated (provided the given account is ok, the given PIN-code must match the PIN-code read from the text file).
2. After successful client validation…

The program will present the client a main menu from where the client can choose an action for the given account: withdraw or deposit money, ask for the balance or end (the processing of the account)…
After executing the selected action, the program must return to the main menu - unless end has been selected.
The client can perform several (different) actions on the given account sequentially (until end is selected).
3. After the client has ended processing the account the program will stop execution.

The program can be a “single-client” ATM (no need to have the functionality for “multi-client” ATM). However, extra functionality (when implemented correctly, may give a few extra points).

3.1. Validating a client account
Note, the example account file in the examples below is 12345.acc, and in that file the PIN-code of the account is 1234 and the balance of the account is 99.90.
The program will ask the client for the account number.
Give account number:
If the client enters a non-existing account number, the program must first display an error message and then return to asking for the account number.
Client tries to enter a non-existing account number…
Give account number: 11223344
Wrong account number!
Give account number:
Client enters an existing account number (12345 matching the file 12345.acc)…
Give account number: 12345
The program will try to open a text file with the name of that given bank account number. If the text file with that name exists (i.e., the client has an existing bank account), the program asks the client to enter the pin code of the account.
The pin code for the account is stored as a string in the first line of the text file (with account number as a file name, e.g., “12345.acc”).
The client has three (3) attempts for entering the PIN-code. If the PIN-code is entered incorrectly three times, the program will show the client an error message, and then return back to ask for the account number or stops the program execution (up to you).
Give your account PIN code (1. try):
The client enters invalid PIN-code three times (the valid one for the account 12345 is 1234)…

Give your account PIN code (1. try): 1
***** Wrong PIN code!

Give your account PIN code (2. try): 2
***** Wrong PIN code!

Give your account PIN code (3. try): 3
***** Wrong PIN code!

***** Too many wrong attempts!
Your account is closed
The program stops execution. (Or, the program could continue to ask for another account number if you would plan to have a “multi-client” ATM, but that is not required).

If the client enters invalid PIN-code just once and the enters a valid one (1234) for the account (12345.acc)…

Give your account PIN code (1. try): 15
***** Wrong PIN code! (Press enter)
Give your account PIN code (2. try): 1234

If the pin code entered by the client and the corresponding pin code read from the text file are the same (exact match)…
The program can read the initial balance for the account from the file. The initial balance (double) for the account is stored as a string in the second line of the text file.
The program will display the client the menu of the available options to choose (withdrawal, deposit, query balance, quit).

3.2. Main menu of the ATM
Implement the main menu of the program as a function.
Once the account and the PIN-code of the account has been validated, the client is shown a main menu. The menu must have options for withdrawing and depositing money, querying the balance of the account and for stopping the processing of the account.
Select an option…
1. = Withdrawal
2. = Deposit
3. = Query balance
9. = Quit
Your choice:
Note that the program must handle possible erroneous cases where the client would enter a wrong value for the choice (e.g., a wrong numeric value or a letter instead of a numeric value).
If the client enters a valid option (1, 2, 3 or 9), the program must perform the required action for the account.
If the client enters an incorrect value for the choice, the program must display an error message…
Select an option…

  1. = Withdrawal
  2. = Deposit
  3. = Query balance
  4. = Quit
    Your choice: t

You did not enter an integer!
Wrong option, try again.
Select an option…

  1. = Withdrawal
  2. = Deposit
  3. = Query balance
  4. = Quit
    Your choice: -2

Wrong option, try again.

3.3. Query balance
Implement the functionality of the query of the balance as a function.
When querying the balance of the account, the program will display the balance to the client, and return back to the main menu.
Note, the initial balance of the example account 12345 is 99.90.
Select an option…

  1. = Withdrawal
  2. = Deposit
  3. = Query balance
  4. = Quit
    Your choice: 3

***** Balance: 99.90
Select an option…

  1. = Withdrawal
  2. = Deposit
  3. = Query balance
  4. = Quit
    Your choice:

3.4. Withdraw money
Implement the functionality for the withdrawal as a function.
Note, the example account file in the examples below is 12345.acc, and in that file the PIN-code of the account is 1234 and the balance of the account is 99.90.
The amount of money asked from the client for withdrawals are implemented using integer variables in the program. The program will inform the client if the amount to withdraw was ok or not (e.g. withing the given limits or non-negative).
The withdrawal is only done if the amount is valid. There are restrictions for withdrawing money.
The ATM will only give out bank notes (paper money) of 20 and 50 euros. Therefore, a client can withdraw either 20€ or 40€, or more at intervals of ten (e.g. 50€, 60€, 70€, 80€, 90€, 100€, 110€, 120€, 130€, etc.), i.e., the client cannot withdraw for example 30, -100, 91 or 77 euros.
The ATM will ask for the amount to be withdrawn - until a valid value or zero is given. (With zero value the client can then stop the withdrawal process).
The minimum draw is 20 euros and the maximum draw is 1000 euros. Naturally, the client cannot withdraw more money than there is in the bank account. And note the following restriction!
The balance of the account must be at least 20 euros after the withdrawal. The client cannot withdraw all money form the account, there must be at least 20 euros left in the bank account.
For withdrawal, the program will print the number of bank notes given, i.e., the number of both 20-euro and 50-euro bank notes needed to be given to the client and also the balance of the account after the withdrawal.
The machine must give the money with least amount of bank notes (giving out the sum with as big bank notes as possible). For example, if the amount of money to withdraw is 270 euros, the program will “give” five 50-euro bank notes and one 20-euro bank note (550 + 120 = 270).

For example - for the amount to withdraw the client first enters 55, then -2 and then letter ‘t’, after which the client decides to go back to the main menu by entering 0.
After that the client selects withdrawal again, and enters first 33 and then 10 (both of which cannot be given with 20 and 50 euro bank notes) and finally 70 which can be given with one 50 and one 20 euro bank notes.

Select an option…
1. = Withdrawal
2. = Deposit
3. = Query balance
9. = Quit
Your choice: 1

Give the amount to withdraw (full tens: 20, 40-1000): 55

Give the amount to withdraw (full tens: 20, 40-1000): -2

Give the amount to withdraw (full tens: 20, 40-1000): t

You did not enter an integer!
Give the amount to withdraw (full tens: 20, 40-1000): 0       

**********
Cancelled.
*******

***** Balance: 99.90

Select an option...
1. = Withdrawal
2. = Deposit
3. = Query balance
9. = Quit
Your choice: 1

Give the amount to withdraw (full tens: 20, 40-1000): 33

Give the amount to withdraw (full tens: 20, 40-1000): 10

Give the amount to withdraw (full tens: 20, 40-1000): 70

**************
Withdrawal ok.
*************

Amount 70:
*** Notes 50:   1
*** Notes 20:   1

Chcek: (1 * 50) + (1 * 20) = 70.

***** Balance: 29.90

3.5. Deposit money
Implement the functionality for the deposit as a function.
Note, the example account file in the examples below is 12345.acc, and in that file the PIN-code of the account is 1234 and the balance of the account is 99.90.
The amount of money asked from the client for deposits are implemented using real number variables (double) in the program.
The money is deposited only if the amount is valid. When depositing money, the client can enter an amount of money between 10.0-1000.0 euros and that will be added to the balance of the account. There are restrictions for depositing money.
The minimum deposit is 10.0 euros and the maximum is 1000.0 euros. Note the following restriction!
The balance of the account is max. 2000.0 euros. The client cannot deposit an amount of money that would result the account to exceed the maximum.
The ATM will ask for the amount to be deposited - until a valid value or zero is given. (With zero value the client can then stop the deposit process).

For example, first the client selects “deposit” but decides to cancel the process by entering 0 as the amount to deposit. Then the client selects “deposit” and decides to add 150.60 euros to the account, so after the deposit the balance will be 250.50 (as 99.90+150.60=250.50).
Then the client tries to deposit an amount of 1750.0 (not allowed, as the balance would exceed the maximum value 2000.0), then the client accidently enters -200.0 (not allowed, a negative value) and finally, enters 220.0, which makes the balance to be 470.50 euros after the deposit.
Select an option…
1. = Withdrawal
2. = Deposit
3. = Query balance
9. = Quit
Your choice: 2

Give the money to deposit (min. 10.00, max. 1000.00 max. (max. saldo 2000.00)): 0

**********
Cancelled.
**********

***** Balance: 99.90


Select an option...
1. = Withdrawal
2. = Deposit
3. = Query balance
9. = Quit
Your choice: 2

Give the money to deposit (min. 10.00, max. 1000.00 max. (max. saldo 2000.00)): 150.60

***********
Deposit ok.
***********

***** Balance: 250.50


Select an option...
1. = Withdrawal
2. = Deposit
3. = Query balance
9. = Quit
Your choice: 2

Give the money to deposit (min. 10.00, max. 1000.00 max. (max. saldo 2000.00)): 1750

Give the money to deposit (min. 10.00, max. 1000.00 max. (max. saldo 2000.00)): -200

Give the money to deposit (min. 10.00, max. 1000.00 max. (max. saldo 2000.00)): 220

***********
Deposit ok.
***********

***** Balance: 470.50
  • 8
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值