Assignment 4 Oops
Assignment 4 Oops
2100290120048
An inline function is a function defined with the `inline` keyword, suggesting to the compiler that it
should insert the complete code of the function at each point where the function is called, instead of
performing a regular function call.
- **Reduced Function Call Overhead:** Inline functions eliminate the overhead of a function call,
which is beneficial for small, frequently used functions.
- **Performance Improvement:** By avoiding the function call mechanism, inline functions can
result in improved performance.
- **Compiler Optimization:** Inline functions enable better opportunities for compiler optimization.
**Example:**
```cpp
#include<iostream>
class Area {
private:
double length;
double width;
public:
// Setter methods
void setLength(double l) {
length = l;
void setWidth(double w) {
width = w;
};
int main() {
Area rectangle;
rectangle.setLength(5.0);
rectangle.setWidth(3.0);
return 0;
```
- **Macro:**
- Defined using `#define`.
- No type checking.
- **Inline Function:**
- Type-checking is done.
A friend function is a function that is not a member of a class but has access to its private and
protected members.
**Example:**
```cpp
#include<iostream>
class MyClass {
private:
int value;
public:
void setValue(int v) {
value = v;
int getValue() {
return value;
}
// Friend function to find the maximum value
};
int main() {
obj1.setValue(10);
obj2.setValue(20);
cout << "Max Value: " << max(obj1, obj2) << endl;
return 0;
```
```cpp
```
```cpp
```
**Q-5) Add Time Objects using Constructor and Friend Function:**
```cpp
```
Function overloading is a feature in C++ that allows a class to have more than one function with the
same name but different parameters.
**Example:**
```cpp
```
Default arguments in C++ allow you to provide default values for function parameters.
**Example:**
```cpp
```
**Q-8) Definitions:**
- **Call by Reference:** Passing a reference to the memory location of a variable rather than the
actual value.
- **Return by Reference:** A function returning a reference, allowing the result to be used directly.
**b) Class, Object, Scope Resolution Operator, Member Function:**
- **Class:** A user-defined data type that encapsulates data members and member functions.
- **Scope Resolution Operator (::):** Resolves the scope of a member function or variable within a
class or namespace.
- **Member Function:** A function associated with a class, acting on its data members.
- **Enum Type:** A user-defined data type used to assign names to integral constants.
Enumerations provide a way to create symbolic names for sets of values.
- **new Operator:** Allocates memory dynamically, returning a pointer to the allocated space.
Feel free to reach out if you have any further questions or need clarifications.