Lab Exercise 13

Decomposing Problems


CS 1510
Introduction to Computing


Introduction

Today's lab is different than our usual routine. Instead of reading, running, and writing code, we will be thinking about and practicing program design. In particular, you will be doing functional decomposition, which is the process of dividing large programming tasks into smaller subproblems.

Different duties call for different deliverables. Today, you write your answers on this lab handout and turn it in before you leave.

Two other changes for this lab:

  1. You will work in pairs. Each pair will submit a single completed lab handout.
  2. You do not need a computer for any of your work today. So...

Let's start.



Tasks

  1. Review the Reading

    Take a few minutes to review individually the excerpt on functional decomposition from Programming and Problem Solving with Ada 95, by Dale, Weems, and McCormick, that you were assigned to read last Thursday. This is general material about designing programs. In your mind, replace any references to "Ada" with "Python".

    Together, answer these questions in your own words. Be sure you both understand the answers.

    Question 1-1. A module is a collection of abstract and concrete steps that solve a problem.

  2. Question 1-2. The reading describes a module structure chart.


  3. Decompose a Task

    An algorithm is a step-by-step procedure for solving a problem. We can express a solution to any problem with and algorithm, whether we write a program to solve the. problem or not. Let's practice on a simple problem with which you have some experience:

    Estimate how much money is required to attend a university for an academic year (two semesters).

    Question 2-1. Create a Level 0 module to solve the problem of estimating the yearly cost of attending a university.

    
    
    
    
    
    
    
    

    Question 2-2. Complete the Level 1 module for the step selected by your instructor: ______________________.

    
    
    
    
    
    
    
    


  4. Think about Functional Equivalence

    One of the key ideas in the reading is functional equivalence.

    Question 3-1. Define functional equivalence.

    
    
    
    

    Question 3-2. Use the modules you wrote for Task 2 as examples to explain the idea of functional equivalence.

    
    
    
    


  5. Think about Functional Cohesion

    Another key idea in the reading is functional cohesion.

    Question 4-1. Define functional cohesion.

    
    
    
    

    Question 4-2. We can often tell that a module is not cohesive from its name. Consider these module names:

    Circle the names of modules you suspect lack cohesion, and explain why.


  6. Practice Functional Decomposition

    Consider this problem specification from another CS 1510 section's programming assignment:

    Your program will allow a human user to play several rounds of Rock, Paper, Scissors with the computer. Each round of the game will have the following structure:
    • The program will choose a weapon (Rock, Paper, Scissors), but its choice will not be displayed until later so the user doesn't see it.

    • The program will announce the beginning of the round and ask the user for his or her choice of attack.
      • The user can enter either of the three attacks or the signal to quit.
      • If the user inputs something other than r, R, p, P, s, S, q or Q, the program will detect the invalid entry and ask the user to make another choice.

    • If the user entered an attack:
      • The two weapons will be compared to determine the winner (or a tie) and the results will be displayed by the program.
      • The computer will keep score which will be displayed later.
      • The next round will begin, and the game will continue until the user chooses to quit.

    • If the user enters quit than the computer:
      • Prints a goodbye message which should include a score of all of the games played.

    Question 5-1. Decompose this problem into a hierarchy of problems and sub-problems, following the process described in your reading.

    Raise your hand when you are done.



Eugene Wallingford ..... wallingf@cs.uni.edu ..... November 19, 2014