Computer Science II PUC Test December 2023
Computer Science II PUC Test December 2023
Inheritance improves software design by promoting code reusability, allowing new classes to be created based on existing classes. This results in a hierarchical class structure, where a derived class inherits properties and behaviors from a base class. Inheritance allows developers to implement polymorphism, where objects of different classes can be treated as objects of a common superclass. This leads to simpler and more manageable code, as the common behaviors can be centralized in the base class, reducing redundancy and potential errors .
Database systems offer several benefits over traditional file storage methods, including reduced data redundancy by ensuring data centralization, improved data integrity and security, as well as support for complex queries through a structured query language like SQL. Databases provide mechanisms for data normalization and ensure better management through transaction support and concurrency control, which are not inherently available in typical file systems .
A memory leak occurs when a computer program incorrectly manages memory allocations, resulting in a loss of accessible memory. It happens when the program allocates memory by using functions like `new` or `malloc` but fails to release it back to the system using `delete` or `free`. This results in prolonged memory consumption, leading to degraded system performance and, eventually, exhaustion of available memory resources. In critical systems, unchecked memory leaks can cause applications to crash or behave unpredictably, posing severe reliability issues .
Inheritance in object-oriented programming is the mechanism by which one class (derived class) is allowed to inherit the attributes and methods of another class (base class). This allows for code reuse and the creation of a hierarchical class structure. It is necessary when multiple classes share common functionality but also contain additional, unique features. For example, a 'Vehicle' class can serve as a base class containing basic functionalities like `start()` and `stop()`. Specific vehicles, like `Car` and `Boat`, can inherit from this base class and add their own specific methods, such as `honk()` for cars and `sail()` for boats .
Static memory allocation occurs at compile-time when the size of an array or a data structure is fixed and cannot be changed during the execution of the program. This means storage is allocated in the stack memory. Dynamic memory allocation, on the other hand, happens at runtime with the use of pointers, specifically using commands like `new` or `malloc`, which allocate memory from the heap, allowing the size of the allocation to be determined and changed during execution. Dynamic allocation provides greater flexibility but requires explicit handling of memory freeing to prevent leaks .
In object-oriented programming, a base class, also known as a superclass, serves as a foundation from which other classes, called derived classes, inherit properties and behaviors. The base class provides a generalized structure containing common attributes and methods that can be utilized and extended by derived classes. This relationship allows derived classes to override or extend the base class functionalities, fostering a modular and reusable design approach. In this way, common functionalities can be centralized and maintained easily, minimizing redundancy .
Text file handling involves processing data that is stored in a human-readable format, where data is typically stored as ASCII or Unicode characters with line breaks and separators clearly delineating data. Binary file handling, however, deals with data stored in a binary format, which preserves the original data structure without conversion to readable characters, allowing for more efficient storage and retrieval, particularly for complex data types or when storage space is a consideration. Binary files are more efficient for read/write operations as they eliminate the need for data conversion, but they are not directly readable by humans without translation programs .
Differentiating between a subclass and a superclass is crucial for understanding and designing class hierarchies in object-oriented programming. The superclass defines a general template with common methods and attributes, while the subclass extends or overrides this template with specific functionality, improving modularization and reducing duplication. This differentiation ensures that the software design remains flexible and adaptable; changes in the superclass propagate efficiently to all subclasses, facilitating maintenance. Furthermore, recognizing the subclass-superclass relationship helps in applying principles like polymorphism and encapsulation effectively, contributing to robust and scalable architecture .
Pointers in C++ enable dynamic memory allocation by allowing programs to request memory from the heap at runtime using operators like `new` and `malloc`. Pointers store the memory address of the allocated data, facilitating flexible memory management. However, improper handling of pointers can lead to issues such as memory leaks, when allocated memory is not freed properly, and dangling pointers, which occur when a memory address is used after the allocation has been freed. These issues can cause undefined behavior, crashes, or security vulnerabilities such as buffer overflows .
Several web hosting methods are available, each differing in features and support. Shared hosting places multiple websites on a single server, shared resources make it affordable but not very scalable. Virtual Private Server (VPS) hosting offers segmented servers acting independently for each website, providing more control and better performance than shared hosting. Dedicated hosting provides a standalone server for a single website, offering maximum control and performance, ideal for high-traffic sites. Cloud hosting utilizes a network of virtual servers, enabling scalable resources usage based on demand. Each of these methods offers different performance levels, cost implications, and scalability options .