Homework 1.

Objectives

We would like to :
  1. Discuss a solution for homework 1.

Notes

MY solution

  1. Personal identifying information. (name, class, ...)
  2. A high level description of the problem.
       Given a set of problems with a start, end and skip value, count from the starting value to the ending value skipping by the skip value.  
  3. A list of questions about the problem.
    
    
  4. A description of the problem's input/output.
       Input:   
           A valid file name.
           For each case in the file
              The case description
              Start, stop and end value
        Output:
           For each case:
              The case description
              The proper count.
    
  5. A set of test cases, both input and output.
    Easy, what everyone knows how to do! 1,5,1 1, 2, 3, 4, 5
    Can you count down? 5,1,1 5, 4, 3, 2, 1
    Can you skip by 2? 1,6,2 1, 3, 5
    Can you skip by 2 counting down? 7,3,2 7, 5, 3
    Can you count a single thing? 1,1,100000 1
    
    
  6. A program decomposition, showing how the various modules will interact.
                          main
                           |
            +--------------+-----------------+
            |              |                 |
        open file      get problem     solve problem
    
  7. Algorithms for the main and all sub algorithms required to solve this problem.
    Main
    Open the file.
    
    get a problem
    while not at the end of the file
       solve the problem
       get a problem.
    
    Open the file
    Ask the user for a file name
    try to open the file with that name.
    while the file was not opened
        Print error message
        Ask the user for a file name
        try to open the file with that name.
    
    return the file stream
    
    Get a problem
    read the problem statement
    read the  start, stop and skip values
    
    Solve the problem
    if skip is not positive
       print error
    else if start is less than or equal to stop
        lcv = start
        while lcv is less than or equal to stop
            if not the first time
               print ", "
            print lcv
            increment lcv by skip
    else
        lcv = start
        while lcv is greater than or equal to stop
            if not the first time
               print ", "
            print lcv
            decrement lcv by skip