0% found this document useful (0 votes)
18 views

Oop

Uploaded by

kalasingayvonne
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

Oop

Uploaded by

kalasingayvonne
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

INTRODUCTION TO PROGRAMMING & ALGORITHMS

What is Programming?
Programming is the process of creating a set of instructions that a computer can follow to
perform a specific task.

These instructions are written in a programming language that the computer can understand
and execute.

Why Learn Programming?


Problem Solving: Helps develop logical thinking and problem-solving skills.

Automation: Automate repetitive tasks to save time and effort.


Career Opportunities: Many high-paying jobs require programming skills.

Innovation: Create new software, apps, games, and websites.

Basic Concepts of Programming

1. Algorithm:
- An algorithm is a step-by-step procedure or formula for solving a problem.

- Example: A recipe for baking a cake.

2. Programming Language:
- A language used to write programs (e.g., Python, Java, C++).

- Each language has its own syntax (rules) and semantics (meaning).

3. Syntax:
- The set of rules that defines the combinations of symbols considered correctly structured in
that language.

- Example: In c++, cout<<("Hello, World!") is correct syntax for printing text.

4. Code:
- The actual text written in a programming language.

- Example: x = 5 assigns the value 5 to the variable x.


What is a program?
Is a set of instructions written to perform a task.

Components of a Program

1. Variables:
- Containers for storing data values.

- Example: name = "Alice"stores the string "Alice" in the variable `name`.

2. Data Types:
- Different kinds of data that can be used in a program.

- Common data types: Integer, Float, String, Boolean.

- Example: age = 25 (Integer), height = 5.9 (Float), is_student = True (Boolean).

3. Operators:
- Symbols that perform operations on variables and values.
- Types: Arithmetic (`+`, `-`, `*`, `/`), Comparison (`==`, `!=`, `<`, `>`), Logical (`and`, `or`,
`not`).

4. Control Structures:
- Direct the order of execution of the statements in a program.

- Examples:

Conditional Statements (`if`, `else`, `elif`).

5. Functions:
- Blocks of code designed to perform a specific task.

- Can be called (executed) whenever needed

6.Debugging
Debugging is the process of finding and fixing errors in a program.

Common errors:
Syntax Errors: Mistakes in the use of the programming language (e.g., missing a colon or
parentheses).

Runtime Errors: Errors that occur when the program is running (e.g., dividing by zero).

Logical Errors: The program runs but produces incorrect results (e.g., incorrect formula).
Integrated Development Environment (IDE)
An IDE is a software application that provides comprehensive facilities to programmers for
software development.

Features:
- Code editor

- Debugger

- Compiler/Interpreter
Examples: PyCharm, Visual Studio Code, Eclipse.

BASIC OBJECT-ORIENTED PROGRAMMING (OOP) CONCEPTS

What is Object-Oriented Programming (OOP)?


Object-Oriented Programming (OOP) is a programming paradigm that uses "objects" to design
applications and computer programs.

Objects are instances of classes, which can hold data and methods to perform tasks.

Why Use OOP?


Modularity: Code is organized into objects, making it easier to manage.
Reusability: Objects and classes can be reused across programs.

Scalability: Easier to modify and expand with new features.

Maintainability: Enhances code readability and maintainability.

Key Concepts of OOP

1. Class:
-A blueprint or template for creating objects.

- Defines a type of object according to the methods and attributes it will contain.

2. Object:
- An instance of a class.

- Has attributes (data) and methods (functions).

3. Attributes:
- Variables that belong to an object.

- Also known as properties or fields.


4. Methods:
- Functions that belong to an object.

- Define behaviors or actions that an object can perform.

Four Main Principles of OOP


1. Encapsulation:
- Bundling the data (attributes) and methods (functions) that operate on the data into a single
unit or class.
- Protects the data from direct access by outside code.

2. Abstraction:
- Hiding the complex implementation details and showing only the essential features of the
object.
- Helps to reduce programming complexity and effort.

3. Inheritance:
- Mechanism where a new class (child or subclass) inherits attributes and methods from an
existing class (parent or superclass).

- Promotes code reusability.

4. Polymorphism:
- Ability of different classes to be treated as instances of the same class through inheritance.

- Allows one interface to be used for a general class of actions.


INTRODUCTION TO C++ PROGRAMMING.

What is C++?

 C++ is an object-oriented programming language and a cross-platform language that can


be used to create high-performance applications.
 C++ was developed by Bjarne Stroustrup, as an extension to C language.
 C++ gives programmers a high level of control over system resources and memory.

Why use C++?

 C++ is an object-oriented programming language which gives a clear structure to programs


and allows code to be reused, lowering development costs.
 C++ is portable and can be used to develop applications that can be adapted to multiple
platforms.
 C++ is fun and easy to learn.

The difference between C and C++.

C++ was developed as an extension of C and both languages have almost the same syntax.

The main difference between C and C++ is that C++ support classes and objects while C does not.

You might also like