CISC106, Fall 2006

First Midterm Exam (E01)

October 4, 2006

Name: ________________________________________________________________


UD Email: _____________________________________________@ udel.edu

 

Are you classified as a freshman (circle one):        YES          NO


Circle your section number:      

     010       011        012        013

     014       015        016        017

 

Do not write your name on any page except this one.

Answer the multiple choice questions on the scantron sheet.

Answer the remaining questions on this paper directly.

Total Points: ???


A hint about allocating your time:

You need to answer 100 points worth of questions in 50 minutes, so....


Multiple Choice: What is the output?

Each of the problems in this section gives you some input that is typed into MATLAB inside the box with the heavy border.

Which of the boxes afterwards with the light border represents the output you will get back?

Consider each problem as a new problem—that is, suppose that you do a clear command in between each problem.

Feel free to use the blank space on the exam sheet for scratch work.

  1. (4 pts) What is the output?

    >> x = 1:4
    1. x =
      
           1     2     3     4
      
      >>
      
    2. x =
      
           1
           2
           3
           4
      
      >> 
      
      
    3. x =
      
           4
           3
           2
           1
      
      >> 
      
    4. No output—just a new >> prompt
    5. 
      x =
      
           1     4
      
      >> 
      

  2. (4 pts) What is the output?

    Note: from this point forward, to save space, I'm showing only the result in the sample output choices—I'm leaving out the x = part, and the new MATLAB prompt (>>).
    >> x = 1:2:7;
    >> x'
    1. 1 2 7
    2. 1
      2
      7
    3. 1 3 5 7
    4. No output—just a new >> prompt
    5. 1
      3
      5
      7
      

  3. (4 pts) What is the output?

    >> x = 5:1
    1. 5 4 3 2 1
    2. 5
      4
      3
      2
      1
      
    3. 5 1
    4. An empty matrix (1 row by 0 columns)
    5. 5
  4. (4 pts) What is the output?

    >> x = [ 1 2 3; 4 5 6]
    1.  1  2  3
      4 5 6
    2. 1 2 3 4 5 6
      
    3. 29
      
    4. MATLAB would give an error message
    5. 1  4
      2 5 3 6
  5. (4 pts) What is the output?

    >> x = [1 2 3];
    >> x + 1
    1. 1 2 3 1
    2. 1
      2
      3
      1
    3. 7
    4. MATLAB would print an error message
    5. 2 3 4
  6. (4 pts) What is the output?

    >> x = 5:-1:1;
    1. 5 4 3 2 1
    2. 5
      4
      3
      2
      1
      
    3. 5 -1 1
    4. No output; just another >> prompt
    5. 5
  7. (4 pts) What is the output?

    >> x = [1 2 3];
    >> y = [4 5 6]';
    >> x * y
    1. 32
    2. 4 10 18
    3. 4
      10
      18
    4. MATLAB would print an error message
    5.   1 2 3
      4
      5
      6
  8. (4 pts) What is the output?

    >> x = [1 2; 3 4];
    >> y = [1 0; 0 1];
    >> x * y
    1. 1 0 0 4
    2. 1 2 
      3 4
    3. 1 0
      0 4
    4. MATLAB would print an error message
    5. 1
      0
      0
      4
  9. (4 pts) What is the output?
    >> x = [1 2; 3 4];
    >> y = [1 0; 0 1];
    >> x .* y
    1. 1 0 0 4
    2. 1 2 
      3 4
    3. 1 0
      0 4
    4. MATLAB would print an error message
    5. 1
      0
      0
      4
  10. (4 pts) What is the output?

    >> x = 5:-1:1
    1. 5 4 3 2 1
    2. 5
      4
      3
      2
      1
      
    3. 5 1
    4. An empty matrix (1 row by 0 columns)
    5. MATLAB would give an error message

    What is the output? (Short answer)

    For each of the questions in this section, you are given the text on a M-file named foo.m. Indicate in the blank box what the output of that M-file would be. In each case, the MATLAB prompt and the command foo to run the M-file is shown—you put in both the output, and show where the MATLAB prompt would appear.

  11. (5 pts)
    % foo.m  Donald Duck, 10/03/06
    for x=1:5;
      fprintf('o\n');
    end;
    
    >> foo
    
    
    
    
    
    
    
    
  12. (5 pts)
    % foo.m  Donald Duck, 10/03/06
    for x=1:3:5;
      fprintf('+');
    end;
    fprintf('\n');
    >> foo
    
    
    
    
    
    
    
    
  13. (5 pts)
    % foo.m  Donald Duck, 10/03/06
    for k=0:2:5;
      fprintf('k is %d\n',k);
    end;
    
    >> foo
    
    
    
    
    
    
    
    
  14. (5 pts) For this problem, assume that the file nums.dat contains the following:
    % nums.dat
    3 14
    5 9
    4 4
    9 6
    
    % foo.m  Donald Duck, 10/03/06
    load nums.dat;
    a = nums(:,1);
    b = nums(:,2);
    for k=1:length(a);
       if ( a(k) < b(k) )
         fprintf('w');
       elseif ( a(k) == b(k) )
         fprintf('d');
       else
         fprintf('l');
       end
    end;
    fprintf('\n');
      
    >> foo
    
    
    
    
    
    
    
      

    ASCII/Binary Conversion

  15. (10 pts) Using the ASCII table below, convert the binary indicated, character by character, to decode the secret message. The secret message is four characters long, all capital letters, eight bits per character.
    01010000 01001001 01001110 01000101
    A   65   J   74    S   83      
    B   66   K   75    T   84      
    C   67   L   76    U   85      
    D   68   M   77    V   86      
    E   69   N   78    W   87      
    F   70   O   79    X   88      
    G   71   P   80    Y   89      
    H   72   Q   81    Z   90      
    I   73   R   82         
     

    Writing an M-file

  16. (30 pts)

    In the space below, write a complete M-file to solve the following problem.

    The Pizza Hoot sells two kinds of pizza: round pies, and rectangular pies. A user wants to know which one is the better value, so he wants to calculate the "price per square inch" of a round pizza.

    Write an M-file that prompts the user to enter the diameter of a pizza in inches, and the price, and then outputs the price per square inch.

    Keep in mind the following:



    (Extra space in case you need it for the M-file)
    (End of Exam)