Lecture 1 OOP
Lecture 1 OOP
Lecture 01
CONTENT
Programming
Computer Program
Programming Languages
Programming Paradigms
C++
3
Programming
Process of creating instructions that a computer can execute.
Programming
Analogy compares programming to giving step-by-step instructions to someone who lacks the ability to
reason on their own.
Example: Imagine instructing a less-than-competent friend to build a Lego set without the provided
instructional manual. Your friend is incapable of doing anything on his own, so you must give him
precise, detailed instructions for every step. If even one piece is placed incorrectly, the entire set could be
ruined.
Computers are not inherently smart; they only do what we explicitly tell them to do through code.
Highlights the need for exactness in programming and how computers rely entirely on clear,
unambiguous instructions.
5
Programming
Typically, the steps and methodologies involved in creating, refining, and managing
software through programming include:
Problem Analysis: Understanding the problem to be solved.
Design: Planning how the program will solve the problem, often using algorithms or
flowcharts.
Coding: Writing the actual code in a specific programming language like Python,
Java, or C++.
Testing and Debugging: Ensuring the program works as intended and fixing any
errors.
Maintenance: Updating and improving the code over time as needed.
6
Programming
Computers only understand machine code, which is a series of 1s and 0s that they can process
and interpret.
Example: Imagine trying to communicate with a friend who only speaks Spanish, while you
speak English—it would be impossible to communicate directly. To bridge the gap, you'd have
to translate your instructions from English into Spanish.
Similarly, when programming, you need to translate your high-level instructions into machine
code (binary) for the computer to understand.
However, manually converting every programming instruction into binary would be impractical,
which is why we use programming languages that automatically handle this translation for us.
7
Computer Program
Computer Program is a structured set of instructions written in a programming language that directs a
computer to perform specific tasks, for instance, calculations, data processing, or controlling hardware
devices.
Create a computer program because it involves designing and writing these instructions in a
structured way that the computer can understand.
Translate human ideas/logic and problem-solving methods into machine-readable code that the
computer can interpret and execute.
Without programming, there would be no way to communicate with the computer or instruct it to
perform tasks.
8
Programming Languages
Programming can be executed utilizing a programming language.
Machine Languages: The most basic level of programming language, consisting of binary code (0s and 1s)
that can be directly executed by a computer's hardware.
Assembly Languages: A low-level programming language that uses symbolic representations (mnemonics)
of machine instructions, allowing for easier programming compared to machine languages. Assembly
languages are translated into machine code by an assembler.
High-Level Languages: Programming languages that are more abstract and human-readable, such as Python,
Java, or C++. Designed to simplify programming tasks and require a compiler or interpreter to convert the
high-level code into machine code that the computer can execute.
9
Programming Paradigms
Programming paradigms are fundamental approaches to programming that influence how developers
structure and organize code. They provide different methodologies for problem-solving and program design.
Imperative Programming: Focuses on explicit commands for the computer to perform, describing how
to achieve a specific task through a sequence of statements.
Procedural Programming: A subtype of imperative programming that organizes code into procedures
or routines, facilitating code reuse through functions. In this paradigm, a program consists of a sequence
of statements that manipulate variables. During execution, the program continuously alters the contents
of the computer's memory, enabling dynamic data management and control flow.
10
Programming Paradigms
Declarative Programming: Emphasizes expressing what the program should accomplish without
specifying how to achieve it. Examples: Structured Query Language (SQL) and functional
programming languages.
Object-Oriented Programming (OOP): Centers around objects, which combine data and behavior,
promoting code reusability and organization through encapsulation, inheritance, and polymorphism.
Examples include: Java, C++, Python, C#, Ruby, PHP etc.
Each paradigm has its strengths and weaknesses and can be chosen based on the specific requirements of a project.
11
Encapsulation
Inheritance
Polymorphism
Abstraction
12
Objective: Restricts direct access to some of an object's components, promoting data hiding
and protecting the integrity of the data. This means that internal object details are hidden
from the outside, and interactions with the object occur through well-defined interfaces
(methods).
Example: A class BankAccount may have private attributes like balance and public
methods like deposit() and withdraw(), controlling how the balance is modified.
13
Purpose: It enhances flexibility and allows for dynamic method resolution. This means that
the same method name can behave differently based on the object that calls it.
Example: If both Dog and Cat classes inherit from the Animal class, they can both
implement the speak() method. When the speak() method is called on an Animal reference
that points to either a Dog or Cat object, the appropriate method for the specific object is
invoked.
15
Four pillars collectively provide a framework for designing and implementing object-
oriented systems, making code more manageable, reusable, and easier to understand.
17
C++
Software Development Activities
Source Program
Editing
Compiling
Compile
Linking with precompiled files:
Library routines
Library modules Edit Link
Object files
Other object files
Loading
Think Load
Executing
C++
Example: Code execution
Link
Test.obj + Libraries Test.exe
19
C++
Integrated Development Environments (IDEs)
Definition: Comprehensive software applications that facilitate software development by integrating various
tools into a single interface.
Fundamental Characteristics:
Code Editor: A text editor with syntax highlighting and code completion to assist in writing code.
Debugger: A utility for testing and troubleshooting code, allowing developers to identify and fix errors.
Build Automation: Tools that automate the process of compiling and linking code, streamlining project
builds.
20
C++
Integrated Development Environments (IDEs)
Benefits:
Streamlined Workflow: Reduces context switching by providing all necessary tools in one
environment.
Encompasses all the attributes for developing software, e.g., Editor, Compiler, Linker, Loader,
Debugger, Viewer etc.
21
C++
Download and install Microsoft Visual Studio 2017/2019
https://visualstudio.microsoft.com/downloads/
22
C++
Beginning with your first C++ Code
23
C++
Code Explanation
1. #include <iostream>: Includes the Input/Output Stream library, which is necessary for using cout, cin, and other I/O
operations.
2. using namespace std;: Allows the program to use the standard namespace, which includes features like cout and endl
without needing to prefix them with std::.
3. void main(): Defines the main function, which is the entry point of a C++ program. Use int main(), if the main function
should return an integer.
4. { and }: These curly braces define the beginning and end of the main function's body.
5. cout << "Hello World" << endl;: This line outputs the string "Hello World" to the console. cout is used for output, << is the
stream insertion operator, and endl not only moves the output cursor to the next line but also ensures that the output is
displayed immediately.
THANK YOU
24