What is Object-Oriented Programming (OOP)?
Object-Oriented Programming (OOP) is a programming approach that organizes
software design around objects, which represent real-world entities.
Each object contains:
• Data (attributes)
• Methods (functions that operate on the data)
OOP focuses on data security, reusability, modularity, and flexibility.
The main principles of OOP are:
1. Encapsulation
2. Abstraction
3. Inheritance
4. Polymorphism
Difference Between OOP and Procedure-Oriented Programming (POP)
Procedure-Oriented Object-Oriented Programming
Basis
Programming (POP) (OOP)
Focuses on functions and Focuses on objects containing
Basic Approach
procedures. data and methods.
Program Program is divided into Program is divided into objects
Structure functions. (classes).
Data is global and can be Data is hidden (encapsulated) and
Data Handling
freely accessed by functions. accessed only through methods.
Less secure because data is More secure due to data hiding
Security
exposed. and access control.
Limited reusability (functions High reusability through
Reusability
can be reused). inheritance and classes.
Data Flow Functions operate on data. Objects interact with each other.
Example
C, Pascal, Fortran. C++, Java, Python.
Languages
Procedure-Oriented Object-Oriented Programming
Basis
Programming (POP) (OOP)
Concepts No support for inheritance, Fully supports inheritance,
Support polymorphism, abstraction. polymorphism, abstraction.
Real-world Difficult to represent real- Natural way to model real-world
Modeling world objects. systems.
Harder to maintain for large Easier maintenance and scaling
Maintenance
programs. for large projects.
Summary (2–3 lines)
• POP focuses on procedures (functions) and treats data as secondary.
• OOP focuses on objects and ensures better security, modularity, and
reusability.
1. Data Abstraction (Simple Definition)
Data Abstraction means showing only the important information and hiding the
unnecessary details from the user.
Example:
When you drive a car, you only see the steering, pedals, and dashboard.
You don't see the engine details → They are abstracted.
2. Data Encapsulation (Simple Definition)
Data Encapsulation means wrapping (binding) data and functions together into a
single unit called a class.
It protects the data and keeps it organized.
Example:
A “Student” class has:
• Data: name, roll no
• Functions: display(), getMarks()
Everything is packed together like a capsule → Encapsulation.
3. Data Hiding (Simple Definition)
Data Hiding means protecting data so that it cannot be directly accessed from
outside the class.
This is done using private and protected access specifiers.
Example:
You cannot access [Link] directly because it is private.
You must use a function like getMarks() → Data is hidden.
Difference in One Line Each
• Data Abstraction: Show only necessary features.
• Data Encapsulation: Bind data + functions together in one unit.
• Data Hiding: Restrict access to data for security.
simplest C++ program to find the area and perimeter of a circle.
Very Simple C++ Program
#include <iostream>
using namespace std;
int main() {
float r, area, peri;
cout << "Enter radius: ";
cin >> r;
area = 3.14 * r * r;
peri = 2 * 3.14 * r;
cout << "Area = " << area << endl;
cout << "Perimeter = " << peri;
return 0;
define the following term with relevant examples: classes and objects , Inheritance,
polymorphism.
1. Classes and Objects
Class (Simple Definition)
A class is a blueprint or template from which objects are created.
It contains data (variables) and functions (methods).
Example:
class Car {
int speed;
void start();
};
Here Car is a class.
Object (Simple Definition)
An object is a real thing created from a class.
It has its own data and can use the class functions.
Example:
Car c1; // c1 is an object
If Car is the design, c1 is the actual car.
2. Inheritance
Simple Definition
Inheritance means creating a new class from an existing class.
The new class inherits (gets) all properties of the old class.
Example:
class Animal {
void eat();
};
class Dog : public Animal {
void bark();
};
• Animal = Parent class
• Dog = Child class (inherits eat())
Dog can eat() + bark().
3. Polymorphism
Simple Definition
Polymorphism means one thing having many forms.
In OOP, the same function name can work in different ways.
Type 1: Function Overloading
Same function name, different parameters.
void area(int r);
void area(int l, int b);
Type 2: Function Overriding
Child class changes the function of parent class.
class Animal {
void sound() { cout << "Animal sound"; }
};
class Dog : public Animal {
void sound() { cout << "Dog barks"; }
};
One-Line Definitions for Revision
• Class: Blueprint of objects.
• Object: Instance of a class (real entity).
• Inheritance: Creating a new class using an existing class.
• Polymorphism: Same function performing different tasks.
What is an Abstract Class? (Simple Words)
An abstract class is a class that cannot create objects.
It is only used as a base class (parent class) for other classes.
It must have at least one pure virtual function.
A pure virtual function is a function with no body and written like this:
virtual void show() = 0;
Why Abstract Class?
• To provide a common structure for all child classes.
• To force child classes to implement certain functions.
Simple Real-Life Example
Think of Shape:
• You cannot draw a “shape” directly → it is abstract.
• But you can draw Circle, Rectangle, Triangle.
So, Shape = Abstract class
Circle/Rectangle = Derived classes
Simple C++ Example
#include <iostream>
using namespace std;
class Shape { // Abstract class
public:
virtual void area() = 0; // Pure virtual function
};
class Circle : public Shape {
public:
void area() {
cout << "Area of Circle" << endl;
};
class Rectangle : public Shape {
public:
void area() {
cout << "Area of Rectangle" << endl;
};
int main() {
// Shape s; // Not allowed (cannot create object of abstract class)
Circle c;
Rectangle r;
[Link]();
[Link]();
return 0;
Explanation
• Shape is an abstract class because it has a pure virtual function area() = 0.
• Objects of Shape cannot be created.
• Circle and Rectangle are derived classes.
• They must override the area() function.
Key Points (Easy to Remember)
• Abstract class = incomplete class.
• Contains at least one pure virtual function.
• Cannot create objects of abstract class.
• Child classes must implement the pure virtual function.
write a C++ program to get the name, age and salary of a person and display the same.
Here is a very simple C++ program to get the name, age, and salary of a person and
display them.
Simple C++ Program
#include <iostream>
using namespace std;
int main() {
string name;
int age;
float salary;
cout << "Enter name: ";
cin >> name;
cout << "Enter age: ";
cin >> age;
cout << "Enter salary: ";
cin >> salary;
cout << "\n--- Details Entered ---\n";
cout << "Name: " << name << endl;
cout << "Age: " << age << endl;
cout << "Salary: " << salary << endl;
return 0;
Applications of OOP
1. Real-time systems
– Banking systems, railway and airline reservation systems.
2. Graphics and GUI applications
– Windows, Android, iOS applications.
3. Gaming and animation
– Unity 3D games, simulation software.
4. Web applications
– Websites built using Java, Python, PHP, C# etc.
5. Object-oriented databases
6. Distributed systems
– Cloud computing, networked applications.
7. Mobile applications
8. Scientific and engineering applications
– CAD/CAM, robotics, modeling.
9. AI and Machine Learning applications
– Using Python classes, objects, OOP models.
10. Large-scale software development
– ERP, CRM, billing systems, inventory systems.
Merits (Advantages) of OOP
1. Reusability of Code
– Inheritance allows using existing code without rewriting.
2. Data Security
– Encapsulation & data hiding protect data from misuse.
3. Easy to Maintain and Modify
– Changes in one class do not affect others.
4. Modularity
– Program is divided into small objects (modules).
5. Better Real-world Modeling
– Objects represent real-life entities like Car, Student, Account.
6. Flexibility
– Polymorphism allows one function to do many tasks.
7. Less Complexity
– Breaks big problems into small manageable objects.
8. Improved Productivity
– Reusable and clean structure makes development faster.
9. Extensibility
– New features can be added without affecting old ones.
10. Encourages Code Organization
– Classes and objects make the program well-structured.
write a syntax , explain the structure of oop
Here is a simple explanation of the syntax and structure of an OOP program in C++,
written in easy words, perfect for exams.
Basic Syntax of an OOP Program (C++ Example)
#include <iostream>
using namespace std;
class ClassName {
private:
// data members
public:
// member functions
};
int main() {
ClassName obj; // creating object
return 0;
This is the general structure of an OOP program.
Explanation of OOP Structure
An OOP program is mainly built using the following components:
1. Class
A class is a blueprint that contains:
• Data (variables)
• Functions (methods)
Example:
class Student {
int age; // data
void show(); // function
};
2. Objects
An object is a real thing created from a class.
Example:
Student s1; // s1 is an object
3. Data Members
These are the variables inside a class.
Example:
int age;
float salary;
4. Member Functions
These are the functions inside a class that operate on data members.
Example:
void getData();
void display();
5. Access Specifiers
They control how data/functions can be accessed.
• private → accessible only inside the class
• public → accessible from outside the class
• protected → accessible in inherited classes
Example:
private:
int age;
public:
void show();
6. Constructor & Destructor (Optional)
• Constructor: initializes objects
• Destructor: destroys objects
Example:
Student() { }
~Student() { }
7. Inheritance (Optional Part of Structure)
Using one class to build another.
Example:
class Teacher : public Person { };
Complete Simple Structure (Easy to Understand)
#include <iostream>
using namespace std;
class Student {
private:
int age; // data member
public:
void getAge() { // member function
cout << "Enter age: ";
cin >> age;
void showAge() {
cout << "Age = " << age;
};
int main() {
Student s; // object creation
[Link]();
[Link]();
return 0;
Summary (Easy Words)
• Class = design
• Object = real item
• Data members = variables inside class
• Member functions = functions inside class
• Access specifiers = control data security
• Main function = program starts here
write a c++ program to find the area of a triangle given its sides
Here is a simple C++ program to find the area of a triangle when its three sides are
given, using Heron's formula.
C++ Program (Simple)
#include <iostream>
#include <cmath>
using namespace std;
int main() {
float a, b, c, s, area;
cout << "Enter three sides of the triangle: ";
cin >> a >> b >> c;
s = (a + b + c) / 2; // semi-perimeter
area = sqrt(s * (s - a) * (s - b) * (s - c)); // Heron's formula
cout << "Area of the triangle = " << area;
return 0;
Explanation (Easy Words)
• First, take three sides of the triangle: a, b, c.
• Find semi-perimeter:
𝑎+𝑏+𝑐
𝑠=
2
• Apply Heron’s formula to find the area:
Area = √𝑠(𝑠 − 𝑎)(𝑠 − 𝑏)(𝑠 − 𝑐)
1. Polymorphism (Simple Definition)
Polymorphism means one name — many forms.
In OOP, the same function or operator can work in different ways depending on the
situation.
Example (Simple):
void area(int r); // circle
void area(int l, int b); // rectangle
Same function name area(), but performs different tasks → Function Overloading (one
type of polymorphism).
Another Example (Function Overriding):
class Animal {
public:
void sound() { cout << "Animal sound"; }
};
class Dog : public Animal {
public:
void sound() { cout << "Dog barks"; }
};
Same function name sound(), but different output.
2. Dynamic Binding (Simple Definition)
Dynamic Binding (also called late binding) means the function to be executed is
decided at run-time, not at compile time.
It happens when:
• A base class pointer refers to a derived class object.
• A virtual function is used.
Simple Example:
class Animal {
public:
virtual void sound() { cout << "Animal sound"; }
};
class Dog : public Animal {
public:
void sound() { cout << "Dog barks"; }
};
int main() {
Animal* a;
Dog d;
a = &d; // base pointer → derived object
a->sound(); // output: Dog barks (decided at runtime)
Here:
• sound() is virtual → dynamic binding occurs.
• Correct function is chosen during execution.
In One Line Each
• Polymorphism: Same function name behaving differently.
• Dynamic Binding: Function call decided at runtime using virtual functions.
justify yhe statement class provides security to the data members than structure
Here is a simple and clear justification of the statement:
“Class provides more security to data members than structure.”
✔ Reason 1: Access Specifiers in Class
In a class, you can make data members:
• private
• protected
• public
This means you can hide the internal data and allow access only through functions.
Example:
class Student {
private:
int marks; // hidden and protected
public:
void setMarks(int m) { marks = m; }
};
Here, marks is private → no one can access it directly.
Reason 2: Structures Have Public Members by Default
In C/C++ structures:
• Members are public by default
• Anyone can access and modify them directly
Example:
struct Student {
int marks; // public by default
};
Here, anyone can do:
Student s;
[Link] = -100; // no protection
This shows no security for data in structure.
Reason 3: Data Hiding is Possible Only in Classes
Classes support data hiding, which means:
• Sensitive data can be hidden
• Only specific functions can change it
This makes the program safe and secure.
Structures generally do not support proper data hiding (unless used like classes in
C++).
Reason 4: Encapsulation is Stronger in Classes
A class binds:
• Data members
• Methods to access and modify them
This encapsulation gives complete control over how data is accessed.
Structures usually group data only; they do not enforce security rules.
Simple Conclusion
✔ Classes provide better data security because:
• They allow private and protected access.
• They support data hiding.
• They allow only controlled access through member functions.
• Structures have members public by default, so less secure.
Write a C++ program to read a temperature in Fahrenheit and convert it into Celsius.
Here is a very simple C++ program to convert Fahrenheit to Celsius.
Simple C++ Program
#include <iostream>
using namespace std;
int main() {
float f, c;
cout << "Enter temperature in Fahrenheit: ";
cin >> f;
c = (f - 32) * 5 / 9;
cout << "Temperature in Celsius = " << c;
return 0;
Formula Used
5
𝐶 = (𝐹 − 32) ×
9
Module 2
What are Arrays? (Simple Definition)
An array is a collection of multiple values of the same data type stored in continuous
(adjacent) memory locations.
Example:
int marks[5];
This means marks can store 5 integers.
Why we use arrays?
• To store many values using one name
• Easy to access using index
• Better memory management
Single-Dimensional Array
A 1-D array stores data in a single row.
Example:
int arr[5] = {10, 20, 30, 40, 50};
Different Ways to Initialize 1-D Arrays in C++
1. Initialization at the time of declaration
(a) Full initialization
int arr[5] = {10, 20, 30, 40, 50};
2. Partial initialization
If you give fewer values, the remaining elements become 0.
int arr[5] = {10, 20};
This becomes:
arr = {10, 20, 0, 0, 0}
3. Compiler decides the size
Size is automatically calculated from the number of elements.
int arr[] = {5, 10, 15, 20};
Size = 4
4. Initialize all elements with 0
int arr[5] = {0};
All values → 0 0 0 0 0
5. Input-based initialization (runtime)
Values are taken from the user.
int arr[5];
for(int i = 0; i < 5; i++) {
cin >> arr[i];
Summary Table
Method Example
Full initialization int a[3] = {1,2,3};
Partial initialization int a[5] = {1,2};
Without size int a[] = {3,6,9};
All elements zero int a[5] = {0};
User input cin >> a[i];
Scope Resolution Operator (::) in C++
The scope resolution operator :: is used to access a global variable or a class
member when there is a naming conflict, or to define a class function outside the
class.
Roles of ::
1. Access global variables when a local variable has the same name.
2. Define class member functions outside the class.
3. Access static members of a class.
Example Program
#include <iostream>
using namespace std;
int x = 100; // global variable
class Demo {
public:
int x; // class data member
void setX(int x) {
this->x = x; // sets class member
void showX() {
cout << "Class x = " << x << endl;
}
void showGlobalX() {
cout << "Global x = " << ::x << endl; // access global variable
};
int main() {
Demo d;
[Link](50);
[Link](); // prints class member x
[Link](); // prints global x
return 0;
Output
Class x = 50
Global x = 100
Explanation (Simple Words)
1. ::x → refers to global variable x.
2. this->x → refers to class member x.
3. Using :: helps avoid confusion between variables with the same name.
4. It can also be used to define functions outside the class:
void Demo::showX() {
cout << x;
}
C++ program to check a palindrome number:
#include <iostream>
using namespace std;
int main() {
int num, rev = 0, temp;
cout << "Enter a number: ";
cin >> num;
temp = num;
while(temp > 0) {
rev = rev * 10 + temp % 10;
temp = temp / 10;
if(num == rev)
cout << num << " is a palindrome.";
else
cout << num << " is not a palindrome.";
return 0;
Explanation (Super Simple)
1. Copy the number to a temporary variable.
2. Reverse the number using % 10 and / 10.
3. Compare the original and reversed number.
If they are equal → palindrome, else → not palindrome.
what is an entry controlled loop? Explain with an example the syntax and workingof "for"
loop in C++.
Here’s a simple and clear explanation of an entry-controlled loop and the for loop in
C++ with example and syntax.
1. Entry Controlled Loop (Definition)
An entry-controlled loop is a loop in which the condition is checked first, before
executing the loop body.
• If the condition is true, the loop body executes.
• If the condition is false, the loop body is skipped.
Examples of entry-controlled loops in C++:
• for loop
• while loop
In contrast, a do-while loop is exit-controlled because it executes the loop body first,
then checks the condition.
2. for Loop in C++
The for loop is commonly used when you know in advance how many times the loop
should run.
Syntax
for(initialization; condition; increment/decrement) {
// loop body
Explanation:
1. Initialization: executed once before the loop starts.
2. Condition: checked before each iteration.
3. Increment/Decrement: executed after each iteration.
4. Loop body: executed if condition is true.
3. Example Program
#include <iostream>
using namespace std;
int main() {
int i;
cout << "Numbers from 1 to 5:\n";
for(i = 1; i <= 5; i++) { // initialization; condition; increment
cout << i << " "; // loop body
return 0;
Output
Numbers from 1 to 5:
12345
4. Working of for Loop (Step by Step)
1. Initialization: i = 1
2. Condition check: i <= 5 → true → execute body
3. Execute body: print i
4. Increment: i++ → i = 2
5. Repeat: check condition → execute body → increment…
6. Stop when i > 5
Summary
• for loop is entry-controlled.
• Used when number of iterations is known.
• Structure: for(initialization; condition; update) { body }.
Constants in C++
A constant is a value that cannot be changed during program execution.
Different Ways to Create Constants in C++
1. Using const Keyword
You can declare a variable as constant using the const keyword.
const int MAX = 100;
• MAX cannot be modified after initialization.
• Type safe, and the compiler will give an error if you try to change it.
Example:
#include <iostream>
using namespace std;
int main() {
const float PI = 3.14;
cout << "Value of PI = " << PI << endl;
// PI = 3.1415; // Error: cannot change constant
return 0;
}
2. Using #define Preprocessor Directive
You can create constant values using #define.
#define PI 3.14
• No memory is allocated.
• It’s replaced by the preprocessor before compilation.
• Cannot specify type, so less safe than const.
Example:
#include <iostream>
#define MAX 50
using namespace std;
int main() {
cout << "Max value = " << MAX;
return 0;
3. Using enum Constants
You can use enumeration to create constants (mostly for integers).
enum Week { Mon=1, Tue, Wed, Thu, Fri, Sat, Sun };
• Mon = 1, Tue = 2, …
• Useful for readable code and grouping related constants.
Example:
#include <iostream>
using namespace std;
enum Colors { Red=1, Green, Blue };
int main() {
Colors c = Green;
cout << "Color code = " << c;
return 0;
Summary Table
Method Example Notes
const const int x=5; Type-safe, cannot be changed
#define #define PI 3.14 Preprocessor constant, no type safety
enum enum Day {Mon, Tue}; Integer constants, grouped values
C++ program to find the sum, maximum, and minimum of all elements in an array.
C++ Program
#include <iostream>
using namespace std;
int main() {
int n;
cout << "Enter the number of elements: ";
cin >> n;
int arr[n];
// Input array elements
cout << "Enter " << n << " elements:\n";
for(int i = 0; i < n; i++) {
cin >> arr[i];
int sum = 0;
int max = arr[0];
int min = arr[0];
// Process array
for(int i = 0; i < n; i++) {
sum += arr[i]; // sum of elements
if(arr[i] > max) max = arr[i]; // maximum element
if(arr[i] < min) min = arr[i]; // minimum element
// Display results
cout << "Sum of elements = " << sum << endl;
cout << "Maximum element = " << max << endl;
cout << "Minimum element = " << min << endl;
return 0;
Explanation (Simple Words)
1. Take number of elements n from the user.
2. Store the elements in an array arr[].
3. Initialize sum = 0, max = arr[0], min = arr[0].
4. Loop through the array:
o Add elements to sum
o Update max if current element is bigger
o Update min if current element is smaller
5. Display sum, max, and min.
Example Run
Enter the number of elements: 5
Enter 5 elements:
10 25 5 30 15
Sum of elements = 85
Maximum element = 30
Minimum element = 5
a) Arrays and Initialization of 1-D Arrays in C++ (CO2 – 08 marks)
Definition of Array
An array is a collection of elements of the same data type stored in continuous
memory locations.
It allows us to store multiple values under a single name.
Example:
int marks[5]; // array of 5 integers
Different Ways to Initialize 1-D Arrays
1. Full Initialization
int arr[5] = {10, 20, 30, 40, 50};
2. Partial Initialization
int arr[5] = {10, 20}; // remaining elements are 0
3. Without Specifying Size
int arr[] = {5, 10, 15, 20}; // compiler calculates size = 4
4. Initialize All Elements to 0
int arr[5] = {0}; // arr = {0,0,0,0,0}
5. Input at Runtime
int arr[5];
for(int i=0; i<5; i++)
cin >> arr[i];
b) Role of Scope Resolution Operator (::) in C++ (CO2 – 06 marks)
The scope resolution operator :: is used to:
1. Access global variables when a local variable has the same name.
2. Define class member functions outside the class.
3. Access static members of a class.
Example
#include <iostream>
using namespace std;
int x = 100; // global variable
class Demo {
public:
int x;
void show() {
int x = 50;
cout << "Local x = " << x << endl;
cout << "Class x = " << this->x << endl;
cout << "Global x = " << ::x << endl;
}
};
int main() {
Demo d;
d.x = 10;
[Link]();
return 0;
Output:
Local x = 50
Class x = 10
Global x = 100
Explanation:
• ::x accesses the global variable x even though a local and class member
variable exist with the same name.
c) C++ Program to Find Sum and Product of All Elements in an Array (CO2 – 06
marks)
#include <iostream>
using namespace std;
int main() {
int n;
cout << "Enter number of elements: ";
cin >> n;
int arr[n];
cout << "Enter " << n << " elements:\n";
for(int i=0; i<n; i++)
cin >> arr[i];
int sum = 0;
int product = 1;
for(int i=0; i<n; i++) {
sum += arr[i]; // sum of elements
product *= arr[i]; // product of elements
cout << "Sum of elements = " << sum << endl;
cout << "Product of elements = " << product << endl;
return 0;
Example Input/Output
Enter number of elements: 4
Enter 4 elements:
2345
Sum of elements = 14
Product of elements = 120
Summary for Exams
• Array: Collection of same-type elements.
• Scope Resolution Operator (::): Access global/class members when there’s a
conflict.
• Sum/Product Program: Loop through array to calculate sum and product.
a) Exit-Controlled Loop & “do-while” Loop in C++ (CO2 – 08 marks)
Definition
An exit-controlled loop is a loop where the loop body executes first and the condition
is checked afterward.
• This guarantees that the loop body executes at least once.
• In C++, the do-while loop is an exit-controlled loop.
Syntax of do-while loop
do {
// loop body (statements)
} while (condition);
Explanation:
1. The statements inside do are executed first.
2. Then, the condition is checked.
3. If the condition is true, the loop repeats.
4. If the condition is false, the loop stops.
Example Program
#include <iostream>
using namespace std;
int main() {
int i = 1;
cout << "Numbers from 1 to 5:\n";
do {
cout << i << " ";
i++; // increment
} while (i <= 5);
return 0;
Output:
Numbers from 1 to 5:
12345
Working (Step by Step)
1. i = 1 → execute loop body → print 1
2. Increment i → i = 2
3. Check condition i <= 5 → true → repeat
4. Continue until i > 5 → loop stops
Key Point: Even if i were initially 6, the loop body would execute once.
b) Different Ways to Create Constants in C++ (CO2 – 06 marks)
1. Using const keyword
const int MAX = 100; // cannot be changed
2. Using #define Preprocessor Directive
#define PI 3.14 // no memory allocated, replaced by preprocessor
3. Using enum
enum Day {Mon=1, Tue, Wed}; // integer constants
Summary Table
Method Example Notes
const const int x=5; Type-safe
#define #define PI 3.14 Preprocessor replaces value
enum enum Colors{Red=1, Green, Blue}; Integer constants
c) C++ Program to Find a Number Using Linear Search (CO2 – 06 marks)
Program
#include <iostream>
using namespace std;
int main() {
int n, key;
cout << "Enter number of elements: ";
cin >> n;
int arr[n];
cout << "Enter " << n << " elements:\n";
for(int i=0; i<n; i++)
cin >> arr[i];
cout << "Enter the number to search: ";
cin >> key;
bool found = false;
for(int i=0; i<n; i++) {
if(arr[i] == key) {
found = true;
break;
if(found)
cout << key << " is present in the array.";
else
cout << key << " is not present in the array.";
return 0;
Example Run
Enter number of elements: 5
Enter 5 elements:
10 20 30 40 50
Enter the number to search: 30
30 is present in the array.
Summary for Exams
1. Exit-controlled loop: do-while → executes first, checks later.
2. Constants in C++: const, #define, enum.
3. Linear search: Traverse array and compare each element with key.