Reference no: EM132164636
Assignment -
Specifications: You are required to design an algorithm for an Automated Teller Machine.
Task 1 - Problem Decomposition
iBank wants to develop its own ATM system. The system will look and work much like other competitor systems work. You have been asked to develop the software for the system. This software will allow customers to withdraw cash and check their balance.
a) Using the approach to problem solving learned in class, identify:
- The principal parts (sub-problems) of the problem.
- Any assumptions you are making with regards to the problem.
b) In pseudo code, outline the basic steps (no more than six) involved in withdrawing cash (Do not include any choice or iteration at this point).
Task 2 - Start-up
The process of withdrawing cash will begin only if a customer card is entered. In pseudo code, add an IF/ENDIF statement to your pseudo code that will account for the customer inserting a card. Please note that if a customer does not insert a card, then NONE of the steps in the cash withdrawal, or balance checking process, should happen.
Task 3 - Pin Entry
Once a card has been inserted into the machine, a customer should be prompted to enter their PIN in order to proceed further. We will assume at this point that the customer has an unlimited number of attempts at entering the correct PIN.
a) In pseudo code, state the variables required for the checking of the PIN. Make sure you choose an appropriate data type for all variables and initialize where appropriate.
c) Adapt your algorithm so that it uses a loop to check the entered PIN number against a customer's stored PIN number.
Task 4 - Menu Choices
Once a correct PIN has been entered, customers will be presented with a services menu. The services menu screen will provide two choices: Check Balance and Withdraw Cash. These choices can be made by selecting buttons 1 or 2 on the menu screen.
If button 1 is selected, the balance screen with the customer's balance should be displayed on the screen. If button 2 is selected, the withdrawal screen should be displayed. You can assume that at this point that all other buttons (3-8) have been disabled. When the withdrawal screen is presented, the following options for the amount to be withdrawn will be presented: £10, £20, £50, £100, £200.
Task 5 - Dispensing Cash
Once the customer has chosen the amount he/she wishes to withdraw, the ATM should dispense the cash and return the card. The cash should be dispensed in the optimum number of notes (Note that the machine dispenses only twenty and ten-pound notes. You can assume that the machine has an unlimited supply of both tens and twenties).
a) Identify any further variables that you would need to implement the dispensing of cash problem. Declare, and initialize where appropriate.
b) Extend your algorithm so that it calculates the optimum number of notes for any requested amount. Thus, if a customer chooses to withdraw £100, the optimum format for the cash to be dispensed would be five twenties, while if the customer chooses to withdraw £50 the optimum format for the cash would be two twenties and one ten.
c) Extend your algorithm to return the £10 and £20 notes to the customer. There will only ever be one £10 note. But there could be 1, 5 or 10 twenties. Thus to return the twenties you will need to use a loop.
Task 6 - Limiting PIN Attempts
A customer should be allowed only three attempts at entering a correct PIN before their card is retained.
a) Identify any further variables that you would need to implement the limitation of PIN attempts to three.
b) Adapt the PIN verification loop from task 3, so that the customer has only three attempts at entering a correct PIN number. If, after three attempts, a correct PIN has not been entered, then the customer's card should be retained, and none of the subsequent steps should happen.
EXERCICES -
Body Mass Index Calculator Body Mass Index (BMI) is used as an indicator of a person's general health. Design a pseudo code algorithm that calculates and displays a person's BMI. BMI is calculated with the following formula. BMI = weight in kilograms ÷ height in metres2 Make sure you identify and declare all required variables.
1. Body Mass Index Calculator
PROGRAM <CalculateBMI>
1. DECLARE double weight, height, bMI ;
2. DISPLAY "Please enter your weight in kilograms" ;
3. INPUT weight ;
4. DISPLAY "Please enter your height in metres" ;
5. INPUT height ;
6. SET bMI = weight / (height * height) ; 7. DISPLAY "Your BMI is " + bMI ;
END
A local authority collects tax on the assessment value of unoccupied land. Tax is paid on 40% of the land's actual value. For example, if a piece of land is valued at £100,000 then only £40,000 is liable for tax. The property is then taxed at 2.6% of the taxable value. Design a pseudo code algorithm that takes a user inputted land value, and displays the amount liable for tax and the amount of tax to be paid. Make sure you identify and declare all required variables and constants. Also, initialize any variables and/or constants that need initializing.
2. Land Tax Calculator
PROGRAM<CalculateLandTax>
1. DECLARE double landValue, taxableValue, taxToPay ;
2. CONSTANT double taxablePercentage, taxRate ;
3. SET taxablePercentage = 0.4 ;
4. SET taxRate = 2.6 ;
5. DISPLAY "Please enter the value of the land" ;
6. INPUT landValue ;
7. SET taxableValue = landValue * taxablePercentage ;
8. SET taxToPay = (taxRate/100) * taxableValue ;
9. DISPLAY "Taxable value = " + taxableValue ;
10. DISPLAY "Tax to pay = " + taxToPay ;
END
Change Calculator Design a pseudo code algorithm for a vending machine that (1) reads (use READ in pseudo code) how much a customer has paid (2) reads the snack price (3) calculates a customer's change (4) returns the change in the fewest number of coins possible. Thus, if a customer purchases a snack for 52p, the change should be returned as 2 x 20p, 1 x 5p, 1 x 2p, and 1 x 1p. While if a customer purchases a snack for 22p, the change returned 2 should be returned as 1 x 50p, 1 x 20p, 1 x 10p, 1 x 5p, 1 x 2p and 1 x 1p. Note that the maximum price of a snack is £1.00, and the machine only accepts payment in coins up to £1.00 in value. UK coins include only 1p, 2p, 10p, 20p and 50p.
3. Vending Machine Change Calculator
PROGRAM<ChangeCalculator>
1. DECLARE integer numberOfFifties, numberOfTwenties, numberOfTens, numberOfFives, numberOfTwos, numberOfOnes, amountPaid, snackPrice, change, remainder ;
2. READ amountPaid ;
3. READ snackPrice ;
4. SET change = amountPaid - snackPrice ;
5. SET numberOfFifties = change / 50 ;
6. SET remainder = change MOD 50 ;
7. SET numberOfTwenties = remainder / 20 ;
8. SET remainder = remainder MOD 20 ;
9. SET numberOfTens = remainder / 10 ;
10. SET remainder = remainder MOD 10 ;
11. SET numberOfFives = remainder / 5 ;
12. SET remainder = remainder MOD 5 ;
13. SET numberOfTwos = remainder / 2 ;
14. SET remainder = remainder MOD 2 ;
15. SET numberOfOnes = remainder / 1 ;
16. Dispense coins ;
END
Design an algorithm that allows refuelling at a petrol station. The algorithm should give the user the option to pay at the pump, or pay at the kiosk. If the user chooses to pay at the pump, then they should be prompted for their payment card, and issued a receipt after refuelling. If the user chooses not to pay at the pump, the payment and receipt steps should be skipped. For both pay at the pump and pay at the kiosk options the algorithm should provide a transaction price. Refuelling should end with a 'Thank you for refuelling with us' message.
1. Pay at Pump
PROGRAM<RefuelVehicle>
1. DECLARE boolean payAtPump ;
2. DECLARE double litresDispensed, price ;
3. CONSTANT double pricePerLitre ;
4. SET payAtPump = false ;
5. SET pricePerLitre = 1.20 ;
6. DISPLAY "Pay at pump?" ;
7. INPUT payAtPump ;
8. IF payAtPump // Or IF payAtPump = true ;
9. DISPLAY "Please insert you payment card" ;
10. ENDIF
11. READ litresDispensed ;
12. SET price = litresDispensed * pricePerLitre ;
13. IF payAtPump
14. PRINT receipt ;
15. ENDIF
16. DISPLAY litresDispensed ;
17. DISPLAY price ;
18. DISPLAY "Thank you for refuelling with us" ;
END
Body Mass Index (BMI) is used as an indicator of a person's general health. Design a pseudo code algorithm that calculates and displays a person's BMI. BMI can be calculated using metric or imperial measurements as follows: Metric: BMI = weight in kilograms ÷ height in metres2 Imperial: BMI = (weight in pounds x 703) ÷ height in inches2 Write an algorithm which (1) Asks the user to select either metric or imperial input (2) Gets the user measurements (3) Calculates the user BMI (4) Displays the user BMI.
2. Body Mass Index Calculator
PROGRAM<CalculateBMI>
1. DECLARE double weight, height, bMI ;
2. DECLARE boolean imperial ;
3. SET imperial = false ;
4. CONSTANT integer imperialMultiplier ;
5. SET imperialMultiplier = 703 ;
6. DISPLAY "Check box for imperial units" ;
7. INPUT imperial ;
8. DISPLAY "Please enter your weight" ;
9. INPUT weight ;
10. DISPLAY "Please enter your height" ;
11. INPUT height ;
12. IF imperial // or IF imperial = true
13. SET bMI = (weight * imperialMultiplier) / (height * height) ;
14. ELSE
15. SET bMI = weight / (height * height) ;
16. ENDIF
17. DISPLAY "Your BMI is " + bMI ;
END
Write an algorithm that totals a grocery order. Use a simple logic controlled WHILE loop to enable the calculation process. Use READ operations to get the price of each grocery item each time the loop iterates. The loop should terminate when there are no more items left to process.
1. Order Total
PROGRAM<TotalOrder>
1. DECLARE double itemPrice, orderTotal ;
2. SET orderTotal = 0.00 ;
3. WHILE more items in order
4. READ itemPrice ;
5. SET orderTotal = orderTotal + itemPrice ;
6. ENDWHILE
7. DISPLAY orderTotal ;
END
Create an algorithm that converts the temperatures 0 to 20 centigrade to their Fahrenheit equivalents and displays the outcome. The formula for converting from centigrade to Fahrenheit is: F = C × 1.8 + 32 Use a count-controlled WHILE loop for this problem, using the counter to limit the number of iterations of the loop to the required number.
2. Centigrade to Fahrenheit
PROGRAM<CentigradeToFahrenheit>
1. DECLARE double centigrade, fahrenheit ;
2. SET centigrade = 0.00 ;
3. WHILE centigrade <=20.00 ;
4. SET fahrenheit = (centigrade * 1.80) + 32.00 ;
5. DISPLAY fahrenheit ;
6. SET centigrade = centigrade + 1.00 ;
7. ENDWHILE
END
Truck Loading Calculations Update the truck loading algorithm below so that it calculates the following:
- The total number of boxes despatched.
- The weight of the heaviest box despatched.
- The average box weight. Make sure you declare and initialize any new variables as required.
2. Truck Loading Calculations
PROGRAM<LoadTrack>
1. DECLARE integer numberOfBoxes ;
2. DECLARE double totalWeight, payload, averageBoxWeight, boxWeight heaviestBox ;
3. CONSTANT integer capacity ;
4. SET capacity = 200 ;
5. SET numberOfBoxes = 0 ;
6. SET totalWeight = 0.00 ;
7. SET heaviestBox = 0.00 ;
8. WHILE (more boxes on conveyor)
9. SET payload = 0.00 ;
10. READ boxWeight ;
11. WHILE boxWeight + payload <= capacity
12. Load box on truck ;
13. SET payload = payload + boxWeight ;
14. SET numberOfBoxes = numberOfBoxes + 1 ;
15. SET totalWeight = totalWeight + boxWeight ;
16. IF boxWeight > heaviestBox
17. SET heaviestBox = boxWeight ;
18. ENDIF
19. READ boxWeight ;
20. ENDWHILE
21. Despatch truck ;
22. ENDWHILE
23. SET averageBoxWeight = totalWeight / numberOfBoxes ;
24. DISPLAY numberOfBoxes ;
25. DISPLAY heaviestBox ;
26. DISPLAY averageBoxWeight ;
END