CS 2073 Engineering Programming
Topics and Review Questions for
Exam 2, Fall 2005


Date and length: Friday, 11 November 2005. The full 50-minute period: 3:00 pm - 3:50 pm.
Note: Answers to parts 1 and 2 are below. Answers to parts 3, 4, 5, and 6 are at: Additional answers


Topics: You can find these heading from the calendar under Lectures for:

You should also review your work for the programming assignments:


Sample Questions: I will pick simple questions about many of the topics from the web pages and from class. Often it will involve giving you some code and asking you to explain, modify, or complete the code. Here are sample questions.


Arrays: This is the most important topic since the first exam.

  1. Array initialization with curley brackets:

    Question: Use a for loop to add up the squares of the primes stored in the array in 2 above. Print the sum.
    Solution. (Don't access until you've tried the problem.)

  2. for loops and arrays: For loops go hand-in-hand with arrays, so I may use such an example as a loop to set all elements of an array to zero:

    Question: Here is a practice problem: Problem involving arrays.
    Solution. (Don't access until you've tried the problem.)

  3. Use of arrays as parameters: Write a main function that will:

  4. 2-dimensional arrays: Write a program that will use 2-dimensional arrays to print a 16-by-16 multiplication table. Use an array m, that is declared int m[17][17];. Use a separate function to initialize m[i][i]; to i*j. Then use another function to print the array, skipping the entries for i = 0 and for j = 0.


Pointers in C:

  1. Start with an array declared in main by:

    Pass this array and its size to a function maxmin that will calculate both the maximum and the minimum value in the array. The function should have two formal parameters max and min, each of type int  *, that is, a pointer to an integer, or the address of an integer. Use these parameters to get the maximum and minimum values back to the function main, where they should be printed. (You must pass the addresses of two ordinary integers as the actual parameters.)


macros in C:

  1. Write a macro STARS that will take i and will print i stars with no newline. (Go ahead and put a for loop and a printf or a putchar inside the macro. In standard C you'll have to declare the loop index separately, but not in C++.)