This is not meant to be inclusive of all material on the final. Use the previously supplied sample exams as well.

2. (8 pts) A line of input consists of a name and height given in feet and inches. The following is an example:

John Smith 6 ft. 2 in.

  1. Define a constant to store the number of inches in a foot (12).
  2. Define appropriate variables for storing name and height. Do not initialize these variables.
  3. Give statement(s) which will read the line of input above into the variables you defined in part (b). (No need to print a prompt.)
  4. Give a statement which prints the name of the person and his height in inches.

4. ( 15 pts) Indicate the contents of x, y and z after each of the function calls below:

int one( int a, int b)
{
   a = a + 1;
   b = b + 1;
   return a * b;
}

void two( int & a, int & b)
{
   a = a * 2;
   b = b * 3;
}

int main()                 // contents of  x, y and z after each call
{                                          x      y       z
    int x = 3, y = 2, z = 1;            ---------------------

    z = one(x, y);                      _____   _____   _____

    two(y, z);                          _____   _____   _____
	return 0;
}

5. ( 8 pts) What is the output of the following program fragment?

for (j = 2; j < 7; j++)
{
    count = 0;
    for (k = 2; k < j; k++)
        if ( j % k != 0)
            count++;
    cout  << j << " " << count << endl;
}

6. (20 pts) Complete the program below by filling in the following (All parts are independent):

  1. Define an array of integers with 8 elements named Numbers.
  2. Assume the function ReadArray has been written to read from standard input correctly and store 8 values. Call this function from main( ).
  3. Write the function Over60 that counts and returns the number of values that are greater than 60 stored in the array Numbers. Call this function from main( ).
void ReadVector(int A[], int size);
int Over60 (const int A[], int size);
int main( )
{
    int count;
 // FILL IN MAIN
	return 0;
}

int Over60(const int A[], int size) 
{
    // FILL IN 
}

7. (12 pts)

  1. Complete the definitions of fin and fout in main( ) below so that fin is associated with the file datain and fout is associated with the file named dataout.
  2. Write the function Process so that it will copy only then values greater than 60 into the output file. (datain consists only of numbers) Call this function from main( ).
#include<fstream>
void Process(ifstream & in, ofstream & out);
int main( )
{
   ifstream 
   ofstream
// FILL IN
   return 0;
}

void Process(ifstream & in, ofstream & out)
{
	// complete
}

9. ( 20 pts) Consider the struct illustrated below and the datatypes of its members.

(a) Give a declaration for a struct of type Candytype appropriate for the illustrated struct.

(b) Define a variable mycandy of this type and give all necessary statements to store the illustrated data.

(c) Define an array of size 4 of these structs named CandyOrder. Assuming the data has been stored, write a program fragment that sums the total number of boxes.

10. ( 8 pts) Write an equivalent for statement for the while statement below which uses the test

const int MAX = 12;
char letters[MAX];
int j = 0;
while (j< MAX)
{
   if (letters[j] == 'A')
       letters[j] = 'a';
   j++;
}

11. ( 16 pts)

  1. What is the purpose of a function prototype?
  2. When is it appropriate to use a binary search?
  3. Explain when a function should use reference parameters.

OTHER QUESTIONS

3. (8 pts) Consider the array

 ---------------------------------------
| 4 |  9  | 11 | 16 | 18 | 22 | 25 | 32 |
 ---------------------------------------
(a) Which entries are checked during a binary search for the target 8?
(b) Which entries are checked during a linear search for the target 22?

4. (8 pts) Suppose the following vector is being sorted into ascending order:

  -----------------------------------
 | 9  |  6  |  4  |  13  |  15  | 7  |
  -----------------------------------

(a) Illustrate the contents of the array after a single pass of the SelectionSort method .

  -----------------------------------
 |    |     |     |      |      |    |
  -----------------------------------

(b) Illustrate the contents of the array after a single pass of the Insertion Sort method .

  -----------------------------------
 |    |     |     |      |      |    |
  -----------------------------------