So ... You Want to be a Programmer by Ron English
Author:Ron English [English, Ron]
Language: eng
Format: azw3
Publisher: Internethics
Published: 2002-08-24T16:00:00+00:00
After we test our pseudo-code to ensure that it a) matches our flowchart, and b) works, then we write the code. Bank Machine
The bank teller problem is a little more challenging, because the possible inputs and outputs vary. Keeping in mind that the solution has to be expandable, the easy solutions are not necessarily the best.
Input Has part pennies Amount There are three places to the right of the decimal
Not enough money in
account Amount is greater than the balance Not multiple of $20.00 OK The amount is not a
multiple of $20.00
Amount is less than the balance. Subtract the
amount from the balance, and give the customer the amount.
Save the balance
For example, we can agree that partial pennies are not acceptable, but what about multiples of $20.00? Is it reasonable to assume that withdrawals might be for bill payment, or interact payments? If so, then can these withdrawals be odd amounts? We can’t just lump all the invalid amounts together, as this would make the solution hard to maintain. We need to ask each question separately. Even the order in which the questions are posed can be the difference between a good program and a not-so-good one. In this example, if our first question is about multiples of $20, then if we add interact payments our code will have to be rewritten. Ask the questions which are crucial first. In this case, having part pennies means the amount is not a valid dollar amount.
Our flowchart will look something like this: Bank ATM Machine
Again, we need to test our flowchart. Does it work? Our pseudo-code is derived form the flowchart.
start
get AMOUNT
get BALANCE
if AMOUNT three decimal places
Error Message - invalid number else
if AMOUNT > BALANCE
error message - NSF
else
if AMOUNT not multiple of $20 Error message - Not $20 else
BALANCE <= BALANCE-AMOUNT Print BALANCE, AMOUNT end if
end if
end if
end
Again, we test. Then we get to code.
Coding Coding is not a major theme of this book. In the first example here, the conversion program, I'll present code in different languages. This is more for comparison of different languages than to teach you how to code. I will leave the bank teller program for you to code in the language of your choice.
In all cases, I assume the input is an integer in the range of 0 to 18,000.
Pascal
Program Conv(input, output); var miles : integer; answer : integer;
begin readln (miles);
if miles >= 0 then
if miles <= 18000 begin
end
else
answer := 1.8 *invalue; writeln (answer); writeln ("Error, too big"); else
writeln ("Error, negative");
end.
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
The Mikado Method by Ola Ellnestam Daniel Brolund(26289)
Hello! Python by Anthony Briggs(25216)
Secrets of the JavaScript Ninja by John Resig Bear Bibeault(24445)
Kotlin in Action by Dmitry Jemerov(23533)
The Well-Grounded Java Developer by Benjamin J. Evans Martijn Verburg(22878)
Dependency Injection in .NET by Mark Seemann(22666)
OCA Java SE 8 Programmer I Certification Guide by Mala Gupta(21430)
Algorithms of the Intelligent Web by Haralambos Marmanis;Dmitry Babenko(20272)
Grails in Action by Glen Smith Peter Ledbrook(19342)
Adobe Camera Raw For Digital Photographers Only by Rob Sheppard(17055)
Sass and Compass in Action by Wynn Netherland Nathan Weizenbaum Chris Eppstein Brandon Mathis(16365)
Secrets of the JavaScript Ninja by John Resig & Bear Bibeault(14077)
Test-Driven iOS Development with Swift 4 by Dominik Hauser(12254)
Jquery UI in Action : Master the concepts Of Jquery UI: A Step By Step Approach by ANMOL GOYAL(11532)
A Developer's Guide to Building Resilient Cloud Applications with Azure by Hamida Rebai Trabelsi(10643)
Hit Refresh by Satya Nadella(9219)
The Kubernetes Operator Framework Book by Michael Dame(8579)
Exploring Deepfakes by Bryan Lyon and Matt Tora(8432)
Robo-Advisor with Python by Aki Ranin(8376)