Name: ____________________________________________________ Alpha: _____________________

Describe help received: _________________________________________________________________

  1. [10pts] For each expression denoted below, fill in the type of the expression.

    a___________ , b ___________, c ______________, d___________ , e ___________
    int count = 0, total = 0;
    char next;
    cin >> next;
           _______________a_______________________
          /                                       \
    while((next == '0' || next == '1') && count < 8) {
           \_________/
                b               c
                               / \
      total = total*2 + next - '0';
              \__________________/
                       d
      cin >> next;
    }
    
    cout << char(total) << endl;
            \_________/
                 e
    	  
  2. [90pts] Write a program that reads in two fractions from the user and prints out the sum of the two numbers in lowest terms. Recall (from grade school!) that $$ \frac{n_1}{d_1} + \frac{n_2}{d_2} = \frac{n_1 d_2 + n_2 d_1}{d_1 d_2}. $$ and that to reduce a fraction $n/d$ to lowest terms you divide the numerator $n$ and the denominator $d$ by the greatest common divisor of $n$ and $d$. Of course, in the lecture notes we discuss greatest common divisor! A run of your program should look something like this:
    ~/$ ./fadd
    Enter a fraction addition problem: 15/28 + 7/32
    15/28 + 7/32 = 169/224
    ~/$ ./fadd
    Enter a fraction addition problem: 68/748 + 111/714
    68/748 + 111/714 = 645/2618
    
    
    Turn In a printout of your code, along with a screen capture of your program running on both of the above test inputs.