next_inactive up previous


CISC 181 sections 010-015 (Conrad) Midterm I October 4, 2004

Name





Section (circle one, (2 pts)):
010 011 012
013 014 015

Circle one:



Freshman Sophomore Junior Senior Other




General Instructions

  1. (30 pts) Write a compete C++ program to solve the following problem, including

    • an opening comment (don't put your name in the comment! -2 pts if you do!)
    • all necessary ``stuff'' that goes before the main program
    • a full main program complete with comments

    Problem Statement: Ask the user of the program to input two positive integers. Then print a message indicating whether the larger is a multiple of the smaller one, or not. If the two numbers are the same, indicate that.

    Examples:

    input output
    9 3 9 is a multiple of 3
    7 8 8 is not a multiple of 7
    7 49 49 is a multiple of 7
    5 5 Both numbers input were 5

    Your program should provide appropriate prompts to the user, and should also label the output appropriately and neatly. Your program should also check for an error condition: if either of the numbers input is negative or zero, then print an error message, and terminate the program immediately.

    Extra space in case you need it

  2. (10 pts) One of your lab exercises involved writing functions to draw pictures using for loops. This questions tests your knowledge of that concept.

    Complete the function drawL in the program listed below.

    The function should draw a picture on standard output in the shape of the letter L of the given height and width, followed by a blank line.

    If either height or width is less than 2, the function simply draws nothing (no error message is produced, and no blank line is printed.

    The complete program appears below (with the body of function drawL omitted), with sample output on the following page. You may fill in the function in the space provided, or rewrite the complete function in the blank space on the next page (below the sample output.)

    // e02.cc  Exam question for CISC181
    // P. Conrad, 10/04/04
    
    #include <iostream>
    using namespace std;
    
    void drawL(int height, int width, char c)
    {
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    }
    
    int main(void)
    {
      drawL(2,2,'s');
      drawL(3,2,'y');
      drawL(4,3,'x');
      drawL(2,1,'a');
      drawL(3,5,'z');
      return 0; 
    }
    
    Output:
    > g++ e02.cc
    > ./a.out
    s
    ss
    
    y
    y
    yy
    
    x
    x
    x
    xxx
    
    z
    z
    zzzzz
    
    >
    

  3. Number conversions:

    1. (3 pts) Convert 73 from decimal to binary














    2. (3 pts) Convert 2A from hexadecimal to decimal














    3. (3 pts) Convert the following from binary to hexadecimal:
      1100 0001 1000 0001 0010 1111 1010 1011







    Extra space in case you need it

  4. Consider the C++ program on the following page.

    1. (8 pts) Give the output


      unit=18pt




    2. (4 pts) What are the names of the parameters in the call to the user-defined function in this program (somes these are called ``actual parameters''?)


    3. (3 pts) Circle the unary operators that appear inside the body of the user-defined function ``mysteryFunc''. Circle only the unary operators their operands.

      (If you circle the wrong thing accidentally and want to change your answer, just find some other way to indicate clearly what the unary operators are.)




    // e01.cc  Exam question for CISC181
    // P. Conrad, 10/04/04
    
    #include <iostream>
    using namespace std;
    
    
    int mysteryFunc(int x, int y)
    {
      x =  -y + x * 5;
      y--;
      cout << "x= " << x << endl;
      return y;
    }
    
    int main(void)
    {
      int a, b, c;
      a = 3; 
      b = 5;
      c = 7;
      
      cout << "a= " << a << endl;
       a = mysteryFunc(b,c);
      cout << "a= " << a ;
      cout << " b= " << b << endl;
      cout << " c= " << c << endl;
    
    }
    

  5. Consider the C++ program on the following page.

    1. (4 pts) Give the output when the input is 5


      unit=18pt




    2. (4 pts) Give the output when the input is 67


      unit=18pt




    3. (1 pts) What relational operator appears in this program?




    4. (2 pts) List two relational operators that are in C++ but do NOT appear in this program (give the C++ symbols.)




    // e03.cc  Exam question for CISC181
    // P. Conrad, 10/04/04
    
    #include <iostream>
    using namespace std;
    
    
    int main(void)
    {
      int x;
      cout << "Enter x: ";
      cin >> x;
    
      int i=1;
      while (i < x)
        {
          cout << "*";
          i *=2;
        }
      cout << endl;
    }
    

Unix Commands

(2 pts) Which of the following Unix commands creates a new directory:

Circle one:
(a) chmod (b) pwd (c) cd (d) mkdir

(2 pts) Which of the following is the directory where a web page accessed via
http://udel.edu/~jsmith/cisc181 would be stored on strauss?

Circle one:
(a) ~jsmith/public_html
(b) ~jsmith/cisc181
(c) ~jsmith/cisc181/index.html
(d) ~jsmith/public_html/cisc181

(2 pts) Which of the following would be used to change the file access permissions (e.g. to make a web directory readable by others)?

Circle one:
(a) chmod (b) pwd (c) cd (d) mkdir

Short Answer

(1 pts) What symbol is used for the stream insertion operator in C++?







(2 pts) In the C++ statement a = b + 7 * 4;
what is the left operand of the assignment operator?







(2 pts) In the C++ statement a = b + 7 * 4;
what is the right operand of the addition operator?







Multiple Choice

(1 pts) Which of the following tests whether x is equal to 10?

(a) if (x == 10) (b) if (x = 10)



(1 pts) Which of the following assigns the value of 2 times y to x?

(a)x == 2 * x; (b) 2 * y = x; (c) x = 2 x y; (d) x = 2 * y;    



(1 pts) In the expression , which part is the mantissa?

(a) (b) (c) (d)  

(1 pts) The C++ statement x = x / 2; is equivalent to which of the following statements?

(a) x /= 2; (b) x += 2; (c) x = 2; (d) x = 2 / x ;  

Working with C++ programs

Suppose you have a C++ program in a file named lab03.cpp
What Unix command do you enter to perform each of the following operations?

  1. (2 pts) Enter a text editor to make changes to the program



  2. (2 pts) Display the contents of the source code on your screen.



  3. (2 pts) Compile the program



  4. (2 pts) Copy the program to a new file called lab03b.cpp.



Total Points: 100

About this document ...

This document was generated using the LaTeX2HTML translator Version 2002-2 (1.70)

Copyright © 1993, 1994, 1995, 1996, Nikos Drakos, Computer Based Learning Unit, University of Leeds.
Copyright © 1997, 1998, 1999, Ross Moore, Mathematics Department, Macquarie University, Sydney.

The command line arguments were:
latex2html -split 0 E01_181F04.tex

The translation was initiated by Phillip Conrad on 2004-10-09


next_inactive up previous
Phillip Conrad 2004-10-09