Final Exam Study Guide - Fall 2005

Wednesday, December 14, 12:30pm-2:30pm

In the following function,

bool Divisible(int Val1, int Val2) {
   if ( (Val1%Val2)==0 ) {
      return true;
   } else {
      return false;
   }
} //end Divisible()

What is the return type?  What is the function name?  What is the parameter list?

Write a function prototype for the above function.

Fill in the following function, which returns the Maximum of two integer input parameters:

____ Max ( __________________ )  {


}

What is the output of the following complete program?

#include <iostream>
#include <string>
using namespace std;

int a=10;
int b=20;

void f1(int x, int y) {
   int b=222;
   b+=10000;
   cout << "In f1, a="<<a<<endl;
   cout << "In f1, b="<<b<<endl;
   cout << "In f1, x="<<x<<endl;
   cout << "In f1, y="<<y<<endl;
} //end f1()

void main() {
   int a=111;
   f1(a, b);
   cout << "In main a="<<a<<endl;
   cout << "In main b="<<b<<endl;
} //end main()

In the program above, next to every line that references a variable, explain which variable is being used, and what its value is.

In the program above, circle the global variables.

Match the following terms and definitions

parameter   A variable that accepts a value from a function that calls it
scope   The visibility of a variable to the program
prototype   A declaration indicating the interface of a function
nested loop   A loop that has another loop defined within it.

You should become familiar with all of the examples we've done in class, which are on the web site.  Here are the links: Simple Array, Bubble Sort.cpp, and Loop Examples. Make sure you understand how these programs work.  Also, take a look at the homework you've done, and the Reading Question Quizzes we've done.

For this test does not cover any of the graphical commands.  The web page has some sample game outlines that we looked at, but that won't be on the test. (That's for the final project, to make a game).

What is the output of the following code?

  int A[] = {10, 3, -7, 14, 37, 45, -73};
  int i;
  int smallest;
  smallest=A[0];
  for (i=0; i<6; i++) {
    if (A[i]<smallest) {
      smallest=A[i];
    }
  }
  cout << "smallest = " << smallest << endl;

What is the purpose of the above code?  What's wrong, and how could you fix it?

Assume an array has been declared char S[100]; Write code to fill in the array so it becomes a string that looks like this: AbbAbb...Abb (Abb repeated 33 times).  Remember that strings end with a '\0' character.

Fill in the following function, which returns the sum of all the integers in the given array

int ArraySum(int A[], int size) {



} //end ArraySum

Write a function that takes two 10-element arrays of integers as input parameters, and returns true if they are identical, and false otherwise.  You will need to write a loop to check each element of the array.

The following section of code calculates statistics for randomly rolling two dice 1000 times.  Rewrite the code, making the necessary changes to calculate statistics for randomly rolling three dice 10000 times.

int Roll[13] = {0};
int dice1, dice2, sum, i;
for(i=1; i<=1000; i++) {
  dice1 = rand()%6+1;
  dice2 = rand()%6+1;
  sum = dice1 + dice2;
  Roll[sum]++;
} //end for(i)

If an array is declared like this: int Numbers[65]; which of the following statements are valid?

a) Numbers[0]; b) Number[-3]; c) Numbers++;
d) ++Numbers[1]; e) Numbers[1]++; f) Numbers[65];

Fill in the following if statement that determines whether the integer x is within 10 of the integer y. For example, if x is 10 and y is 18, it should say Yes, but if x is 20 and y is less than 10 or bigger than 30, it should say No.

if (       ) {
   cout << Yes, x is within 10 of y << endl;
} else {
   cout << No, x is not within 10 of y << endl;
}