CCIT 102 – COMPUTER PROGRAMMING 1
Programming
Key
Concepts
C A M A R I N E S S U R P O LY T E C H N I C C O L L E G E S | C O L L E G E O F C O M P U T E R S T U D I E S
ALGORITHM
• An algorithm is a step-by-step procedure Example: A simple algorithm to find the factorial of a
for solving a problem. In C++, it's typically number
implemented as a function. The function
takes input, performs specific operations
on it, and produces output.
Key components of an algorithm in C++:
1. Input: The data that the algorithm
processes.
2. Processing: The steps involved in
transforming the input into output.
3. Output: The result produced by the
algorithm.
FLOWCHART
Key Components of Flowcharts
• A flowchart in C++ is a visual tool Symbols Used:
that represents an algorithm,
showing the sequence of steps in a 1. Terminal (Oval): Represents the start and end points
program. of the flowchart.
2. Input/Output (Parallelogram): Indicates operations
that involve data input and output.
• It uses geometric shapes to depict 3. Process (Rectangle): Denotes processing steps, such
different operations and decisions, as calculations or data manipulation.
connected by arrows to indicate 4. Decision (Diamond): Represents branching points
the flow of control. where a decision is made, leading to different paths
based on yes/no or true/false outcomes.
• Flowcharts help programmers plan 5. Flow Lines (Arrows): Show the sequence of
and visualize the logic of their operations and the direction of flow between
code, making complex processes different symbols
easier to understand.
SYMBOLS
PROGRAM
• A program in C++ is a set of instructions that tells the computer what
actions to perform. It is written in the C++ programming language
and consists of one or more functions, which are blocks of code that
perform specific tasks. The main function is the entry point of the
program, where execution begins.
Structure of a C++ Program
A basic C++ program typically consists of the following elements:
1. Include Directives: These lines include header files that provide access to
predefined functions, classes, and data types. For example, #include
<iostream> provides access to input/output functions like cout and cin.
2. Namespace: The using namespace std; statement allows the use of
standard library components without the std:: prefix. Alternatively, you can
use std:: before each standard library entity.
3. Functions: A function is a block of code that performs a specific task.
The main() function is the entry point of the program and is required in
every C++ program.
4. Variables: Variables are used to store data values. They have a data type,
such as int for integers or double for floating-point numbers.
5. Statements: Statements are individual instructions that perform specific
actions, such as assigning values to variables or displaying output.
EXAMPLE #1
Write a flowchart for finding the greater
between two numbers
CCIT 102 – CP 1 CAMARINES SUR POLYTECHNIC COLLEGES | COLLEGE OF COMPUTER STUDIES
EXAMPLE #2
Write a flowchart to print the sum of two
numbers.
CCIT 102 – CP 1 CAMARINES SUR POLYTECHNIC COLLEGES | COLLEGE OF COMPUTER STUDIES
Writing and Executing a Simple C++ Program
EXAMPLE # 1
Write a flowchart that exchanges the value of two variables: x
and y. The output must be the value of variable y will become the
value of variable x, and vice versa.
CCIT 102 – CP 1 CAMARINES SUR POLYTECHNIC COLLEGES | COLLEGE OF COMPUTER STUDIES
Activity 1
Write a flowchart that checks if the input
number is “positive”, “negative” , or “0”
CCIT 102 – CP 1 CAMARINES SUR POLYTECHNIC COLLEGES | COLLEGE OF COMPUTER STUDIES
Activity 2
Write a flowchart that reads two whole
numbers (also called integers) from the
input, and print them out in increasing
order.
CCIT 102 – CP 1 CAMARINES SUR POLYTECHNIC COLLEGES | COLLEGE OF COMPUTER STUDIES