Name: ____________________________________________________ Alpha: _____________ Section: ________

Describe help received: _________________________________________________________________

See the bottom for how to submit your work.

Due: Before 0800 on next class day

  1. (10 pts) Read lecture notes for today. Honestly declare how you read the notes.
    1. (10 pts) I read the notes carefully. I have a good understanding of the topics therein.
    2. (10 pts) I read the notes carefully, but I don't really understand the following points well:
      
      
      
      
    3. (0 pts) I didn't read the notes carefully.
  2. [10pts] Rewrite the following code so that the for-loops are replaced with while-loop loops. Use the empty space below.
    
    // using for loops
    #include <iostream>
    using namespace std;
    int main()
    {
      int a, b;
      cin >> a >> b;
      for(int i=1; i < a; i++)
      {
        for(int j=b; j >= 0; j -= 2)
          cout << i*j << " ";
    
        cout << endl;
      }
      return 0;
    }
    
    
    // using while loops
    
  3. [10pts] Consider the following source code:
    
      int a, b;
      cin >> a >> b;
      for(int i=1; i < a; i++)
      {
        for(int j=b; j >= 0; j -= 2)
          cout << i*j << " ";
    
        cout << endl;
      }
    
    Suppose the user gives the following input to the program:
     3 3 
    Write below the output of the program, given the above input. Try it without compiling and running the code.
    
    
    
    
    
    
  4. [70pts] Write a program hw.cpp that works as follows:
    1. The program reads a text file specified by a user.
    2. The file contains an arbitrary number of integers each of which is between 10 and 29 (inclusive). Assume all the numbers are always in the correct range (i.e., between 10 and 29).
    3. After reading all the numbers, the program draws a histogram.
    A sample run is as follows:

    dataA.txt sample run
    28
    13
    29
    20
    27
    24
    
    ~/$ ./hw
    Enter a filename: dataA.txt
    [10,19]: *
    [20,29]: *****
    

    In the above output,

    We provide three files: dataA.txt, dataB.txt, and dataC.txt. Below, we give a sample run for each of dataB.txt and dataC.txt.

    ~/$ ./hw
    Enter a filename: dataB.txt
    [10,19]: ***************
    [20,29]: *****
    
    ~/$ ./hw
    Enter a filename: dataC.txt
    [10,19]: ***************************************************
    [20,29]: *************************************************
    
    Note: You can freely use either while-loops or for-loops or both.

Submit to the submission server (due: 0800 on the next class day)

 ~/bin/submit -c=IC210 -p=hw11 hw.cpp 
Bring to class