Docsity

Object-Oriented Programming in CS106B: Classes, Objects, and Design UPDATED ACTUAL Exam Qu, Exams of Object Oriented Analysis and Design

Toggle sidebar
bg1
Object-Oriented Programming in
CS106B: Classes, Objects, and
Design UPDATED ACTUAL Exam
Questions and CORRECT
Answers 2026/2027 edition
What is the focus of object-oriented programming (OOP)?
OOP focuses on classes and objects, allowing us to package data with
functions that operate on that data.
What marks the transition in CS106B from ADTs to OOP?
The transition involves examining implementation details and creating
ADTs in C++.
What is a class in object-oriented programming?
A class is a blueprint that defines a new datatype, packaging related
data and functions.
What are instances in the context of classes?
Instances are specific objects created from a class, each having its own
unique state.
How does OOP differ from non-object-oriented programming like C?
OOP unifies data and functionality within classes, whereas non-OOP
keeps them separate.
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff

Partial preview of the text

Download Object-Oriented Programming in CS106B: Classes, Objects, and Design UPDATED ACTUAL Exam Qu and more Exams Object Oriented Analysis and Design in PDF only on Docsity!

Object-Oriented Programming in

CS106B: Classes, Objects, and

Design UPDATED ACTUAL Exam

Questions and CORRECT

Answers 2026/2027 edition

What is the focus of object-oriented programming (OOP)? OOP focuses on classes and objects, allowing us to package data with functions that operate on that data. What marks the transition in CS106B from ADTs to OOP? The transition involves examining implementation details and creating ADTs in C++. What is a class in object-oriented programming? A class is a blueprint that defines a new datatype, packaging related data and functions. What are instances in the context of classes? Instances are specific objects created from a class, each having its own unique state. How does OOP differ from non-object-oriented programming like C? OOP unifies data and functionality within classes, whereas non-OOP keeps them separate.

What is the significance of constructor functions in a class? Constructor functions initialize new objects of a class when they are created. What role do private class members play? Private class members restrict access to the data, ensuring encapsulation. What are getters and setters in OOP? Getters and setters are methods used to access and modify private class members. What is the purpose of overloading constructor functions? Overloading allows multiple constructors with different parameters to create objects in various ways. What is a destructor function in a class? A destructor function is called when an object is destroyed, allowing for cleanup of resources. What is the purpose of the Quokka class in the course? The Quokka class serves as a practical example for students to apply OOP concepts. What is the relationship between classes and data types in C++? Classes define new data types, allowing variables to be declared as instances of those classes. How does the concept of abstraction relate to classes? Classes allow for abstraction by encapsulating data and functionality, simplifying complex systems.

What is the role of the 'main' function in C++? The 'main' function serves as the entry point for program execution in C++. How do vectors function as classes in C++? Vectors encapsulate a collection of elements and provide functions for manipulation, like add() and remove(). What is the significance of the 'using namespace std;' directive? It allows the use of standard library features without prefixing them with 'std::'. What is the difference between a class and an object? A class is a blueprint for creating objects, while an object is an instance of a class. What is the importance of understanding OOP for programmers? Understanding OOP enhances code clarity, organization, and the ability to solve complex problems. What is the main advantage of using a stack abstraction over a vector approach? The stack abstraction simplifies operations by abstracting away the details of insertion and deletion. What C++ header files are included for using stack and vector? #include , #include "console.h", #include "stack.h" for stack; #include , #include "console.h", #include "vector.h" for vector. What does the 'push' operation do in a stack? It adds an element to the top of the stack.

What does the 'pop' operation do in a stack? It removes and returns the top element of the stack. What is the output of 'cout << s.pop() << endl;' in the stack example? It outputs the last element added to the stack, which is 15. What is the purpose of the interface in a class? The interface defines what data and functions are accessible from outside the class. What is the purpose of the implementation in a class? The implementation contains the actual definitions of the functions that provide the class's behavior. What file extension is used for a class's header file in C++? .h What file extension is used for a class's implementation file in C++? .cpp What are include guards in a header file? Include guards prevent multiple inclusions of the same header file, typically using #ifndef and #define directives. What does the 'public:' section in a class definition indicate? It indicates the members and functions that are accessible to users of the class. What does the 'private:' section in a class definition indicate? It indicates the members and functions that are not accessible to users of the class.

What is the purpose of the 'cout' statement in the examples? It is used to output data to the console. What is the significance of the 'Quokka::Quokka()' line in the implementation file? It defines the constructor for the Quokka class, allowing for initialization when an object is created. What is the difference between a functional prototype and a function definition? A functional prototype declares the function's signature, while a function definition provides the actual code. What is the output of 'cout << "Stack contents: " << s;'? It outputs the current contents of the stack. What does 'v.size()' return in the vector example? It returns the number of elements currently stored in the vector. What is the purpose of the 'return 0;' statement in the main function? It indicates that the program has completed successfully. What does the Quokka class represent? A class that models a Quokka with member variables and functions. What are member functions in the Quokka class? Functions that govern behaviors an object can perform, such as Quokka() constructor, haveASnack(), and printInfo().

What are member variables in the Quokka class? Variables that govern the state of an object, such as _name, _howAdorable, and _location. What is the purpose of the constructor in the Quokka class? To initialize a new instance of the Quokka class. What does the printInfo() function do? It outputs the Quokka's name, adorableness score, and location. What is the significance of the Quokka:: prefix in function definitions? It indicates that the function belongs to the Quokka class. What happens if quokka.h is not included in main.cpp? The compiler would not recognize the Quokka class, leading to a compilation error. What is an overloaded constructor in the Quokka class? A constructor that takes parameters to initialize member variables, making object creation more efficient. What does the _location member variable default to in the Quokka class? Australia, as Quokkas are native to that location. What are instance variables? Variables that are unique to each instance of a class. What is the purpose of making class members private? To prevent misuse that could leave an object in a broken state. How do you access member variables of a Quokka object?

It displays the information of both Quokka objects created. What is the purpose of the std::string type in the Quokka class? To define member variables that hold string data, such as names and locations. What is the significance of the comment about IDEs displaying callable functions? It highlights the ease of using object-oriented programming by showing available methods for an object. What does it mean when a function's name matches the class name? It indicates that the function is a constructor for that class. Why is it considered best practice to avoid using namespace std; in header files? To prevent namespace pollution and maintain clarity in code. What does the overloaded constructor in quokka.h require as parameters? It requires a name, an adorableness score, and a profile picture filename. What is the benefit of using constructors with parameters? They simplify the object creation process by allowing initialization in one line. What happens if a client directly modifies the size of a vector? It can lead to a broken state where the vector's size does not reflect the actual number of elements. What is a getter function?

A function that returns the value of a private member variable. What is a setter function? A function that changes the value of a private member variable, often with restrictions. How do you typically name getter and setter functions? Getter functions often start with 'get' and setter functions with 'set', followed by the variable name. What is the significance of the size() function in a vector class? It allows clients to retrieve the size of the vector without modifying it directly. What is a constructor in C++? A special function that initializes an object when it is created. What is a destructor in C++? A special function that is called when an object goes out of scope, used to free resources. What does the tilde (~) signify in a destructor's name? It indicates that the function is a destructor. What happens to local variables when a function returns in C++? They are destroyed and their memory is marked as unused. What is the purpose of the Lexicon class in the Quokka example? To check for bad words in the name being set for a Quokka object. What is the output when a bad word is detected in the Quokka name? An error message indicating the name contains a bad word.

A situation where an object's internal state is inconsistent or invalid due to improper modifications. What is the significance of the 'bad_words.txt' file in the Quokka example? It contains words that are not allowed in Quokka names, used for validation. What does the 'cout' statement do in C++? It outputs text to the console. What is the purpose of the 'using namespace std;' directive? To avoid prefixing standard library names with 'std::'. What is the purpose of the Quokka class? To represent a quokka with attributes like name, adorability, location, and profile picture. What are the member variables of the Quokka class? The member variables are _name, _howAdorable, _location, and _profilePic. What does the constructor Quokka(std::string name, int howAdorable, std::string profilePic) initialize? It initializes the quokka's name, how adorable it is, and its profile picture, setting the location to Australia. What is the function of the destructor in the Quokka class? The destructor prints a message indicating that the quokka is being deconstructed. What does the printInfo() method do?

It prints the quokka's name, adorability, and location. How does the setName() method ensure the name is appropriate? It checks the name against a list of bad words and raises an error if any are found. What does the howAdorable() method return? It returns the adorability rating of the quokka, which is an integer from 1 to 5. What is the default location set for all Quokka objects? Australia. What does the renderProfile() method do? It calls the renderGeocitiesPage function, passing the current Quokka object using 'this'. What is the purpose of the main() function in the provided code? To create a vector of Quokka objects and call their printInfo() or renderProfile() methods. What happens when a Quokka object is added to the vector? A copy of the Quokka object is created, which may lead to multiple deconstructions if not managed properly. What does the location() method return? It returns the location of the quokka, which is set to Australia. What is the significance of the 'this' keyword in the Quokka class? It refers to the current instance of the Quokka object within its member functions.

'Muffinface (how adorable: 5, loc: Australia)' What additional functionality can be added to the Quokka class as per the exercises? Implement more member functions, additional member variables, and ensure proper encapsulation. What is the purpose of the 'error' function in setName()? To signal an error condition when an inappropriate name is detected. How does the Quokka class demonstrate object-oriented programming principles? It encapsulates data and behavior, uses constructors and destructors, and manages object lifecycles.