SRM OODP Unit 1 Study Guide 📖
Master all 10 crucial questions covering Object-Oriented Design Principles, C++ code & UML Diagrams for your exam.
Question 1: What is Object-Oriented Programming (OOP)?
Object-Oriented Programming (OOP) is a programming paradigm based on the concept of "objects", which can contain data and code: data in the form of fields (often known as attributes or properties), and code, in the form of procedures (often known as methods).
Key Concepts:
- Class: A blueprint or prototype from which objects are created. It defines the variables and methods common to all objects of a certain kind.
- Object: A real-world entity that has state and behavior. It is an instance of a class.
Question 2: Explain the Core Features of OOP
| Feature | Description |
|---|---|
| Encapsulation | Wrapping data and functions together into a single unit (class). Keeps data safe from outside interference and misuse. |
| Inheritance | Reusing properties and behaviors of a parent class in a child class. Promotes code reusability. |
| Polymorphism | Ability of a single function, object, or operator to behave differently depending on the context (e.g., Method Overloading). |
| Abstraction | Hiding internal complex implementation details and showing only the essential features of the object to the user. |
Important Note 💡
Ensure you can provide a real-world example for each feature (e.g., Encapsulation = Capsule/Pill, Inheritance = Parent/Child, Polymorphism = A person acting as an employee, father, and customer).
Question 3: Differentiate between POP and OOP
Procedure Oriented Programming (POP) focuses on functions, while Object-Oriented Programming (OOP) focuses on data.
| POP (Procedure Oriented) | OOP (Object-Oriented) |
|---|---|
| Divided into smaller parts called functions. | Divided into smaller parts called objects. |
| Follows Top-Down approach. | Follows Bottom-Up approach. |
| Data moves freely around the system. | Data is hidden and cannot be accessed by external functions. |
| Does not have access specifiers. | Has access specifiers like Public, Private, Protected. |
Question 4: What is a UML Use Case Diagram?
A Use Case Diagram represents the dynamic behavior of a system. It shows the interaction between the user (Actor) and the system (Use Cases).
+--------------------------------+
| ATM SYSTEM |
| |
| Customer ---> ( Withdraw Cash) |
| Customer ---> ( Check Balance) |
| Customer ---> ( Deposit Money) |
+--------------------------------+
- Actor: External entity interacting with the system (e.g., Customer, Admin). Represented by a stick figure.
- Use Case: A specific function or action the system performs. Represented by an oval.
- System Boundary: The box indicating the scope of the system.
Question 5: What is a UML Activity Diagram?
An Activity Diagram represents the workflow and execution process of a system. It models the logic from activity to activity, functioning similarly to a complex flowchart.
[ Start ]
|
v
( Insert Card )
|
v
( Enter PIN ) ---> [ Invalid? ] ---> ( Reject & Eject )
|
[ Valid? ]
|
v
( Select Account )
|
v
[ Finish ]
Question 6: What is a UML Class Diagram?
A Class Diagram maps out the static structure of a system by detailing its classes, attributes, operations, and the relationships among objects.
+------------------+
| Student | <-- Class Name
+------------------+
| - name : string | <-- Attributes (Private)
| - id : int |
+------------------+
| + study() : void | <-- Methods (Public)
| + exams() : void |
+------------------+
Visibility Marks: + Public, - Private, # Protected.
Question 7: Explain the Basic Structure of a C++ Program
A standard C++ program includes header files, namespace declarations, and a main function where execution begins.
#include <iostream>
using namespace std;
int main() {
cout << "Hello, Object-Oriented World!" << endl;
return 0;
}
#include <iostream>allows input/output operations.using namespace std;tells the compiler to use the standard namespace.main()is the mandatory entry point of the program.
Question 8: Control Structures in C++
Control structures dictate the flow of the program logic. They are divided into decision-making and looping structures.
- Selection / Decision Making:
if,if-else,switch. Used to branch execution based on conditions. - Iteration / Looping:
for,while,do-while. Used to repeat blocks of code until a condition is met.
Question 9: Core C++ Practical Programs
For the practical portion of the exam, you must be comfortable writing these standard logic algorithms in C++:
1. Prime Number Identification
#include <iostream>
using namespace std;
int main() {
int n, i, flag = 0;
cout << "Enter a positive integer: ";
cin >> n;
if (n == 0 || n == 1) flag = 1;
for (i = 2; i <= n / 2; ++i) {
if (n % i == 0) {
flag = 1;
break;
}
}
if (flag == 0)
cout << n << " is a prime number.";
else
cout << n << " is not a prime number.";
return 0;
}
2. Fibonacci Sequence Generator
#include <iostream>
using namespace std;
int main() {
int n, t1 = 0, t2 = 1, nextTerm = 0;
cout << "Enter the number of terms: ";
cin >> n;
cout << "Fibonacci Series: ";
for (int i = 1; i <= n; ++i) {
if(i == 1) { cout << t1 << " "; continue; }
if(i == 2) { cout << t2 << " "; continue; }
nextTerm = t1 + t2;
t1 = t2;
t2 = nextTerm;
cout << nextTerm << " ";
}
return 0;
}
3. Armstrong Number Validation
#include <iostream>
using namespace std;
int main() {
int num, originalNum, remainder, result = 0;
cout << "Enter a three-digit integer: ";
cin >> num;
originalNum = num;
while (originalNum != 0) {
remainder = originalNum % 10;
result += remainder * remainder * remainder;
originalNum /= 10;
}
if (result == num)
cout << num << " is an Armstrong number.";
else
cout << num << " is not an Armstrong number.";
return 0;
}
Question 10: Explain Access Specifiers in C++
Access specifiers define how the members (attributes and methods) of a class can be accessed. In C++, there are three main access modifiers used to implement Data Hiding and Encapsulation:
| Specifier | Accessibility Scope |
|---|---|
| Public | Members are accessible from outside the class anywhere the object is visible. |
| Private | Members cannot be accessed or viewed from outside the class. They can only be accessed by methods inside the same class. (This is the default specifier in C++ classes). |
| Protected | Members cannot be accessed from outside the class, but they can be accessed by child classes (derived classes) during inheritance. |
#include <iostream>
using namespace std;
class Base {
private:
int x; // Only accessible within Base
protected:
int y; // Accessible within Base and derived classes
public:
int z; // Accessible everywhere
};
Night Before Exam Tips 🌙
- Revise the exact definitions of the 4 OOP features.
- Practice writing the Prime and Armstrong logic programs on paper.
- Practice drawing one complete Use Case Diagram for a standard system (like an ATM or Library Management).
- Practice drawing one Class Diagram with proper visibility symbols (+ for Public, - for Private, # for Protected).
- Double-check your UML symbols (Arrows, Actors, Diamonds).