|
|
|
Mid-Term Exam, Friday, Nov. 02, 2001, 12:00-12:50 PM
FRANZ 1260
Instructor: Prof. Ivo D. Dinov
TAs: Katie Tranbarger & Scott Spicer
URL:: http://www.stat.ucla.edu/~dinov/
1.Explain the difference between:
2.Describe the functions strlen, strcat, strcpy and strcmp. Give
3.Assume this code fragment is embedded in a complete, correct program. What is the output from this code fragment?
int array[4][4];
int index1, index2;
for (index1 = 0; index1 < 4; index1++)
for (index2 = 0; index2 < 4; index2++)
array[index1][index2] = index2*index1;
for (index1 = 0; index1 < 4; index1++)
{
for (index2 = 0; index2 < 4; index2++)
cout << array[index1][index2]
<< " ";
cout << endl;
}
4. Write a complete program which declare an array of 4 String
objects named list. Prompt the user for and accept 4 names, one
per line, from the standard input. Order the strings in lexicographical
order and report the ordered list of 4 strings. [Hint: use a single
pointer to a string object and initialize it to contain 4 objects, then
use the standard comparison functions (< and >) to properly order the
4 strings.]
5. Explain the definition of the multi-dimensional array int
myIntArray3D[10][15][20]; Order the indices fast-to-slow, elaborate
on the very definition of a 3D array - its meaning. If the address of the
first element is in memory location 10,000, compute the starting
location for the element myIntArray3D[3][5][10].
6. Let p1 and p2 be two pointers to double type objects and v1 and v2 be two double variables.
7. Again p1 and p2 are two pointers to double type objects and A is a 1D array of doubles.
8. For the interface of the StringVar class we discussed in lecture write the body definition of the assignment overloading operator (=), void StringVar::operator= ( const StringVar & rhs ). Remember, you need to nullify previous assignments of the left-hand-side, then make room for a new c-string object and assign to it the value of the right-hand-side, rhs.
class StringVar
{
public:
StringVar(int size);
StringVar( );
StringVar(const char a[ ]);
StringVar(const StringVar& string_object);
~StringVar( );
int length( ) const;
void input_line(istream& ins);
friend ostream& operator <<(ostream& outs, const StringVar& the_string);
private:
char *value;
int max_length;
};
9. Write a recursive (on the left side) and an equivalent
regular (loop-based) function (on the right side), which print out on the
std::out the string PIC10B, N times, where both functions
take in an integer argument (N).
10. Fill in the blanks in each of the following sentences.
11.State whether each of the following is true or false. If false, explain why.