CS 2073 Engineering Programming
Topics and Review Questions for
Final Exam, Spring 2006


Date and length: Friday, 12 May 2006, 8:00 pm - 10:15 pm.
Note: Answers are at: Selected Answers.


Reviews for past exams, exams themselves, and answers:


Topics: Check out the previous reviews and the calendar for material before the second exam. Material after the second exam:

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. Note: I still need to add some questions to the list below.


if-else:

  1. Write a short if statement (no else) that will check if an int size is inside the range from 2 to 10 (inclusive) and will print "In range" if this is so.

  2. Write another short if statement (no else) that will check if an int size is not inside the range from 2 to 10 (inclusive) and will print "Out of range" if this is so.

  3. Suppose a variable temperature is supposed to be in the range from 96.0 to 100.6 inclusive. Write a short piece of C code (not an entire program or even a function) that will print the message "Temperature OK" in case the temperature is in range and will print "You are sick" in case the temperature is out of range.


functions:

  1. Write a function that will take double x and double y as input formal parameters. Then the function should return the quadrand number that the point(x, y) lies in (1-4). In case the point is on an axis, return 0. Try this out with inputs: (1, 2), (-1, 3), (3, -2), (-1, -4), (0, 5), (-3, 0), (0, 0).


Loops:

  1. Translate the following while loop to a for loop that does the same thing:

  2. Translate the following for loop to a while loop that does the same thing:

  3. Use a for loop to calculate 100000 terms of the following sum. Compare the result with pi*pi/6.0.

  4. Write a code segment that will use the following equations to approximate pi to 15 digits:

    Then replace a1 and b1 by a0 and b0, and repeat the last two equations. Keep repeating until a1 and b1 are within 1.0e-15 of one another. The final answer should be the average of a1 and b1.


Arrays:

  1. Write a C function that will take two 1-dimensional int arrays and their size as formal parameters, and will compute and return their inner product. If int a[] = {1, 2, 3}; and int b[] = {6, 7, 8};, then the inner product (a*b) is 1*6 + 2*7 + 3*8. Execute your function with the above example and with another longer example.


Input/Output:

  1. Look at the initial input/output example in: Input/output.


structs:

  1. You should especially look at the first example in: Structs and Fractions. Possible questions: I give you the definition of a struct, such as lines 2-6 in the example, and then ask you do declare several such structs (lines 12-14), how you can initialize them in two ways (line 12 and lines 15-17), how to reference fields in the structs (lines 15-17, and lines 27-29), how to pass a struct as an actual parameter (lines 20-22), and how do declare a struct as a formal parameter(line 8 and line 26).

  2. In class we covered an example that used a struct and also input/output: License Plate Example.