BARMAGA ACADEMY
MAY 2024
Programming Fundamental
OOP
Build your future
1 Loops Definition.
2 For - Rule.
3 While - Rule.
4 Do - While - Rule.
5 Functions.
6 Array.
7 Structure.
Agenda
Every day the knowledge was updated so you must upgrade
your self.
Stay connected with us ...
Stay Learn With
Us
Loops Definition.
Back to Agenda
In programming, a loop is a control structure that allows a section of code to be
repeated a certain number of times. It is a way to execute a block of code repeatedly
for a specified number of iterations.
A loop typically consists of three elements:
Initialization: This is the starting point of the loop, where the loop counter or
variable is initialized.
1.
Condition: This is the test that determines whether the loop should continue to
execute or terminate. The condition is evaluated at the beginning of each
iteration.
2.
Increment/Decrement: This is the step that updates the loop counter or variable
after each iteration.
3.
Back to Agenda
For - Rule.
For Loop: A for loop is used to execute a block of code for a specified number
of iterations. It is typically used when the number of iterations is known
beforehand.
Back to Agenda
While - Rule.
While Loop: A while loop is used to execute a block of code as long as a certain
condition is true. It is typically used when the number of iterations is not known
beforehand.
Back to Agenda
do while - Rule.
Do-While Loop: A do-while loop is similar to a while loop, but the condition is
evaluated at the end of each iteration.
Functions.
Back to Agenda
In programming, a function is a block of code that can be executed multiple times
from different parts of a program. It is a self-contained piece of code that
performs a specific task, and it can be called multiple times with different inputs
to produce different outputs.
A function typically has the following characteristics:
Name: A function has a unique name that identifies it.1.
Parameters: A function can take one or more parameters, which are values passed to the function
when it is called.
2.
Body: The body of the function is the code that is executed when the function is called.3.
Return type: A function can return a value to the caller, which can be used in the program.4.
Functions.
Back to Agenda
Functions are useful in programming because they:
Modularization: Functions allow you to break down a large program into smaller, manageable
pieces of code.
1.
Re usability: Functions can be called multiple times from different parts of a program, reducing
code duplication.
2.
Abstraction: Functions can hide complex implementation details, making it easier to use and
understand the code.
3.
Easier maintenance: Functions make it easier to modify and update code, as changes can be
made in one place and affect the entire program.
4.
Types of functions:
User-defined functions: These are functions created by the programmer to perform a specific task.1.
Built-in functions: These are functions provided by the programming language or library, 2.
such as printf () or sqrt ().
3. Recursive functions: These are functions that call themselves repeatedly until a base
case is reached.
Arrays.
Back to Agenda
An array is a collection of elements of the same data type stored in contiguous memory
locations. Here's a breakdown of how to define and use arrays in C++:
To define an array, you need to specify the following:
Data type: The type of elements that the array will hold (e.g., int, double, char, etc.).1.
Array name: The name of the array.2.
Size: The number of elements that the array will hold.3.
data_type array_name [size];
int element [100];
Structure.
Back to Agenda
A structure (also known as a struct) is a user-defined data type that allows you to combine
multiple variables of different data types into a single unit. Here's how to define a structure
in C++:
To define a structure, you use the struct keyword followed by the name of the structure
and the variables that make up the structure, enclosed in curly braces {}.
struct structure_name {
data_type variable1;
data_type variable2;
data_type variableN;
};
struct Person {
int age;
char name[20];
double height;
};