[Univ of Cambridge] [Dept of Engineering]

C++LentWelcome

Cipolla Welcome back! Hope you enjoyed your break. This term you'll be learning more C++, but first here's a quiz so that you can see if you've forgotten anything over the holiday.
#include <iostream.h>      [0]
int num[5];                [1]
                           [2]
int triple(int num) {      [3]
  return num*3;            [4]
}                          [5]
                           [6]
int main() {               [7]
int i=4;                   [8]
cout <<triple(i)  << endl; [9]
return 0;                 [10]
}                         [11]
  1. What is num on line 1?
    an integer
    an array
    a function
  2. What is triple?
    an integer
    an array
    a function
  3. How many comments are in this code?
  4. When this is compiled and run, what is printed out?
Quiz Answers"; $unanswered=0; if ($Q1=="array"){ $correct=$correct+1; } else { if ($Q1=="") $unanswered=$unanswered+1; else echo "Q1: Look back at the code, especially line 1. The C++ summary might help.
"; } if ($Q2=="function") $correct=$correct+1; else{ if ($Q2=="") $unanswered=$unanswered+1; else { echo "Q2: The C++ summary might be useful if you're unsure about integers, arrays and functions.
"; if ($Q2==int) echo "triple isn't an integer itself. It's a kind of mini-program that given an integer calculates a new one.
"; } } if ($Q3=="0" || $Q3=="none" || $Q3=="zero" ) $correct=$correct+1; else{ if ($Q3=="") $unanswered=$unanswered+1; else echo "Q3: It's worth checking in the C++ summary to see what comments are!
"; } if ($Q4=="12") $correct=$correct+1; else{ if ($Q4=="") $unanswered=$unanswered+1; else echo "Q4: You could try copying the code into an editor and compiling it.
"; } echo "You have $correct out of 4 correct. "; if ($unanswered==1) echo "You haven't answered a question."; if ($unanswered>1) echo "You haven't answered $unanswered questions."; if ($correct==4) echo "Well Done! "; else { echo "You may find the following links useful -
"; echo "* C++ Summary index
"; echo "*Introduction for New Users"; } } ?>
[1A C++] [Help]

Updated December 2000
tpl@eng.cam.ac.uk