{"id":18862827,"url":"https://github.com/anshsinghsonkhia/oopm-3rd-sem","last_synced_at":"2026-02-10T16:30:15.738Z","repository":{"id":221015958,"uuid":"752926035","full_name":"AnshSinghSonkhia/OOPM-3rd-Sem","owner":"AnshSinghSonkhia","description":"OOPS \u0026 OOPM Syllabus for B.Tech in C++","archived":false,"fork":false,"pushed_at":"2024-02-07T07:22:54.000Z","size":55,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-12-30T21:16:44.823Z","etag":null,"topics":["cpp","object-oriented-programming","oop","oop-principles","oops","oops-in-cpp"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AnshSinghSonkhia.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-02-05T05:46:21.000Z","updated_at":"2024-03-02T16:29:58.000Z","dependencies_parsed_at":"2024-11-08T04:36:20.214Z","dependency_job_id":"aeed8e3a-d562-42be-a167-4f09004a9fcf","html_url":"https://github.com/AnshSinghSonkhia/OOPM-3rd-Sem","commit_stats":null,"previous_names":["anshsinghsonkhia/oopm-3rd-sem"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AnshSinghSonkhia%2FOOPM-3rd-Sem","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AnshSinghSonkhia%2FOOPM-3rd-Sem/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AnshSinghSonkhia%2FOOPM-3rd-Sem/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AnshSinghSonkhia%2FOOPM-3rd-Sem/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AnshSinghSonkhia","download_url":"https://codeload.github.com/AnshSinghSonkhia/OOPM-3rd-Sem/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239808147,"owners_count":19700440,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cpp","object-oriented-programming","oop","oop-principles","oops","oops-in-cpp"],"created_at":"2024-11-08T04:35:51.750Z","updated_at":"2026-02-10T16:30:15.706Z","avatar_url":"https://github.com/AnshSinghSonkhia.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Procedure Oriented Programming\nC, COBOL, FORTRAN\n\nStep by step procedures or algorithms\n\n- POP follows Top-down approach in program design.\n\n## Problems in POP \n- Global Data: accessible from entire program.\n- difficult to track which function changed the data.\n- If data structure is changed, functions are to be revised.\n\n# Object Oriented Programming\n\n\nIt focuses on data rather than the procedure.\n\n- We bind the data to the function using it\n\n- Program is divided into OBJECTS, i.e. data and functions.\n\n- Data is hidden \u0026 can NOT be accessed by external functions\n\n- OOP follows Bottoms-up approach in program design.\n\n- It protects data from accidental changes.\n\n# What is Class?\n\nThe fundamental unit of OOP\n- It is a User-defined data type.\n\n- Class can have its properties and its functions\n- It is a blueprint of objects\n\nFor example: Class - `Fruit`\n    `Mango`\n    `Apple`\n    `Grapes`\n\n# What are Objects?\n\nObjects are variables of type `class`\n\nMango, Apple, Grapes are objects of class - Fruit\n\n- All objects of a class has its properties and functions.\n\n# Constructors\n\nare used to initialise an object.\n\n- This is a function, which is called when an object is created.\n\n- This will have the same name as class name.\n\n- 1 Class can have multiple constructors.\n\n## Types of Constructors\n\n1. Default Constructor - NO Arguments are passed.\n\n2. Parametrized Constructor - Arguments are passed.\n\n3. Copy Constructor - Used When we want to initialise an object based on another object.\n\n# Destructor\n\nThis function is called when the object is deleted.\n\n- Can NOT pass any parameters\n\n```cpp\n~Rectangle(){\n    cout\u003c\u003c\"Destructor is called\";\n}\n```\n\n# Encapsulation\n\n- It ensures Binding of methods and variables together into a single unit, i.e., `Class`.\n\n- It is a property of OOPS.\n\n- Data is only accessible from the class methods (function)\n\n- It leads to Data Abstraction / Hiding.\n    - Due to which, `Class` is known as an `Abstract Data type`.\n\n# Abstraction \n\n- Property of OOP\n\n- It enables us to display only essential information, while hiding the implementation details.\n\nExample: The implement details of `pow(x,y)` function is hidden to us. We may not know how it is calculating the powers, but we can use it.\n\n## Types of Abstraction:\n### 1. Data abstraction\nThis type only shows the required information about the data and hides the unnecessary data.\n### 2. Control Abstraction\nThis type only shows the required information about the implementation and hides unnecessary information.\n\n# Inheritance\n\n- A class inherits properties of another class.\n\n`Parent Class (Super Class) ----\u003e Child Class (Sub Class)`\n\n- Once a property is defined in a parent class, you won't need to repeat that code for other inherited classes.\n\n- So, Inheritance brings `Code Reusability`\n\n# Access Specifiers \u0026 Modes of Inheritance\n\u003e Used for Data Members \u0026 Member Functions in Class\n\n1. Public\n    - Data Members \u0026 Member Functions can be accessed from `anywhere` in the code.\n\n2. Protected\n    - Data Members \u0026 Member Functions can only be accessed from its `own class`, `parent class` \u0026 `derived class`.\n\n3. Private\n    - Data Members \u0026 Member Functions can only be accessed from its `own class`.\n\n## Access Specifiers - Public, Protected, Private\n\n```cpp\nclass Parent{\n    public:\n        int x;\n    \n    protected:\n        int y;\n        \n    private:\n        int z;\n};\n```\n\n## Modes of Inheritance - Public, Protected, Private\n\n```cpp\nclass Child1: public Parent {\n    // x will remain public\n    // y will remain protected\n    // z will NOT be accessible\n};\n\nclass Child2: private Parent {\n    // x will become private\n    // y will become private\n    // z will NOT be accessible\n};\n\nclass Child2: protected Parent {\n    // x will become protected\n    // y will become protected\n    // z will NOT be accessible\n};\n```\n\n# Types of Inheritance\n\n### 1. Single Inheritance\n`A --\u003e B`\n\n-  A derived class inherits directly from one Parent class (or Base Class)\n\n\u003e Think of it like a child inheriting traits from one parent. The child gets both unique and shared features.\n\n- Maintains a clear hierarchy.\n\n### 2. Multi-level Inheritance\n`A --\u003e B --\u003e C`\n\n- A derived class inherits from another derived class, forming a chain of inheritance\n\n\u003e This is like a grandchild inheriting from their parent (who inherited from a grandparent). Each generation builds on the previous one, gaining more specialized skills.\n\n### 3. Multiple Inheritance\n`A --\u003e C \u003c-- B`\n\n- A derived class inherits from multiple parent classes.\n\n- Potentially combining their features but increasing complexity and requiring careful management of ambiguities.\n\n\u003e Imagine a child inheriting from two parents, like having skills from both mom and dad (e.g., programming and music). It can be powerful, but managing who gets what can be tricky.\n\n### 4. Hierarchical Inheritance\n`A --\u003e B`, `A--\u003e C`\n\n- Multiple derived classes inherit from a Parent base class.\n\n- creating a branching hierarchy where each derived class focuses on a distinct aspect of the parent class's functionality.\n\n\u003e Picture siblings, each inheriting from the same parent but developing in different directions (e.g., one becomes a doctor, the other an engineer). They share some traits but specialize in different areas.\n\n### 5. Hybrid Inheritance\n\n- Combination of more than one inheritance type\n\n- For Example:\n    - `A --\u003e B`\n    - `A --\u003e C`\n    - `C --\u003e D`\n    - `B --\u003e F`\n\n- A derived class combines multiple inheritance (from more than one base class) and multilevel inheritance (inheriting from a derived class), leading to a complex inheritance structure that requires careful design and attention to potential conflicts.\n\n\u003e This is like having a complex family tree, combining multiple parents and grandparents. It can be flexible, but keeping track of who gets what can be confusing\n\n\n# Polymorphism\n\nPolymorphism is the ability of objects / methods to take different forms with the same name (or Word).\n\n## 2 Types of Polymorphism\n1. Compile Time Polymorphism\n2. Run Time Polymorphism\n\n# 1. Compile Time Polymorphism\n\n- resolved at Compile-time\n- this is performed using `Function Overloading` \u0026 `Operator Overloading`\n\n-  Multiple methods with same name but different signatures, chosen by the compiler based on parameters. (e.g., function overloading)\n\n\u003e The compiler decides which function to use based on what information you give it.\n\n## Function Overloading\n\u003e works at compile-time polymorphism\n\n- Defining a number of functions with the SAME Function `Name`.\n- But, they perform differently, acc. to the `Arguments` passed.\n\n### This Decision of which function will be called, acc. to Arguments is based on:\n\n- `Number` of Arguments Passed.\n- `Type` of Argument Passed.\n\n### For Example:\n\nTo calculate the area of `Circle`, `Sqaure`, or `Triangle`, we can define functions with the same name, but different types of arguments.\n\n## Operator Overloading\n\u003e works at compile-time polymorphism\n\n- Addition: `2 + 3 = 5`\n- Concatination: `\"cat\" + \"woman\" = \"catwoman\"`\n\n### Question: How to add 2 complex numbers using operator overloading?\n\n# 2. Run Time Polymorphism\n\n- resolved at Run-time\n- this is performed using `Function Overriding`\n\n- Same method name in subclasses with different implementations, chosen dynamically based on object type. (e.g., method overriding)\n\n\u003e The program figures out which function to use based on the actual data it's working with.\n\n## Function Overriding\n\n`https://www.geeksforgeeks.org/function-overriding-in-cpp/`\n\n- When a Child class defines a function of parent class.\n    - `Same function` in both `Parent class` \u0026 `child class`\n\n\u003e  Function overriding in C++ is termed as the redefinition of base class function in its derived class with the same signature i.e. return type and parameters.\n\n\u003e It falls under the category of Runtime Polymorphism.\n\n### Use of `virtual` keyword to decide at runtime, about which function to use for `function overriding`\n\n```cpp\nclass Parent{\n    public:\n        virtual void print(){\n            cout \u003c\u003c \"Parent Class print\" \u003c\u003c endl;\n        }\n        void show(){\n            cout \u003c\u003c \"Parent Class shown\" \u003c\u003c endl;\n        }\n        \n};\n\nclass Child: public Parent{\n    public:\n        void print(){\n            cout \u003c\u003c \"Child Class print\" \u003c\u003c endl;\n        }\n        void show(){\n            cout \u003c\u003c \"Child Class shown\" \u003c\u003c endl;\n        }\n};\n\nint main() {\n    \n    Parent *p;\n    Child c;\n    \n    p = \u0026c;\n    p -\u003e print();\n    p -\u003e show();\n    \n    return 0;\n}\n\n// OUTPUT\n// Child Class print\n// Parent Class shown\n```\n\n### So, which function will be called in case of overriding?\n\n- The one nearest, will be called.\n\n# Function Overloading Vs Function Overriding\n\n| Function Overloading | Function Overriding |\n| ------- | ------- |\n| It falls under Compile-Time polymorphism\t| It falls under Runtime Polymorphism |\n| A function can be overloaded multiple times as it is resolved at Compile time\t| A function cannot be overridden multiple times as it is resolved at Run time |\n| Can be executed without inheritance  |\tCannot be executed without inheritance |\n| They are in the same scope |\tThey are of different scopes. |\n\n# Compile Time Polymorphism Vs Run Time Polymorphism\n\n| Compile Time Polymorphism | Run Time Polymorphism |\n| ------- | ------- |\n| Achieved at `Compile Time` | Achieved at `Run Time` |\n| Through `Function Overloading` \u0026 `Operator Overloading` | Achieved through `Function Overriding` |\n| Function names should be `Same`, but Parameters can be `Different` | Function name and parameters both should be same. |\n| Faster `execution time` | slower |\n| More `memory efficient` | Comparatively less memory efficient |\n\n# Friend Function\n\n- It is a Non-member function, which can access private members of the class.\n\n# Exception Handling in Java\n\n```java\n        int i = 0;\n        int m = 0;\n// try \u0026 catch blocks - won't stop the further execution, if an exception is encountered\n        try {\n            m = 18/i;\n        }\n        catch(Exception obj) {\n            System.out.println(\"Something went wrong.......\");\n        }\n        finally {\n            System.out.println(\"Finally Block runs, whether error occurs or not\");\n        }\n```\n\n# Control Statements:\n## Conditional Statements\n1. if\n2. else\n3. else if\n4. switch\n## Iterative Statements\n1. for\n2. while\n3. do while\n## Jump Statements\n1. break\n2. continue\n3. goto\n\n# Empty Classes\n\nEmpty classes in C++ can't have any data members (variables), but they can indeed still have member functions (methods). It's important to clarify this distinction:\n\n- `Data members:` These are variables that store data associated with an object of the class. Empty classes by definition don't have any.\n- `Member functions:` These are functions defined within a class that can access the class's data members (if any) and other member functions. Empty classes can still have these, even without data members, to perform specific actions or calculations.\n\n## Creating Instances of Empty Classes:\n\n- Yes, you can create instances of empty classes. The compiler allocates a minimum of `1 byte` of memory for each object, even if it's empty, to maintain unique object addresses and facilitate some internal operations.\n\n- While the object itself holds no user-defined data, it retains its type information and can be manipulated like any other object of its class.\n\n```cpp\nclass EmptyClass {\n    public:\n        // Member function (doesn't access any data)\n        void say_hello() {\n            cout \u003c\u003c \"Hello from the empty class!\" \u003c\u003c endl;\n        }\n};\n\nint main() {\n  EmptyClass obj1, obj2; // Creating instances of the empty class\n  // obj1 and obj2 have separate memory addresses despite being empty\n\n  obj1.say_hello();   // Output: Hello from the empty class!\n  return 0;\n}\n```\n\n## Reasons for Using Empty Classes:\n\n- `Placeholders`: Sometimes you might need a class to serve as a placeholder for future implementation or to define relationships between other classes without actual functionality.\n\n- `Type Differentiation`: By creating empty classes, you can differentiate types even when they might have the same behavior, promoting code clarity \u0026 organization.\n\n- `Mixins` and `Traits`: In more advanced scenarios, empty classes can be used as mixins or traits to bundle specific behaviors or properties that can be inherited by other classes for modularity and code reuse.\n\n- `Singletons`: Empty classes can be used to implement the singleton design pattern, ensuring only one instance of a class exists.\n\n### Remember:\n\n- Empty classes don't provide any intrinsic functionality on their own.\n- Using them excessively can lead to unnecessary complexity and might not be the most efficient approach in all situations.\n- Consider alternatives like interfaces or abstract classes if you only need to define common behavior without implementation.\n\n# Role of `cout` and `cin` in C++\n\nI'd be glad to discuss `cout` and `cin` in C++:\n\n**What are cout and cin?**\n\n- **`cout`** (standard output stream) and **`cin`** (standard input stream) are predefined objects in C++ used for formatted input and output operations, respectively.\n- They are instances of the `ostream` and `istream` classes, respectively, which provide the base functionalities for input/output operations.\n\n**Why are they used?**\n\n- **Convenient and User-Friendly:** `cout` and `cin` offer a simple and readable way to interact with the user during program execution. They eliminate the need for low-level system calls, making your code more portable and maintainable.\n- **Formatted Input/Output:** They allow you to control the presentation of data using formatting options like precision, width, and justification. This enhances code readability and improves user experience.\n- **Object-Oriented Approach:** Being objects themselves, `cout` and `cin` integrate seamlessly into the object-oriented paradigm of C++, promoting consistency and modularity.\n\n**Key Points:**\n\n- **Accessing `cout` and `cin`:** You typically don't need to create instances of `cout` and `cin` yourself. They are implicitly declared in the `iostream` header file, which most C++ programs include by default.\n- **Basic Usage:**\n    - Print to the console: `std::cout \u003c\u003c \"Hello, world!\" \u003c\u003c std::endl;`\n    - Read input from the user: `int age; std::cin \u003e\u003e age;`\n- **Formatting:**\n    - Control output precision: `std::cout \u003c\u003c std::fixed \u003c\u003c std::setprecision(2) \u003c\u003c value;`\n    - Set output width: `std::cout \u003c\u003c std::setw(10) \u003c\u003c name;`\n    - Format input/output to different bases: `std::cout \u003c\u003c std::hex \u003c\u003c number;`\n- **Error Handling:** Check for successful input/output operations using member functions like `fail()` or `good()`.\n\n**Additional Considerations:**\n\n- **Alternative Input/Output Methods:** For more advanced scenarios, C++ offers other classes and functions for file I/O, network I/O, and specialized input/output tasks.\n- **Efficiency:** While `cout` and `cin` are generally convenient, for very performance-critical applications, you might consider lower-level I/O operations for optimizations.\n\n**Beyond the Basics:**\n\n- **Manipulators:** For finer control over formatting, use manipulators like `endl`, `setw`, and `setprecision`.\n- **Customizing Streams:** You can create custom I/O streams that inherit from `ostream` and `istream` to implement specific formatting or behavior.\n\n# Can friend function be used to overload the assignment operator `=` ?\n\n No, friend functions cannot be used to overload the assignment operator (=) in C++. Here's why:\n\n**Specific Operator Restrictions:**\n\n- The assignment operator (=), along with a few other special operators like the function call operator (), must be overloaded as member functions of the class. This is a language-specific rule to ensure these operators behave as expected within the context of the class and its objects.\n\n**Friend Function Purpose:**\n\n- Friend functions are designed to grant external functions access to the private and protected members of a class. They are not intended to act as substitutes for member functions when it comes to core operators like assignment.\n\n**Why Member Function is Necessary:**\n\n- The assignment operator is fundamental to how objects are copied and modified. It needs to have direct access to the object's internal state and modify its data members appropriately. Friend functions, being external, don't have the same level of integration with the object's structure.\n\n**Correct Approach:**\n\n- To overload the assignment operator, define it as a member function within the class:\n\n```c++\nclass MyClass {\npublic:\n  MyClass\u0026 operator=(const MyClass\u0026 other) {\n    // Implement assignment logic here, copying data members from other\n    return *this; // Return a reference to the current object\n  }\n};\n```\n\n**Key Points:**\n\n- Remember that friend functions serve a specific purpose of granting external access, not replacing core member functionality.\n- When overloading operators, adhere to the language rules for each operator to ensure correct behavior and maintainability.\n\n\n# `new` and `delete` in C++: \n\n**Dynamic Memory Allocation:**\n\n- `new` and `delete` operators enable dynamic memory allocation during program execution, meaning memory is allocated at runtime based on specific needs.\n- This contrasts with static allocation, where memory is fixed at compile time.\n\n**`new` Operator:**\n\n- Allocates memory on the heap (free store) for an object of a specific type.\n- Returns a pointer to the newly allocated memory block.\n- Requires a matching `delete` to avoid memory leaks.\n\n**`delete` Operator:**\n\n- Deallocates memory previously allocated with `new`.\n- Takes a pointer to the memory block to be freed.\n- Must match the type of object allocated with `new`.\n\n**Key Points:**\n\n- Use `new` for dynamic object creation and `delete` for deallocation.\n- Always deallocate memory using `delete` when it's no longer needed.\n- Mismatched `new` and `delete` calls can lead to memory leaks or undefined behavior.\n- Be mindful of potential dangling pointers if you delete the object pointed to by the pointer before deleting the pointer itself.\n- For arrays, use `new[]` for allocation and `delete[]` for deallocation.\n\n**Example:**\n\n```c++\nint* ptr = new int(42); // Allocate memory for an int and store address in ptr\ncout \u003c\u003c *ptr \u003c\u003c endl; // Access the value\n\ndelete ptr; // Deallocate memory pointed to by ptr\n```\n\n**Additional Notes:**\n\n- Consider using smart pointers (`std::unique_ptr`, `std::shared_ptr`) to simplify memory management and avoid manual `new` and `delete` usage.\n- The C++ Standard Library provides additional memory management functions like `malloc` and `free`, but `new` and `delete` offer type safety and better integration with object-oriented programming.\n\n# Write a simple program in C++ which demostrate the use of inheritance\n\n```c++\n#include \u003ciostream\u003e\nusing namespace std;\n\n// Base class (parent)\nclass Shape {\npublic:\n    int sides;\n\n    void printName() {\n        cout \u003c\u003c \"I am a Shape\" \u003c\u003c endl;\n    }\n};\n\n// Derived class (child) inherits from Shape\nclass Rectangle : public Shape {\npublic:\n    int width;\n    int height;\n\n    void printDetails() {\n        cout \u003c\u003c \"I am a Rectangle with \" \u003c\u003c sides \u003c\u003c \" sides, \" \u003c\u003c width \u003c\u003c \" width, and \" \u003c\u003c height \u003c\u003c \" height.\" \u003c\u003c endl;\n    }\n};\n\nint main() {\n    Rectangle rectangle;\n    rectangle.sides = 4;\n    rectangle.width = 5;\n    rectangle.height = 3;\n\n    rectangle.printName(); // Inherited from Shape\n    rectangle.printDetails(); // Specific to Rectangle\n\n    return 0;\n}\n```\n\n**Output:**\n```\nI am a Shape\nI am a Rectangle with 4 sides, 5 width, and 3 height.\n```\n\n# Write a program in c++ which defines a function with 3 default arguments and call the function in 4 different ways.\n\nHere's a C++ program that defines a function with three default arguments and demonstrates calling the function in four different ways:\n\n```cpp\n#include \u003ciostream\u003e\nusing namespace std;\n\n// Function with three default arguments\nvoid display(int a = 1, int b = 2, int c = 3) {\n    cout \u003c\u003c \"a = \" \u003c\u003c a \u003c\u003c \", b = \" \u003c\u003c b \u003c\u003c \", c = \" \u003c\u003c c \u003c\u003c endl;\n}\n\nint main() {\n    // Calling the function with no arguments\n    cout \u003c\u003c \"Calling the function with no arguments:\" \u003c\u003c endl;\n    display();\n\n    // Calling the function with one argument\n    cout \u003c\u003c \"\\nCalling the function with one argument:\" \u003c\u003c endl;\n    display(10);\n\n    // Calling the function with two arguments\n    cout \u003c\u003c \"\\nCalling the function with two arguments:\" \u003c\u003c endl;\n    display(10, 20);\n\n    // Calling the function with all three arguments\n    cout \u003c\u003c \"\\nCalling the function with all three arguments:\" \u003c\u003c endl;\n    display(10, 20, 30);\n\n    return 0;\n}\n```\n\n**Output:**\n```sql\nCalling the function with no arguments:\na = 1, b = 2, c = 3\n\nCalling the function with one argument:\na = 10, b = 2, c = 3\n\nCalling the function with two arguments:\na = 10, b = 20, c = 3\n\nCalling the function with all three arguments:\na = 10, b = 20, c = 30\n```\n\nIn this program, the function `display` has three default arguments (`a`, `b`, and `c`). It prints out the values of these arguments. In `main()`, we call this function in four different ways: with no arguments, with one argument, with two arguments, and with all three arguments.\n\n# Advantages of using default arguments:\n1. Simplifies function calls by allowing parameters to have default values, reducing the need for overloaded functions.\n2. Provides flexibility to users, allowing them to omit certain arguments if they are not needed.\n\n# Limitations of using default arguments:\n1. Can make code less readable and more error-prone if default values are not well-documented or if there are multiple parameters with default values.\n2. Default arguments can only be provided at the end of the parameter list, restricting the flexibility of parameter order.\n3. Default arguments are evaluated at compile-time, so changes to default values won't affect existing function calls unless recompiled.\n\n# How inherited method is different from redefined method? in C++\n\nIn C++, inherited methods and redefined methods differ as follows:\n\n## Inherited method:\n1. Inherits the behavior and implementation from a base class.\n2. Accessible directly through the derived class without reimplementation.\n3. Does not need to be explicitly defined again in the derived class.\n\n**Example**:\n\n```cpp\n#include \u003ciostream\u003e\nusing namespace std;\n\n// Base class\nclass Base {\npublic:\n    void display() {\n        cout \u003c\u003c \"Display from Base class\" \u003c\u003c endl;\n    }\n};\n\n// Derived class\nclass Derived : public Base {\n    // No explicit definition of display() here\n};\n\nint main() {\n    Derived obj;\n    obj.display(); // Calls the display() method inherited from Base class\n    return 0;\n}\n```\n\n**Output**\n```sql\nDisplay from Base class\n```\n\n## Redefinition method:\n1. Overrides the behavior of a method from the base class in the derived class.\n2. Requires explicit reimplementation in the derived class to provide a different behavior.\n3. Can provide specialized functionality for the derived class.\n\n**Example**:\n\n```cpp\n#include \u003ciostream\u003e\nusing namespace std;\n\n// Base class\nclass Base {\npublic:\n    void display() {\n        cout \u003c\u003c \"Display from Base class\" \u003c\u003c endl;\n    }\n};\n\n// Derived class\nclass Derived : public Base {\npublic:\n    void display() {\n        cout \u003c\u003c \"Display from Derived class\" \u003c\u003c endl;\n    }\n};\n\nint main() {\n    Derived obj;\n    obj.display(); // Calls the display() method redefined in Derived class\n    return 0;\n}\n```\n\n**Output**\n```sql\nDisplay from Derived class\n```\n\nIn the first example, the `display()` method is inherited from the `Base` class and is used directly in the `Derived` class without reimplementation. In the second example, the `display()` method is redefined in the `Derived` class to provide a different behavior than the one in the `Base` class.\n\n# Design a class called FATHER and MOTHER as base classes and class CHILD which is derived from both FATHER and METHOD classes. FATHER has qualities q1, q2, q3 and MOTHER has qualities q1, q2, q4 . Write a c++ program to display the qualities of CHILD due to inheritance\n\n```c++\n#include \u003ciostream\u003e\nusing namespace std;\n\n// Base class: Father\nclass Father {\npublic:\n    int q1;\n    int q2;\n    int q3;\n\n    // Constructor to initialize qualities of Father\n    Father(int a, int b, int c) : q1(a), q2(b), q3(c) {}\n\n    // Displaying qualities of Father\n    void displayFatherQualities() {\n        cout \u003c\u003c \"Father qualities: q1 = \" \u003c\u003c q1 \u003c\u003c \", q2 = \" \u003c\u003c q2 \u003c\u003c \", q3 = \" \u003c\u003c q3 \u003c\u003c endl;\n    }\n};\n\n// Base class: Mother\nclass Mother {\npublic:\n    int q1;\n    int q2;\n    int q4;\n\n    // Constructor to initialize qualities of Mother\n    Mother(int a, int b, int d) : q1(a), q2(b), q4(d) {}\n\n    // Displaying qualities of Mother\n    void displayMotherQualities() {\n        cout \u003c\u003c \"Mother qualities: q1 = \" \u003c\u003c q1 \u003c\u003c \", q2 = \" \u003c\u003c q2 \u003c\u003c \", q4 = \" \u003c\u003c q4 \u003c\u003c endl;\n    }\n};\n\n// Derived class: Child\nclass Child : public Father, public Mother {\npublic:\n    // Constructor to initialize qualities of Child inherited from Father and Mother\n    Child(int fq1, int fq2, int fq3, int mq1, int mq2, int mq4)\n        : Father(fq1, fq2, fq3), Mother(mq1, mq2, mq4) {}\n\n    // Displaying qualities of Child inherited from Father and Mother\n    void displayChildQualities() {\n        cout \u003c\u003c \"Child qualities inherited from Father:\" \u003c\u003c endl;\n        displayFatherQualities();\n        cout \u003c\u003c \"Child qualities inherited from Mother:\" \u003c\u003c endl;\n        displayMotherQualities();\n    }\n};\n\nint main() {\n    // Creating a Child object and displaying its qualities\n    Child child(1, 2, 3, 4, 5, 6);\n    cout \u003c\u003c \"Displaying Child's qualities:\" \u003c\u003c endl;\n    child.displayChildQualities();\n\n    return 0;\n}\n```\n\n# What are the various stream classes and stream error? Explain in brief. What are input and output streams? Give Examples\n\nIn C++, stream classes are used for input and output operations. These classes represent various types of data sources or destinations, such as files, strings, console input/output, and more. The two primary categories of streams are input streams and output streams.\n\n### Input Streams:\nInput streams are used for reading data from various sources.\n\n#### Examples of Input Streams:\n1. `istream`: This is the base class for all input stream classes. It provides functionalities to read data from various sources like standard input (keyboard), files, and strings.\n   - Example: `cin`, `ifstream` (for file input), `istringstream` (for string input).\n\n### Output Streams:\nOutput streams are used for writing data to various destinations.\n\n#### Examples of Output Streams:\n1. `ostream`: This is the base class for all output stream classes. It provides functionalities to write data to various destinations like standard output (console), files, and strings.\n   - Example: `cout`, `ofstream` (for file output), `ostringstream` (for string output).\n\n### Stream Errors:\nStream errors occur during input/output operations due to various reasons, such as end-of-file, invalid data format, failure to open a file, and others. In C++, stream classes provide mechanisms to handle these errors.\n\n#### Examples of Stream Errors:\n1. `eof()`: This function returns `true` when the end-of-file is reached during input operations.\n2. `fail()`: This function returns `true` when an input/output operation fails due to reasons like invalid data format.\n3. `bad()`: This function returns `true` when a non-recoverable error occurs during input/output operations.\n\n### Brief Explanation:\n- Input streams (`istream`) are used for reading data from various sources, and output streams (`ostream`) are used for writing data to various destinations.\n- Stream errors occur during input/output operations and can be handled using error-checking mechanisms provided by stream classes.\n\n### Example:\n```cpp\n#include \u003ciostream\u003e\n#include \u003cfstream\u003e\n#include \u003csstream\u003e\nusing namespace std;\n\nint main() {\n    // Output stream example: writing to console\n    cout \u003c\u003c \"Hello, World!\" \u003c\u003c endl;\n\n    // Output stream example: writing to a file\n    ofstream outFile(\"output.txt\");\n    if (outFile.is_open()) {\n        outFile \u003c\u003c \"Hello, File!\" \u003c\u003c endl;\n        outFile.close();\n    }\n\n    // Input stream example: reading from console\n    int num;\n    cout \u003c\u003c \"Enter a number: \";\n    cin \u003e\u003e num;\n    cout \u003c\u003c \"You entered: \" \u003c\u003c num \u003c\u003c endl;\n\n    // Input stream example: reading from a file\n    ifstream inFile(\"input.txt\");\n    if (inFile.is_open()) {\n        int data;\n        while (inFile \u003e\u003e data) {\n            cout \u003c\u003c \"Data from file: \" \u003c\u003c data \u003c\u003c endl;\n        }\n        inFile.close();\n    }\n\n    // String input stream example: reading from a string\n    string inputString = \"Hello, String!\";\n    istringstream iss(inputString);\n    string word;\n    while (iss \u003e\u003e word) {\n        cout \u003c\u003c \"Word from string: \" \u003c\u003c word \u003c\u003c endl;\n    }\n\n    return 0;\n}\n```\n\nIn this example:\n- Output streams (`cout`, `ofstream`, `ostringstream`) are used to write data to console, files, and strings respectively.\n- Input streams (`cin`, `ifstream`, `istringstream`) are used to read data from console, files, and strings respectively.\n- Stream error-handling mechanisms (`is_open()`) are used to check if file streams are successfully opened.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanshsinghsonkhia%2Foopm-3rd-sem","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fanshsinghsonkhia%2Foopm-3rd-sem","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanshsinghsonkhia%2Foopm-3rd-sem/lists"}