








Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!









CSE 232 S’11 Last name (printed): ________________________________
Sample Exam #2 First name (printed): ________________________________
Form 2 X
Directions:
a. DO NOT OPEN YOUR EXAM BOOKLET UNTIL YOU HAVE BEEN TOLD TO BEGIN.
b. This exam booklet contains 30 questions, each of which will be weighted equally.
c. You may use one 8.5" x 11" note sheet during the exam. No other reference materials or calculating devices may be used during the examination.
d. Questions will not be interpreted during the examination.
e. You should choose the single best alternative for each question, even if you believe that a question is ambiguous or contains a typographic error.
f. Please fill in the requested information at the top of this exam booklet.
g. Use a #2 pencil to encode any information on the OMR form.
h. Please encode the following on the OMR form:
-- Last name and first initial -- MSU PID -- Exam form (2 X)
i. Please sign the OMR form.
j. Only answers recorded on your OMR form will be counted for credit. Completely erase any responses on the OMR form that you wish to delete.
k. You must turn in this exam booklet and the OMR form when you have completed the exam. When leaving, please be courteous to those still taking the exam.
A) Temperature P(X); B) Temperature Q[100]; C) Temperature * R = new Temperature[50]; D) All of the above. E) None of the above.
A) Z = Temperature( Y.Degrees, Y.Scale ); B) Z = Y += 10.0; C) Z = 5.0 + X; D) All of the above. E) None of the above.
A) Temperature::Temperature( double D, char S ) { return *this; }
B) void Temperature( double D, char S ) { return *this; }
C) Temperature::Temperature( double D = 0.0, char S = ’C’ ) {}
D) void Temperature( double D, char S ) { return 0; }
E) None of the above.
A) Temperature& operator+=( double D ) { return D; }
B) Temperature& Temperature::operator+=( double D ) { return *D; }
C) Temperature& Temperature::operator+=( double D ) { return *this; }
D) Temperature::operator+=( double D ) { return this; }
E) None of the above.
A) Temperature Temperature::operator+( const Temperature& T, double D ) { return T; }
B) Temperature operator+( const Temperature& T, double D ) { return T; }
C) Temperature Temperature::operator+( const Temperature& T, double D ) { return; }
D) Temperature operator+( const Temperature& T, double D ) { return; }
E) None of the above.
A) Fixed capacity and contiguous storage allocation B) Fixed capacity and non-contiguous storage allocation C) Variable capacity and contiguous storage allocation D) Variable capacity and non-contiguous storage allocation E) None of the above.
A) It uses neither a dummy header node nor a dummy trailer node. B) It uses a dummy header node, but not a dummy trailer node. C) It uses a dummy trailer node, but not a dummy header node. D) It uses a dummy header node and a dummy trailer node. E) None of the above.
A) The default constructor is O(N) and the destructor is O(N). B) The default constructor is O(N) and the destructor is O(1). C) The default constructor is O(1) and the destructor is O(N). D) The default constructor is O(1) and the destructor is O(1). E) None of the above.
A) Function "size" is O(N) and function "is_present" is O(N). B) Function "size" is O(N) and function "is_present" is O(1). C) Function "size" is O(1) and function "is_present" is O(N). D) Function "size" is O(1) and function "is_present" is O(1). E) None of the above.
A) Function "insert" is O(N) and function "remove" is O(N). B) Function "insert" is O(N) and function "remove" is O(1). C) Function "insert" is O(1) and function "remove" is O(N). D) Function "insert" is O(1) and function "remove" is O(1). E) None of the above.
A) delete Temp2; Temp2 = Temp1; Temp1 = Temp2->Link;
B) Temp1 = Temp2; Temp2 = Temp2->Link; delete Temp1;
C) Temp2 = Temp1; delete Temp2; Temp1 = Temp1->Link;
D) All of the above.
E) None of the above.
A) Temp = Mem; Temp->Item = X; Temp->Link = Mem;
B) Mem = Temp; Mem->Item = X; Mem->Link = Temp;
C) Temp->Item = X; Temp->Link = Mem; Mem = Temp;
D) All of the above.
E) None of the above.
A) if (Mem == Prev) Mem->Link = Curr->Link; else Mem = Curr->Link;
B) if (Curr == Mem) Mem = Curr->Link; else Prev->Link = Curr->Link;
C) if (Curr != Mem) Curr = Curr->Link; else Mem = Prev->Link;
D) All of the above.
E) None of the above.
A) if (Room > Used) { Pool[Used] = X; Used++; }
B) if (Used < Room) { Used++; Pool[Used] = X; }
C) if (Used != Room) { Pool[Used] = X; }
D) All of the above.
E) None of the above.
A) while ((Pool[Curr] == X) || Curr < Used) { Curr++; }
B) while (Curr < Used || (Pool[Curr] == X)) { Curr++; }
C) while (Curr < Used || (Pool[Curr] <= X)) { Curr++; }
D) All of the above.
E) None of the above.
A) for (unsigned J=0; J
##############
A collection of floating point values is to be processed using ADT Stack. The number of records (N) will never exceed MAX. Two implementations have been proposed:
Implementation #1 uses a dynamically allocated array of MAX records.
Implementation #2 uses a singly-linked linear chain of dynamically allocated nodes, where each node contains one value.
Both implementations use the most appropriate algorithms and are implemented correctly.
A) Create is O(1) and Push is O(1). B) Create is O(1) and Push is O(N). C) Create is O(N) and Push is O(1). D) Create is O(N) and Push is O(N). E) None of the above.
A) Destroy is O(1) and Pop is O(1). B) Destroy is O(1) and Pop is O(N). C) Destroy is O(N) and Pop is O(1). D) Destroy is O(N) and Pop is O(N). E) None of the above.
A) Implementation #1 will use less memory for the stack. B) Implementation #1 will use less time to push an item into the stack. C) Implementation #1 will use less time to destroy the stack. D) All of the above. E) None of the above.
Figure 2 ******************************************************************************/
using namespace std; #include
class Rectangle { public:
Rectangle( double = 0.0, double = 0.0 );
friend ostream& operator<<( ostream&, const Rectangle& );
private:
double length, width; };
Rectangle A, B( A ), C = B; // Line 1
Rectangle * D, E, F( 12.5, 5.2 ); // Line 2
void display( Rectangle X, Rectangle& Y ) { cout << X << endl << Y << endl; }
Rectangle process( const Rectangle& X, const Rectangle& Y ) { Rectangle Z[3]; // Line 3
Z[0] = 17.5; // Line 4
D = new Rectangle; // Line 5
return Z[0]; // Line 6 }
int main() { Rectangle P, Q( 20.0, 2.5 );
A = process( P, Q );
E = Q; // Line 7
display( P, Q ); // Line 8
delete D; }
Figure 3 -- Interface file for class "Group" (file "group.h")
Class "Group" represents a unordered collection of items which does not allow multiple occurrences of a given item. ******************************************************************************/
typedef int EType;
using namespace std; #include
class Group { private:
struct Node { EType Item; Node * Link; };
Node * Mem;
public:
// Initialize group to empty // Group() { Mem = NULL; }
// De-initialize group // ~Group() { reset(); }
// Re-initialize group to empty // void reset();
// Initialize group using existing group // Group( const Group& Source );
// Assign into group from other group // Group& operator=( const Group& Source );
// Return number of items in group // unsigned size() const;
// Test for presence of specified item in group // bool is_present( const EType& X ) const;
// Insert specified item into group, if possible // bool insert( const EType& X );
// Remove specified item from group, if possible // bool remove( const EType& X ); };
Figure 5 -- Interface file for class "String" (file "string.h") ******************************************************************************/
using namespace std; #include
class String { public:
// Initialize empty string // String() { Pool = NULL; Room = Used = 0; }
// De-initialize string // ~String();
// Initialize string by copying existing string // String( const String& );
// Return string length // unsigned length() const { return Used; }
// Assign into string by copying existing string // String& operator=( const String& );
// Append character to current string // String& operator+=( char );
// Return reference to element I // char& operator[]( unsigned I );
// Return constant reference to element I // const char& operator[]( unsigned I ) const;
// Return true if character is present in string // bool is_present( char ) const;
private:
char * Pool; // Pointer to memory to hold characters unsigned Room; // Number of bytes currently allocated unsigned Used; // Number of bytes currently used
// Get more memory, if possible // void reallocate(); };
// Compare two strings (equality operators) // bool operator==( const String& One, const String& Two ); bool operator!=( const String& One, const String& Two );
Figure 6 -- Implementation file for class "String" (file "string.cpp") ******************************************************************************/
#include "string.h" // From Figure 5
String& String::operator+=( char X ) { if (Used == Room) { reallocate(); }
// ***** missing code *****
return *this; }
bool String::is_present( char X ) const { bool Result = false; unsigned Curr = 0;
// ***** missing code *****
if (Curr < Used) { Result = true; }
return Result; }
void String::reallocate() { const unsigned Inc = 16;
char * Temp = new (nothrow) char[Room+Inc]; if (Temp != NULL) { // ***** missing code *****
Room = Room + Inc; } }