Information Technology Topic

Decomposing a Problem

  1. Read notes
  2. Flashcards
  3. Quiz
  4. Confident

Study focus - 3 things

  1. Decomposing a simple problem means breaking it into four significant parts: input, process, storage and output
  2. Input is what is typed in, process is the working-out, storage is the named places in memory that hold values, and output is the result shown to the user
  3. List the four parts first, then write the pseudocode in the same order: Input, then Store (the working-out), then Display

Section 1Breaking a big problem into small parts

Decomposing a problem means breaking it into smaller parts that are each easier to think about. Nobody solves 'make a billing program for a hardware shop' in one go. They ask smaller questions: what goes in, what is worked out, what is kept, what comes out? For a simple program there are four significant parts: input, process, storage and output. Here's the trick: if you can fill in all four parts for a problem, you understand it well enough to write the algorithm. It is step 1 of problem solving, defining the problem, made specific.

Section 2Input: what goes in

Input is the data the program must be given before it can do anything. It is usually typed at the keyboard, and the program reads each value into a named place in memory. Ask: what does the program need to be told? For a tuck-shop bill, the price and the quantity. In pseudocode: Input price, quantity. The words Read and Input mean the same thing here. In Pascal-style code the statement that reads typed values into variables is readln(price, quantity). Watch out: list only what the user must supply. A value the program works out, such as the total cost, is not an input.

Section 3Process: the working-out

Process is the working-out: the calculations and decisions that turn the inputs into the answer. The arithmetic operators are + (add), - (subtract), * (multiply) and / (divide). For the tuck shop the process is: cost is the price multiplied by the quantity. In pseudocode that is Store price * quantity in cost. Easy to mix up: a computer needs * for multiply, not x. The line price x quantity is not accepted.

Section 4Storage: where values are kept

Storage means the named places in memory that hold values while the program is running. Each input is read into one of them and each calculated result is kept in one too. A place has a name such as price, quantity or cost. In a decomposition, list every value the program needs to keep and give each a meaningful name. A value that can change while the program runs is a variable. A value that never changes, such as a fixed delivery fee, is a constant. The next topic covers both. Easy to mix up: storage here is not about saving a file on a disk or flash drive. It is the working memory of the running program.

Section 5Output: what comes out

Output is the result the program gives back to the user, normally shown on the screen. In pseudocode the words Write, Output and Display are all used for this, as in Display cost. In Pascal-style code, writeln(cost) writes a value out to the screen. Output comes last in the chain, because the result must be worked out and kept before it can be shown. Display cost before cost has been stored and there is nothing correct to show.

Section 6Putting the four parts together

Problem: a pupil at a Portmore school buys patties at the tuck shop and the program shows the cost. Input: the price of one patty and the number bought. Process: cost is price multiplied by quantity. Storage: price, quantity and cost. Output: the cost. With a price of 250 and a quantity of 3, the process works out 250 * 3 = 750, and 750 is displayed.

Section 7From the four parts to pseudocode

Once the parts are known, the pseudocode almost writes itself. Inputs first, then the process, then the output: Input price, quantity Store price * quantity in cost Display cost Check the order. A value must have been input or stored before a later line uses it. Here's the trick: if one part is still hard, decompose that part again into smaller parts, until each is easy.

Examples

A pupil at a Portmore school buys 3 patties at 250 dollars each. A program is to read the price and the quantity and show the cost. (a) Decompose the problem into input, process, storage and output. (b) Write the pseudocode. (c) Calculate the value displayed.

(a) Input: the price of one patty and the quantity bought. Process: cost is price multiplied by quantity. Storage: price, quantity and cost. Output: the cost. (b) Input price, quantity Store price * quantity in cost Display cost (c) With price 250 and quantity 3, cost = 250 * 3 = 750, so 750 is displayed. Notice that cost is not an input. The user never types it, because the program works it out in the process part and keeps it in storage.

A hardware shop in Mandeville sells zinc sheets at 2400 dollars each and adds a fixed delivery fee of 1500 dollars to every order. The program reads the number of sheets and shows the bill. (a) Decompose the problem into input, process, storage and output. (b) Write the pseudocode. (c) Calculate the bill for 5 sheets, and for 3 sheets. (d) The shop changes the delivery fee to 1800 dollars. State which part of the decomposition changes and calculate the new bill for 5 sheets.

(a) Input: the number of sheets. Process: cost is sheets multiplied by the price, and bill is cost plus the delivery fee. Storage: sheets, cost and bill, which change from order to order, and price (2400) and delivery (1500), which never change. Output: the bill. (b) Store 2400 in price Store 1500 in delivery Input sheets Store sheets * price in cost Store cost + delivery in bill Display bill (c) For 5 sheets: cost = 5 * 2400 = 12000 and bill = 12000 + 1500 = 13500. For 3 sheets: cost = 3 * 2400 = 7200 and bill = 7200 + 1500 = 8700. (d) Only a stored value changes: delivery becomes 1800. The input, the process steps and the output stay exactly as they were. The new bill for 5 sheets is 12000 + 1800 = 13800. The price and delivery values are kept in named storage, so the change is made in one place.

Now let's water it

Session runs notes to flashcards to quiz back-to-back.

Where this comes from