Basics of C++ Programming
Flowchart
INTRODUCTION
Here are the steps that may be followed to solve an algorithmic problem:
● Analysing the problem statement means making the objective of the
program clear in our minds like what the input is and what is the
required output.
● Sometimes the problems are of complex nature, to make them easier
to understand, we can break-down the problem into smaller
sub-parts.
● In order to save our time in debugging our code, we should
first-of-all write down the solution on a paper with basic steps that
would help us get a clear intuition of what we are going to do with the
problem statement.
● In order to make the solution error-free, the next step is to verify the
solution by checking it with a bunch of test cases.
● Now, we clearly know what we are going to do in the code. In this
step we will start coding our solution on the compiler.
Basically, in order to structure our solution, we use flowcharts. A flowchart
would be a diagrammatic representation of our algorithm - a step-by-step
approach to solve our problem.
Flowcharts
Uses of Flowcharts
➔ Used in documentation.
➔ Used to communicate one’s solution with others, basically used for
group projects.
➔ To check out at any step what we are going to do and get a clear
explanation of the flow of statements.
Flowchart components
● Terminators
Mainly used to denote the start point of the program.
Used to denote the end point of the program
1
,● Input/Output
R Used for taking input from the user and store it in
variable ‘var’
Used to output value stored in variable ‘var’.
● Process
Used to perform the operation(s) in the program. For
example:Sum(2, 3) just Sum(2,3) performs arithmetic
summation of the numbers 2&3.
● Decision
Used to make decision(s) in the program means it
depends on so some condition & answers in the form of T
(for yes) &F (for No).
● Arrows
Generally, used to show the flow of the program from one step
to another The head of the arrow shows the next step and tail
shows the previous one.
● Connector
2
, Used to connect different parts of the program and are
used in case of break through Generally, used for
functions (which we will study .
in our further sections).
Example 1:
Suppose we have to make a flowchart for adding 2 numbers a and b.
Solution:
Summary:
● Flowcharts are the building-block of any program written in any
language.
● Different shapes used to have different meanings.
● Every problem can be represented in the form of a flow chart.
● Sometimes, it becomes a bulky process to represent any program using
flowchart, In those cases, try to find out the optimal solution to the given
problem.
Getting Started
3
, For this course, you will be provided with the in-built compiler of Coding
Ninjas. However, if you want to run programs and practice them on your
local desktop, there are various compilers out there like Code blocks, VS
Code, Dev C++, Atom and many more. We have provided the steps for
installing Code Blocks in a separate file.
About Code blocks
Code blocks is an Integrated Development Environment (IDE) for C/C++. To
set the path of compiler, follow the given steps:
1. Click on menu Settings -> Compiler.
2. Then click on the tab Toolchain Executables.
3. In the text box under Compiler’s installation directly, click on the button
Auto Detect. A pop-up appears.
4. In case, pop-up says, Couldn’t auto detect…, that means you have
downloaded the incorrect setup of code blocks. Uninstall this setup, and
install the setup with MinGW.
Then repeat the above steps. To create a new file:
1. Follow File -> New -> Empty File.
2. Then save that file with extension .cpp
3. In order to run and compile the program press F11 or click on the button
right next to a play button which says Build and Run.
You will get your output window after following step 3.
Looking at the code
C++ code begins with the inclusion of header files. There are many header
files available in the C++ programming language which you will discuss
while moving ahead with the course.
So, what are these header files?
The names of program elements such as variables, functions, classes, and
so on must be declared before they can be used. For example, you can’t just
write x = 42 without first declaring variable ‘x’ as:
int x = 42;
The declaration tells the compiler whether the element is an int, a double, a
float, a function or a class. Similarly, header files allow us to put
declarations in one location and then import them wherever we need them.
This can save a lot of typing in multi-file programs. To declare a header file,
we use #include directive in every .cpp file. This #include is used to ensure
that they are not inserted multiple times into a single .cpp file.
4
Flowchart
INTRODUCTION
Here are the steps that may be followed to solve an algorithmic problem:
● Analysing the problem statement means making the objective of the
program clear in our minds like what the input is and what is the
required output.
● Sometimes the problems are of complex nature, to make them easier
to understand, we can break-down the problem into smaller
sub-parts.
● In order to save our time in debugging our code, we should
first-of-all write down the solution on a paper with basic steps that
would help us get a clear intuition of what we are going to do with the
problem statement.
● In order to make the solution error-free, the next step is to verify the
solution by checking it with a bunch of test cases.
● Now, we clearly know what we are going to do in the code. In this
step we will start coding our solution on the compiler.
Basically, in order to structure our solution, we use flowcharts. A flowchart
would be a diagrammatic representation of our algorithm - a step-by-step
approach to solve our problem.
Flowcharts
Uses of Flowcharts
➔ Used in documentation.
➔ Used to communicate one’s solution with others, basically used for
group projects.
➔ To check out at any step what we are going to do and get a clear
explanation of the flow of statements.
Flowchart components
● Terminators
Mainly used to denote the start point of the program.
Used to denote the end point of the program
1
,● Input/Output
R Used for taking input from the user and store it in
variable ‘var’
Used to output value stored in variable ‘var’.
● Process
Used to perform the operation(s) in the program. For
example:Sum(2, 3) just Sum(2,3) performs arithmetic
summation of the numbers 2&3.
● Decision
Used to make decision(s) in the program means it
depends on so some condition & answers in the form of T
(for yes) &F (for No).
● Arrows
Generally, used to show the flow of the program from one step
to another The head of the arrow shows the next step and tail
shows the previous one.
● Connector
2
, Used to connect different parts of the program and are
used in case of break through Generally, used for
functions (which we will study .
in our further sections).
Example 1:
Suppose we have to make a flowchart for adding 2 numbers a and b.
Solution:
Summary:
● Flowcharts are the building-block of any program written in any
language.
● Different shapes used to have different meanings.
● Every problem can be represented in the form of a flow chart.
● Sometimes, it becomes a bulky process to represent any program using
flowchart, In those cases, try to find out the optimal solution to the given
problem.
Getting Started
3
, For this course, you will be provided with the in-built compiler of Coding
Ninjas. However, if you want to run programs and practice them on your
local desktop, there are various compilers out there like Code blocks, VS
Code, Dev C++, Atom and many more. We have provided the steps for
installing Code Blocks in a separate file.
About Code blocks
Code blocks is an Integrated Development Environment (IDE) for C/C++. To
set the path of compiler, follow the given steps:
1. Click on menu Settings -> Compiler.
2. Then click on the tab Toolchain Executables.
3. In the text box under Compiler’s installation directly, click on the button
Auto Detect. A pop-up appears.
4. In case, pop-up says, Couldn’t auto detect…, that means you have
downloaded the incorrect setup of code blocks. Uninstall this setup, and
install the setup with MinGW.
Then repeat the above steps. To create a new file:
1. Follow File -> New -> Empty File.
2. Then save that file with extension .cpp
3. In order to run and compile the program press F11 or click on the button
right next to a play button which says Build and Run.
You will get your output window after following step 3.
Looking at the code
C++ code begins with the inclusion of header files. There are many header
files available in the C++ programming language which you will discuss
while moving ahead with the course.
So, what are these header files?
The names of program elements such as variables, functions, classes, and
so on must be declared before they can be used. For example, you can’t just
write x = 42 without first declaring variable ‘x’ as:
int x = 42;
The declaration tells the compiler whether the element is an int, a double, a
float, a function or a class. Similarly, header files allow us to put
declarations in one location and then import them wherever we need them.
This can save a lot of typing in multi-file programs. To declare a header file,
we use #include directive in every .cpp file. This #include is used to ensure
that they are not inserted multiple times into a single .cpp file.
4