Discussion-about-Programming-Construct-computer-science-homework-help
Discussion-about-Programming-Construct-computer-science-homework-help
Discussion:
(I will post a student’s example for this assignment )
There are 3 basic programming constructs we use. Let’s look at the process of withdrawing money from a bank account by way of an ATM machine. What are the steps we might use?
Step 1: Slide debit card
Step 2: Enter PIN
Step 3: Ask how much to withdraw
Step 4: Make a choice from the account
If savings account and if enough money, money is withdrawn from savings
If checking account and if enough money, money is withdrawn from checking
Step 5: Money is given.
Step 6: Receipt is given.
Step 7: Do you want to perform another transaction
if yes, go back to Step 3,
if no, stop.
This may not be exactly like your ATM, but it’s not a far stretch. However, from this example, we can see the need for the 3 basic programming constructs.
They are:
1: Sequence
2: Selection
3: Iteration
Let’s detail each of these:
1: Sequence. This is something like a recipe. You follow instructions, step by step, in order, one at a time, to achieve some goal. You will most always have this in programming. In the ATM example, Steps 1, 2, and 3 are examples of sequence.
2: Selection. Sometimes we are required to make a choice, such as Step 4 above. We will either select one path OR another path based upon some condition or question that we ask.
3: Iteration. Repetition is its synonym. Often, we need to repeat code, so based upon some condition or question, we will do some set of instructions again. In coding, we call this a loop.
Student’s example:
One main example I found regarding sequence is a payroll. For example:
1. Do payroll
2. Enter pay details (employee name, rate of pay, hours worked)
3. Calculate pay
4. Document/print pay details
5. Update employee record
So, every time a business does a payroll it’s always going to be done using the same method.
