Exam 3 Topics and Practice Problems
CSSE 221 – Fundamentals of Software Development Honors
Fall 2008–2009
Exam format
HALF of this exam is closed-book, in-class, as follows:
- The exam is closed-book, closed-notes,
except that you may bring a 3x5 index card with whatever you want on it
(handwritten, typed, xeroxed, whatever, on both sides).
- The exam is designed to take less than 45 minutes,
although you will have 90 minutes to take it.
- The exam is paper-and-pencil; no computer is needed or allowed.
- This document lists at least 95%,
and perhaps 100%,
of the topics on this exam.
- The points listed for each item indicate approximately
how many points of the exam (out of 50 points) will be devoted to that topic.
HALF of this exam is OPEN-book, TAKE-HOME, as follows:
- The exam is open-book. You may use any written materials
(books, internet, DyKnow notes, whatever) you wish.
- The exam is closed mouth.
You may not discuss the exam in any way with anyone except your instructor,
until after the exam is due.
- The exam is designed to take about 2 hours,
although you may take as much as 6 hours (but NOT MORE).
You may take the exam in two segments if you wish.
- For example, you could work on the exam for 2.5 hours,
go to luch and/or do other things,
then return to work on the exam for up to 3.5 more hours.
- The exam is on-your-computer; you will implement something in C, e.g.:
- A simple ArrayList or LinkedList
- Some string processing or array processing
Exam topics and Practice problems
All the topics and questions below refer to the C programming language, unless otherwise specified.
- [5 points] C versus Java: biggest differences.
Sample problem:
-
List three of the biggest differences between C and Java.
-
What happens when the following executes in C?
In its equivalent in Java?
int x[3];
int y;
x[3] = 48;
-
What happens when the following executes in C?
Can its equivalent happen in Java?
int* x;
int y;
x = 10;
y = *x;
- [5 points] Pointers: basics.
Sample problems:
-
Declare a pointer to a float.
-
Suppose x is a pointer to a float. Print the value of x,
followed by the value of the float that x refers to.
-
Suppose that y is a char. Print the address of y.
- [5 points] Obtaining information from a function:
returning values from the function and returning information through pointer arguments.
Sample problems:
-
Explain, by giving an example, how functions "normally" return values.
Give both the function prototype and an example of the function call.
- Repeat the previous problem, this time using a void function.
- [10 points] Arrays versus pointers, and pointer arithmetic.
Sample problems:
-
Consider a function whose specification and prototype is:
// Returns the sum of the numbers in the given array.
double foo(double* arr, int arrayLength);
- Implement the function using array (bracket) notation.
- Implement the function using pointer arithmetic.
- [10 points] Dynamic allocation of arrays.
Sample problems:
-
Is the following code legal in C? Why or why not? Is its equivalent legal in Java?
void foo(int n) {
double x[n];
...
}
-
Write a statement that declares an array of floats and allocates space for 300 floats in the array.
-
Write a statement that declares a C-style string and allocates space for it to contain
up to 300 characters.
-
Write the statement that deallocates (i.e. makes available again)
the space allocated in the previous problem.
-
Explain the difference between how space is deallocated (i.e. made available again)
in C and in Java.
- [10 points] Structures.
Sample problems:
-
What is the most obvious difference between structures in C and classes in Java?
-
Write a statement that declares a structure type Car
that contains the Car's model (at most 20 characters),
year, and gasoline tank capacity (to the nearest tenth of a gallon).
-
Write statements that declares a Car variable
and gives values to its fields.
-
Write statements that declares a pointer to a Car variable,
allocates space for the variable to hold a Car,
and gives values to the Car's fields.
-
How would you change the above subproblems if you wanted to allow the Car's model
to be a string of unlimited length?
-
Consider the following code:
typedef struct {
int x;
int y;
int z;
} Point3D;
Point3D p1;
Point3D p2;
p1.x = 10;
p1.y = 20;
p1.z = 30;
p2 = p1;
Is p2 a copy of p1, or do p2 and p1 refer to the same place in memory?
What about the equivalent situation in Java?
-
Continuing the previous problem, consider the following code:
Point3D p1;
p1.x = 10;
p1.y = 20;
p1.z = 30;
foo(p1);
When execution returns after the call to foo,
is p1.x guaranteed to be 10, or might foo have changed the value of p1.x?
What about the equivalent situation in Java?
- Consider the code:
typedef struct {
float* w;
float x;
char* y;
char[10] z;
} Trio;
Trio t;
How much storage is allocated by the declaration of t?
That is, how many floats? Chars? Etc?
- [5 points] Strings.
Sample problems:
- What is the terminating character of a C-style string?
- Declare a C-style string and give it value java.
- What is the minimum number of characters that you must allocate to solve the previous problem?
- Consider the following code:
char* x = "jumbled";
char* y = x;
stringSort(y); // Sorts y, so that y becomes "bdejlmu"
Explain why the above code changes x.
Then fix the code so that x does not change (but y still becomes the sorted version of x).
Total: 50 points.