CPP Asgn 22bai10314
CPP Asgn 22bai10314
Polymorphism in C++ is the ability of a function or an object to take on many forms. There are two
types of polymorphism: compile-time (overloading) and runtime (overriding).
#include <iostream>
class Base {
public:
};
public:
};
int main() {
Base* basePtr;
Derived derivedObj;
basePtr = &derivedObj;
Encapsulation: Bundling of data and methods that operate on the data within a single unit, e.g., a
class.
Inheritance: Mechanism by which one class can inherit properties and methods from another class.
Polymorphism: Ability of different classes to be treated as instances of the same class through a
common interface.
Abstraction: Hiding the complex implementation details and showing only the essential features of
the object.
Procedure-oriented programming (POP), on the other hand, is based on procedures or routines. The
main differences include:
Structure: POP is structured around functions and procedures, whereas OOP is structured around
objects.
Data Access: In POP, data is usually exposed and can be accessed by any function. In OOP, data is
encapsulated within objects and accessed via methods.
Reusability: OOP promotes reusability through inheritance and polymorphism, which is not
inherently supported in POP.
Modularity: OOP provides better modularity by organizing related data and functions into objects,
making the code more maintainable and scalable.
int a;
int b = 10;
a = a + b;
if (a > 5) {
} else {
switch (a) {
case 8:
break;
default:
break;
int i = 0;
i++;
}
i = 0;
do {
i++;
if (i == 5) {
continue;
if (i == 8) {
break;
return 0;
Q4) Write a program in C++ that display entered string into reverse order.
#include <iostream>
#include <string>
int main() {
string str;
getline(cin, str);
return 0;
int a = 10;
unsigned int b = 20;