<< Chapter < Page | Chapter >> Page > |
In understanding how you might behave as a human computer program, consider yourself to have a job working at the checkout counter of a small grocery store in the 1930s.
You have two tools to work with:
Initialization
Each morning, the owner of the grocery store tells you to insert a name in the slot above each compartment and to place a little slip of paper with a number written on it inside each compartment. (In programming jargon, we would refer to this as initialization.)
Each of the names on the compartments represents a type of grocery such as
No two compartments can have the same name.
No compartment is allowed to have more than one slip of paper inside it.
The price of a can of beans
When you place a new slip of paper in a compartment, you must be careful to remove and destroy the one that was already there.
Each slip of paper that you insert into a compartment contains the price for the type of grocery identified by the label on the compartment.
For example, the slip of paper in the compartment labeled Beans may contain the value 15, meaning that each can of beans costs 15 cents.
The checkout procedure
As each customer comes to your checkout counter during the remainder of the day, you execute the following procedure:
In programming jargon, we would say that as you process each grocery item for the same customer, you are looping . We would also say that you are executing a procedure or an algorithm .
When you have processed all of the grocery items for a particular customer, you would
A schematic representation of the procedure
We might represent the procedure in schematic form as shown in Figure 1 .
Figure 1 . A checkout counter algorithm. |
---|
For each customer, do the following:
For each item, do the following:a. Identify the type of grocery item
b. Get the price from the compartmentc. Add the price to accumulated total
End loop on grocery itemsPresent customer with a bill
End loop on a specific customer |
Common programming activities
This procedure illustrates the three activities commonly believed to be the fundamental activities of any computer program:
Sequence
A sequence of operations is illustrated by the three items labeled a, b, and c in Figure 1 because they are executed in sequential order.
Selection
The process of identifying the type of grocery item is often referred to as selection . A selection operation is the process of selecting among two or more choices.
Notification Switch
Would you like to follow the 'Object-oriented programming (oop) with java' conversation and receive update notifications?