Computer Science II PUC Viva Questions
Computer Science II PUC Viva Questions
In C++, the main difference between struct and class revolves around access control. By default, members of a struct are public, while members of a class are private . This fundamental distinction impacts their use in programming. Structures are typically used for passive objects with public data members that are easy to access, whereas classes are used for active objects with encapsulated data, restricting direct manipulation. The choice between struct and class often depends on the level of encapsulation needed; classes provide stricter control over data and operations, supporting object-oriented principles more effectively .
Inheritance allows for the creation of new classes based on existing ones, serving as a means of establishing a hierarchical relationship between classes. It enables code reusability by allowing derived classes to inherit characteristics and behaviors of base classes, reducing redundancy . Polymorphism, on the other hand, allows objects to be treated as instances of their parent class, enabling a single interface to represent different data types or classes. This enhances maintainability by allowing code to handle new, unforeseen cases seamlessly, often through function overloading and method overriding. Both inheritance and polymorphism enable flexibility and scalability in software development, but polymorphism specifically allows for extending capabilities without altering existing code structure, thus enhancing maintainability .
A class in object-oriented programming serves as a blueprint for creating objects, encapsulating data and functions that manipulate this data, which define its characteristics and behaviors. This supports encapsulation by combining data and functions into a single entity. An object, on the other hand, is an instance of a class, representing a specific example of the data described by the class. Through encapsulation, access to the data of an object is restricted to the functions that are defined within the class, thus safeguarding the data from unauthorized access and misuse. Encapsulation and data abstraction work together to allow objects to interact with one another without needing to understand their underlying implementation, which promotes modularity and maintainability .
HTML tags are fundamental in structuring webpage content, providing hooks for styling and behavior scripts. They encapsulate content within start and end tags, defining the document's structure and applying specific semantics. For example, <p> tags structure text into paragraphs, <h1> to <h6> tags denote headings of different levels, imparting semantic meaning and facilitating navigation . Tags like <b>, <i>, and <u> apply stylistic modifications, strength, italics, and underline, respectively, representing different semantic meanings. Additionally, layout-related tags such as <table>, <tr>, <td> conceptualize tabular data, while <div> and <span> tags are used within CSS to apply styles and control layout. These tags collectively allow HTML documents to be machine-readable and human-understandable, enabling the creation of structured, accessible content .
Function overloading in C++ allows multiple functions with the same name to coexist in the same scope, differentiated by their parameter lists—different numbers or types of arguments . This feature enhances program flexibility by enabling functions to process various types of data without changing their name, simplifying the interface. For example, an overloaded function 'print' can handle int, float, or string inputs by defining it: print(int), print(float), and print(string). This reduces redundancy and, therefore, increases maintainability, allowing changes and extensions without altering the function names or interface, decreasing potential errors .
The dot operator in C++ is used to access members of an object, effectively tying together the object and the members of the class it was instantiated from . For example, if an object named 'obj' is created from a class, its members are accessed using 'obj.member'. In contrast, the scope resolution operator '::' serves a different purpose by allowing the definition of member functions outside their class definition or specifying the class to which a certain member belongs when ambiguities arise within a program's structure. This operator enhances readability and maintains organization in complex projects by clearly linking function definitions to their class declarations .
Access specifiers in C++—private, protected, and public—are essential for controlling the visibility and accessibility of class members, thereby ensuring secure and effective use of data encapsulated within classes. Private access restricts access to members so they can only be modified by functions within the same class, providing a high level of data protection. Protected members can be accessed by derived classes, offering a balance between encapsulation and inheritance utility. Public members are accessible from outside the class, necessary for defining interfaces for object interaction. These specifiers enforce data hiding and abstraction principles, ensuring that class internals are shielded from improper access and modification, which enhances security and reliability in software development .
Constructors and destructors play a pivotal role in managing the lifecycle of objects in C++. Constructors initialize objects upon creation, with different types serving specific scenarios: default constructors initialize objects with default values, parameterized constructors allow for initialization with specific values, and copy constructors create copies of existing objects . Destructors, denoted with a tilde (~), automatically manage resource cleanup when objects go out of scope, preventing memory leaks and ensuring efficient resource use . Together, they automate and streamline object initialization and destruction, crucial for robust resource management in complex applications, directly impacting performance and stability .
SQL commands in database management are critical for maintaining, querying, and securing data within databases. Data Definition Language (DDL) commands like CREATE, ALTER, and DROP manage the structure of database objects, setting up schemas as required . Data Manipulation Language (DML) commands including SELECT, INSERT, UPDATE, and DELETE allow precise data querying and modification, underpinning dynamic data interactions. Data Control Language (DCL) commands such as GRANT and REVOKE control data access and permissions, implementing security frameworks by restricting unauthorized access. Transaction Control Language (TCL) commands like COMMIT and ROLLBACK ensure data consistency and reliability during transactions, providing mechanisms to either finalize changes or revert to previous states upon errors . This multi-faceted approach to data handling boosts a database system's robustness, ensuring data integrity and security in diverse operational conditions.
Stacks and queues are fundamental data structures used to abstract various real-world scenarios and optimize computational processes. A stack functions as a Last In, First Out (LIFO) structure, ideal for scenarios where tasks must be processed in reverse order of arrival, such as undo functionalities in software . Its LIFO nature simplifies function call management through recursive calls and backtracking algorithms, minimizing overhead. A queue implements a First In, First Out (FIFO) approach, resembling scenarios like task scheduling, where the first task to enter is the first to execute . Both structures inherently simplify and enhance the efficiency of operations, leveraging minimal complexity for common procedures like insertion and deletion, optimizing both memory use and processor time .