OOP Assignment SyedZaeemAzharF21BINFT1E02054
OOP Assignment SyedZaeemAzharF21BINFT1E02054
Semester: 2nd
1. What is OOP?
5. What is an Object?
7. What is a Class?
8. What is Meta-Class?
A meta-class is a class that contains instances of other classes. It describes class
structure and behavior in the same way as classes describe object structure and
behavior.
9. What is Inheritance?
Operator overloading enables you to define or override the behavior of operators like
as +, -, and * for user-defined types. This allows operators to operate with custom
classes in a more semantic and natural way, akin to built-in ones.
This is the provision that allows various methods in a class to share the same name
but differ in their parameters. This can, in this situation, enable various functions
depending on the arguments supplied into the method.
Polymorphism is the ability for distinct objects to behave differently to the same
method call. It so permits methods to behave differently depending on the object
calling them.
Inheritance is the process by which a new class, known as the derived or child class,
obtains the properties and methods of an existing class, known as the base or parent
class. It simplifies code reuse and establishes a hierarchical relationship.
A base class, also known as a parent or superclass, is the source of properties and
methods for other classes known as derived or subclasses.
A concrete class is a class that implements all of its methods and can be created
using an object. This contrasts with abstract classes, which cannot be instantiated.
Data members are class variables specified within a class to store its status or
properties. They represent the class's properties, which can be accessed through its
methods.
What is a Constructor?
What is a Destructor?
A global variable is one that is declared outside of any function or class and can be
accessed from anywhere in the program. It has a worldwide scope.
A local variable is a declared variable that can only be accessed within the same
function or block. Its scope is local.
A null pointer is the pointer that does not point to any valid memory address or
object. It generally means that a pointer does not currently reference something. In
modern C++, it is represented by `nullptr`.
28. Describe What Kind of Copy the Default Assignment Operator "=".
Makes on Objects. (Shallow Copy or Deep Copy).
The default assignment operator (`=`) makes a **shallow copy**. It copies the
values of an object's data members but, for pointers, only copies the addresses. This
means that more than one object may point to the same location in memory.
In C++, a friend function can access a class's private and protected members,
reducing its encapsulation. While this allows for greater flexibility in class
interactions, it also exposes information that was intended to be kept private.
A constant member function promises not to change any member variables of the
class:
```cpp
class Example {
public:;
```
};
```
```cpp
class Vector {
public:
```
private:
int x, y;
};
```
36. What is IS-A Relationship? Show How It Is Implemented Using C++ Code
(You Do Not Have to Give the Detailed Code Simply Show in a Single Line or
Two How It Will Be Implemented).
The IS-A relationship defines that one class is a type of another class. In C++, it is
implemented using the mechanism of inheritance:
```
```
```
class Base {
```
};
```
A straight base class derives from another class without passing through any
intermediate classes.
39. How to Declare Template Class as Friend Class of Any Other Class.
To declare a template class as a friend of another class, you may use the following
syntax:
``.END
class OtherClass {
```
```cpp
class Base {
private:
void base1();
protected:
void base2();
public:
void base3();
};
class Derived : public Base {
private:
void derived1();
protected:
void derived2();
public:
void derived3();
};
int main() {
return 0;
```
Definition:
Yes, `deque` is a bidirectional container. It allows the fast insertion and deletion at
both ends.
46. Sort the Following Data in the Order in Which Compiler Searches a
Function
Order:
- Standard Function
- Partial Specialization
- Complete Specialization
- Generic Template
Conflicting Example:
```cpp
class A {
public:
";
}; class B : public A {
public: } ;
"; }
};
class C : public A {
public:
"; }
};
};
```
2. Inheritance: Derived classes can override functions inherited from base classes
to provide specific implementations.
3. Access Through Base Class Pointer: Virtual functions ensure that the correct
function implementation is actually called even when a base class pointer is used to
access the derived-class instance.
Code Snippet:
#include <iostream>
acoास Α('.');
class A {
public:
"; }
};
class B : public A {
public:
"; }
};
int main()
delete a;
return 0;
**
END
- Add `virtual` keyword to the declaration of `method` function inside class `A` to
ensure runtime polymorphism.
Example:
```cpp
#include <iostream>
class Example {
public:
~Example() {
```
try {
catch (.) {
};
};
int main()
return 0;
End
If an exception is thrown in the destructor and is not caught, the program may end.
For example, in the code above, exceptions in the destructor are captured within the
destructor, preventing program termination.
Definition:
Abstraction is the concept of not displaying complex implementation details but
instead presenting simply the features required for an object. Abstraction minimizes
complexity by focusing on key features rather than precise implementation details.
Useage:
Definition:
It is defined as the capacity of a derived class to inherit features from its base class.
A derived class can inherit aspects from the base class, such as data members and
member functions. This allows the derived class to use or override those features
and build upon them.
Example:
```cpp
#include <iostream>
//
class Base {
public :
"; }
};
//
public :
"; }
};
//------------------------------------------------
int main() {
Derived obj;
``
return 0;
```
Explanation:
- `Derived` inherits `baseMethod` from `Base` and can call it, but that doesn't
necessarily mean it doesn't have its own method `derivedMethod`.