Name: ____________________________________________________ Alpha: _____________________

Describe help received: _________________________________________________________________

  1. [20pts] Below is the program that works as follows: Fill out the blanks below.
    
    #include <iostream>
    #include <fstream>
    using namespace std;
    
    int main()
    {
      ifstream f1("in.txt");
      
      ____________________________;                // fill here 
    
      char c;
      int x, y;
      while( f1 >> c >> x >> c >> y >> c )         // fill here
      { 
        if( (x != 2) ________________ )            // fill here
    
          _____________________________________;   // fill here
        else
    
          _____________________________________;   // fill here
      }
    
      return 0;
    }
    
       in.txt:
     (1,2) (2,3) (2,1) (1,3) (10,1) (2,3)
    out.txt:
     (1,2) (0,0) (2,1) (1,3) (10,1) (0,0)
  2. [80pts] Write a program hw.cpp that prints rectangles (in text) on the screen. The outline of the rectangles should be in * characters and the inside should be empty (i.e., filled with spaces).

    Your rectangle will have a certain height and width, as well as an offset which is a number of spaces to the left of the left side of your rectangle.

    Here are some examples of how your program should work:

    ~$ ./hw
    Enter height (greater than 2): 5
    Enter width  (greater than 2): 8
    Enter offset: 3
       ********
       *      *
       *      *
       *      *
       ********
    ~$ ./hw
    Enter height (greater than 2): 3
    Enter width  (greater than 2): 10
    Enter offset: 7
           **********
           *        *
           **********
    

    In writing your program, use the idea of stepwise refinement that we talked about in class. You may assume that the height and width will always be at least 2.

Turn in