Modular Programming Test
Back to activity index

Modular Programming Test

Fill in the form below and click the [Mail to Instructor] button to mail your answers to the instructor.

Administrative Information

Please select your group from the list:

Name of the Captain:

E-mail address of the Captain:

Name of the Recorder:

E-mail address of the Recorder:

Name of the Reflector:

E-mail address of the Reflector:


Vocabulary

Select the best answer for each question below:
  1. Function.
    1. The normal and specific contribution of a bodily part to the economy of a living organism.
    2. The purpose of a group of source statements.
    3. Some source statements grouped together.
  2. Parameter.
    1. A number shared between the called function and the calling function
    2. A number or memory location shared between the called function and the calling function
    3. A memory location shared between the called function and the calling function
  3. Return value.
    1. A number or memory location that is always given to the called function when this function is called.
    2. A number or memory location that is always given back to the calling function by the called function when it has finished its job.
    3. The amount of cash Wallmart gives you back when you return unused paint to the store.
  4. Return type.
    1. The act of pressing a plus-size key on a computer keyboard.
    2. The variable returned by a called function to the caller when the called function is done.
    3. The sort of variable that comes out of a called function.
  5. Scope.
    1. Means: in which functions a variable can be used.
    2. The mouthwash of choice of C++ programmers.
    3. The locations or functions in which a variable has been declared using a type-declaration of local or global validity and accessibility.
  6. Pass-by-value.
    1. Giving the value of a variable to a called function.
    2. Giving the storage location of a variable to a called function.
    3. Giving students a passing grade based on their lab and test performance.
  7. Pass-by-reference.
    1. Giving the value of a variable to a called function.
    2. Giving the storage location of a variable to a called function.
    3. Giving students a passing grade based on their letters of recommendation.
  8. Function prototype.
    1. A first draft of a function's source code, before being debugged.
    2. An absolutely useless line or few lines in a file that indicate roughly how some function looks. Only necessary since the compiler is too stupid to check other open windows and files in the directory for the function.
    3. A valuable part of program that defines a function header, arguments, and source code statements. It allows the function to be compiled correctly.

Critical Thinking Questions

Select the best answer:
  1. Without using global variables, what is the proper way to get information {\em into} a function from the caller?
    1. Using the return type.
    2. Using the return value.
    3. Using a parameter.
  2. Without using global variables, what are the proper two ways to get information {\em out of} a function to the caller?
    1. Using the return type or return value.
    2. Using a parameter type or return type.
    3. Using a parameter value or return value.
  3. What is produced by the following program?
        #include <iostream.h>
        void three(void) { cout << "3 "; }
        void two(void) { cout << "2 "; three(); }
        void one(void) { cout << "1 "; two(); }
        void main(void) { cout << "Counting "; one(); }
    
    1. The program will produce a compilation error.
    2. 3 2 1 Counting
    3. Counting 1 2 3
  4. What is produced by the following program?
        #include <iostream.h>
        void Jack(void);
        void John(void) { cout << "John "; Jack(); }
        void Jane(void) { cout << "Jane "; }
        void Jill(void) { cout << "Jill "; John(); }
        void Jack(void) { cout << "Jack "; Jane(); }
        void main(void) { cout << "Hi "; Jill(); cout << "!";}
    
    1. John Jack Jane Jill John Jack Jane Hi Jill!
    2. John Jane Jill Jack Hi !
    3. Hi Jack Jill Jane John !
    4. Hi Jill John Jack Jane !
  5. Why is the Jack definition done twice in the above program, and John, Jane, and Jill are not?
    1. The instructor is an idiot.
    2. This is necessary since Jack is the last function before the main function.
    3. Are you an idiot? Jack is not defined twice!
  6. What happens if you call the following function:
        void hi(void) {
          cout << "Hello\n" ;
          hi();
          }
    
    1. It comes running.
    2. It will produce a compilation error since recursion of functions is not allowed.
    3. It will keep writing Hello lines to the screen.
  7. What is produced by:
        #include <iostream.h>
        void set(void) {
          int a;
          a=1;
          }
        void main(void) {
          int a;
          a=0;
          set();
          cout << a;
          }
    
    1. It will produce a compilation error since we did not put void between the parentheses when a was called inside main.
    2. 0
    3. 1
  8. What is produced by:
        #include <iostream.h>
        int a;
        void set(void) {
          a=1;
          }
        void main(void) {
          a=0;
          set();
          cout << a;
          }
    
    1. It will produce a compilation error since declarations must be immediately behind the opening curly brackets of functions.
    2. 0
    3. 1
  9. Is the following code legal in C++? What does it produce?
        #include <iostream.h>
        void out(int houses, int horses) {
         cout << houses << " " << horses;
          }
        void main(void) {
          int boats=10, sheep=2;
          out(boats, sheep);
          }
    
    1. No, this is a syntax error.
    2. No, you must put void before out in main.
    3. No, you must put int before boats and sheep in the call to out in main.
    4. Yes, but it is lousy coding. It produces houses horses
    5. Yes, but it is lousy coding. It produces boats sheep
    6. Yes, but it is lousy coding. It produces 10 2
  10. What is produced by the following program?
        #include <iostream.h>
        void show(float a) {
          cout << a << endl;
          }
        void main(void) {
          float a=1, b=2;
          show(b);
          }
    
    1. This will produce a compilation error. The argument must be a, not b
    2. 1
    3. 2
  11. What is produced by:
        #include <iostream.h>
        void out(int a, int b) {
          cout <<  a << " " << b << endl;
          }
        void main(void) {
          int a=1, b=2;
          out(b,a);
          }
    
    1. This will produce a compilation error. The arguments are reversed.
    2. 1 2
    3. 2 1
  12. What is produced by:
        #include <iostream.h>
        int out(int a, int b) {
          cout << a << " " << b << " ";
          return a+b;
          }
        void main(void) {
          cout << "(" << out(1,2) << ")" << endl;
          }
    
    1. This will produce a compilation error. You cannot use a function in a cout statement.
    2. (1 2)
    3. (3)
    4. (1 2 3)
    5. (1 2 ) 3
    6. (a b ) 3
  13. What is produced by:
        #include <iostream.h>
        int fun(int i) {
          if (i==1) return 1;
          else return i*fun(i-1);
          }
        void main(void) {
          cout << fun(1) << " " << fun(2) << " " << fun(3) << " "
               << fun(4) << " " << fun(5) << endl;
          }
    
    1. 0 0 0 0 0
    2. 1 2 3 4 5
    3. 1 2 6 8 10
    4. 1 2 6 24 120
  14. What does the following code produce:
        #include <iostream.h>
        int ratio(int a, int b) {
          return a/b;
          }
        void main(void) {
          int a=1, b=2;
          cout << ratio(a,b) << " " << ratio(b,a);
          }
    
    1. ratio(a,b) ratio(b,a)
    2. a/b a/b
    3. 0 0
    4. 0.5 0.5
    5. 0.5 2
    6. 0 2
    7. 2 2
  15. What happens for:
        #include <iostream.h>
        void out(int i) {
          cout << i << endl;
          }
        void main(void) {
          out(1.5);
          }
    
    1. This will produce a compilation error. The argument must be an integer.
    2. It will print 1.5.
    3. The computer will stream the I/O to an h.
  16. What is produced by:
        #include <iostream.h>
        void swap(int a, int b) {
          int tmp;
          tmp=a;
          a=b;
          b=tmp;
          }
        void main(void) {
          int a=1, b=2;
          cout << a << " " << b << " --- ";
          swap(a,b);
          cout << a << " " << b << endl;
          }
    
    1. 1 2 --- 1 2
    2. 1 2 --- 2 1
    3. 1 2 --- b tmp
  17. What is produced by:
        #include <iostream.h>
        void swap(int &a, int &b) {
          int tmp;
          tmp=a;
          a=b;
          b=tmp;
          }
        void main(void) {
          int a=1, b=2;
          cout << a << " " << b << endl;
          swap(a,b);
          cout << a << " " << b << endl;
          }
    
    1. This will produce a compilation error. There is an & before the a and b.
    2. This will produce a compilation error. a and b must be reference variables in main.
    3. This will produce a compilation error. a and b must be aliases in main.
    4. 1 2 --- 1 2
    5. 1 2 --- 2 1
    6. 1 2 --- b tmp

Assessments

Give two strengths of your group:

Give two areas of improvement of your group:

Give two insights obtained about your group:


Give two strengths of the class:

Give two areas of improvement of the class:

Give two insights obtained about the class:


Submission

When all is OK, press the Mail to Instructor button. The Reset button will clear all fields.

Back to activity index