LabManual 1
LabManual 1
LabManual 1
Lahore Campus
========================================================
Email: [email protected]
Table of Contents
1.Objectives .................................................................................................................... 3
2.Scope ............................................................................................................................. 3
3.Concepts ....................................................................................................................... 3
“Lab Manual 1”
Objectives:
1. What is an Algorithm?
2. What is a Flowchart?
3. Difference between Algorithm and Flowchart.
4. What is Pseudo Code?
5. Learn Basic Components of C++ Program.
6. Learn about Compilation Process.
7. Learn how to use Code::Blocks C++.
8. Learn how to Write, Edit and Run a C++ Program.
Scope:
The student should know the following at the end of this Lab:
1. Problem Solving.
2. How to Install, Run and Compile.
3. Basic Structure of a Program.
4. Writing Complete Programs.
Concepts:
1. Algorithm:
To make the program work properly, we must have to properly design the
algorithm. Designing the algorithm helps to utilize computing resources
effectively. Generally, the algorithms are written in natural language or in plain
English language. We can represent algorithms via flowcharts, pseudo code,
and others.
Algorithms use a set of initial data or input, process it through a series of logical
steps or rules, and produce the output (i.e., the outcome, decision, or result).
• Step 1: Start.
• Step 2: Put the teabag in a cup.
• Step 3: Fill the kettle with water.
• Step 4: Boil the water in the kettle.
• Step 5: Pour some of the boiled water into the cup.
• Step 6: Add milk to the cup.
• Step 7: Stir the tea.
• Step 8: Drink the tea.
• Step 9: Stop.
• Step 1: Start.
• Step 2: Input Number1, Number2.
• Step 3: Sum = Number1 + Number2.
• Step 4: Display Sum.
• Step 5: Stop.
Advantages Disadvantages
2. Flowchart:
• The Flowchart is the most widely used graphical representation of
algorithms and procedural design workflows.
• It uses various symbols to show the operations and decisions to be followed
in a program.
• It flows in sequential order. As an instance, a parallelogram in the flowchart
may be used to indicate input and output, a rectangular box indicates a
mathematical operation, a diamond symbol indicates the decision-making
statements, and several other symbols are used in flowcharts.
• A flowchart is an important document for a system and individual program
because it summarizes a program's function in the form of symbols that are
easy to understand and clearly explained in English.
Using Condition:
Advantages Disadvantages
Flowcharts and Algorithms are both required for every programming language.
It helps to solve complex problems as it breaks down into simpler steps. A
flowchart is the graphical representation of the steps of a program, while an
algorithm is a step-by-step method written in simple English.
Note:
4. Pseudo Code:
Begin
End
Begin:
Print Sum.
End
5. C++ Program:
A typical structure of a C++ program consists of:
i. Pre-processor Directives that always begin with #.
(e.g. #include <iostream>)
• The two most frequent commands are #include and #define.
• #include command will include header files that have the definition
of a function used in the program like cout that is in iostream file.
• #define is used to replace a text with a value, e.g. #define PI
3.141593. It allows the programmer to give a name to a constant
value before the program is compiled.
• Note: #include <file> tells the compiler to look for file where system
include files are held.
ii. Functions
A function is a block of statements that make a specific kind of
processing. Every C++ program has a main() function. The execution
starts from main().
Step 1: Go to https://www.codeblocks.org/
Step 2: Go to Downloads.
Step 6: On the Sourceforge page, the download file should* pop up after
severalseconds. Click save file.
*If the download file does not pop up after a few seconds, use the direct link
provided at the top of the page by the Code::Blocks logo.
Step 11: Click Install. Code::Blocks will immediately start installing and
shouldtake less than 5 minutes.
Step 12: If you want, start Code::Blocks now. If not, click no, then next.
You’re done!
1. Here is the video guide link (How to install CodeBlocks IDE on windows):
https://www.youtube.com/watch?v=zmT79Ljo0lI
2. Here is the video guide link (How to install Visual Studio Code IDE on
windows):
https://www.youtube.com/watch?v=CPmQwlycfGI
Lab Tasks:
Task 1: Compile, Run, and Test the program.
Task 2: Type and save the program with the Name LabQ1.cpp.
Task 10: You have to write a C++ program that will print your complete bio
data on the screen.
Output:
Name:
University ID:
Father Name:
Phone Number:
Address:
Semester:
Course:
Home Tasks:
Task 1: Launch Code::Blocks C++ in your computer and run all of the
above programs.
Task 6: Write a pseudo code and draw a flowchart to check whether the
number is even or odd.