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


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. Use of arrays as parameters: Write a main function that will:

  2. 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++.)