This Comprehensive CSE 2100 Lab Quiz Practice Bank has been compiled directly from laboratory exam sheets and the refined curriculum of Lessons 1 to 8.
It covers: Fill in the Gaps, True/False, Multiple Choice (MCQs), and “Find the Error” debug drills, followed by an Unabridged Answer Key with Explanations at the bottom.
🏷️ Topic 1: Transitioning from C to C++ and Core Class Structure
The ____________ operator is used to define member functions outside the class declaration.
Functions defined directly inside a class body are implicitly treated as ____________ by the compiler.
Calling a member function from inside another member function of the same class without using the dot operator is called ____________.
✗ Section B: True / False
True or False: If an object is passed to a function by value, any modifications made to its fields inside the function will persist in main() after execution completes.
True or False: The compiler is forced to inline any function that is prefixed with the inline keyword, regardless of loops or size.
💎 Section C: Multiple Choice Questions (MCQs)
To pass an object to a function with maximum efficiency (avoiding copying overhead) while guaranteeing read-only safety, you should pass it as:
A. void print(Item obj)
B. void print(Item &obj)
C. void print(const Item &obj)
D. void print(Item *obj)
🔍 Section D: Find the Error in Code
Find the mistake in this outside member function implementation:
class Distance {private: int feet;public: void setFeet(int f);};void setFeet(int f) { feet = f;}
🏷️ Topic 3: The Lifecycle of an Object (Constructors & Destructors)
Public (Only distinction between C++ struct and class).
FALSE (Functions are allocated once in read-only code space; objects only allocate data properties).
FALSE (The extraction operator >> stops at whitespace. To read spaces, use getline(cin, str)).
C. Encapsulation (Bundling attributes and methods into one capsule).
B. Invalid operands to binary expression (Reversing << and >> on streams throws a compiler error).
Missing Semicolon: Class declarations must end with a semicolon ; following the closing brace. Fix: };
Topic 2 Answers
Scope resolution (::) (Tells the compiler which class scope a member belongs to).
Inline (Compiler replaces call sites directly to optimize pipeline).
Nesting (Calling class functions internally without object wrappers).
FALSE (Pass-by-value replicates the object on the stack; main’s original object remains untouched).
FALSE (The inline keyword is a suggestion; compilers ignore it for complex loops or recursive routines).
C. void print(const Item &obj) (Const reference prevents copying overhead while securing raw data).
Missing Scope Resolution Prefix: Defining member functions outside the class requires class membership labels. Fix: void Distance::setFeet(int f) { ... }.
Topic 3 Answers
Tilde (~) (The prefix that denotes destructor cleanup).
Copy (Initializes an object using an identical sibling instance).
new (C++ dynamic heap allocation operator).
Constructor Initializer List (Direct member assignment syntax, skipping default constructor overhead).
FALSE (Destructors take zero parameters; therefore, overloading signatures is impossible).
FALSE (Default copy constructors perform shallow copies, leading to multiple objects pointing to the same heap address).
D. No return type (Destructors have no return value—not even void).
C. Passing by value triggers infinite copy-constructor recursion (Value passing requires copying, which invokes the copy constructor… forever).
Rule of Three Violation: The code implements a custom Copy Constructor and Destructor but misses the Copy Assignment Operator (operator=). Simple assignments like s2 = s1 will trigger a shallow member copy, leading to a double-free runtime crash.
private (C++ class inheritance defaults to private; structs default to public).
Base to Derived (Parent constructor runs first to build baseline attributes).
Reverse (Destruction layers peel off backward: derived first, base last).
FALSE (Private base members are inherited but completely inaccessible inside derived classes).
TRUE (Constructors and destructors are not inherited; each class defines its own setup and teardown footprint).
C. Private (Private inheritance changes base public and protected elements to private).
B. Protected (Protected variables are inherited directly but block external main accesses).
Missing Default Base Constructor: Parent has a parameterized constructor, removing the automatic compiler-generated default constructor. Child’s default constructor will fail because it cannot implicitly call a default constructor in Parent.
C. A friend function has an implicit this pointer (Since they are not members, friends cannot access this).
Missing Friend Keyword:Box::getWidth lacks the friend prefix inside the class block.
Fix: Change declaration inside Box to: friend int getWidth(Box b);.
Topic 6 Answers
this (Implicit pointer holding the current object address).
*this by reference (ClassName&) (Enables sequential chaining of methods on the same memory block).
sizeof (Or .*, as they resolve static types or names instead of operating on dynamic values).
FALSE (You can only overload existing C++ operator symbols).
FALSE (Precedence and associativity rules cannot be altered).
B. int parameter (A dummy int parameter distinguishes post-increment from pre-increment).
B. The left-hand operand is a stream object (Streams like cout cannot invoke member functions of user classes).
Incorrect Parameter Count: When defined as a member function, the LHS is passed implicitly via this, so the member operator must take exactly one parameter.
tellg() (Returns the current read position byte offset).
<iomanip> (Header file for parameterized manipulators).
ios::in | ios::out (Bitwise OR binds read and write modes).
-15 (Negative values seek backward from the current position pointer).
FALSE (The width manipulator setw is temporary and deactivates immediately after printing the very next item).
FALSE (Relative seeks with non-zero offsets on text-mode streams result in undefined behavior due to line-ending translations. It is only safe in binary mode).
B. &&&&&&901 (setw(8) applies only to 90, padding it with 6 & characters. 1 is printed immediately next with zero padding).
C. ios::failbit (Indicates non-fatal formatting failures, such as trying to read characters into an integer).
Single Character Fill Bug:cout.fill() takes a single char parameter, not a double-quoted string literal.
Fix: Pass as a character literal: cout.fill('$');.