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

Lab Manual 01 - Working of IDE (Code Blocks)

Uploaded by

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

Lab Manual 01 - Working of IDE (Code Blocks)

Uploaded by

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

Lab Manual: Programming Fundamentals

University of Management and Technology,


Lahore Campus

Lab- 01 Manual
Lab Instructor: Saima Waseem
Department of Artificial Intelligence
Email: [email protected]
LAB 01: Integrated Development Environment (IDE) Installation (Code Blocks)
and Basics of Programming.

1.1 Objective:
1. Learn basic components of a C++ program.
2. Learn compilation process.
3. Learn how to use Code Block Compiler.
4. Learn how to write, edit & run C++ Program.

1.2 Scope:
The student should know the following at the end of this lab:
1. Problem solving
2. How to install run and compile Code Block.
3. Basis structure of program
4. Writing Complete Programs

1.3 Useful Concepts:

C++ program:

A typical structure of a C++ program consists of:

 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.

Department of Computer Science, UMT, Lahore. 1 Riaz Ahmad


Lab Manual: Programming Fundamentals
 Note: #include <file> tells the compiler to look for file where system include
files are held
 #define is used to replace a text with a value, e.g. #define PI 3.141593

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().

Variables / identifiers

These are used to store data in a program. You must declare a variable before you use it.

Here is a general structure of a C++ program.

pre-processor directives main function #include <iostream>

heading using namespace std;

{ int main()

declarations executable statements {

} cout<<“hello World”;

return 0;

Department of Computer Science, UMT, Lahore. 2 Riaz Ahmad


Lab Manual: Programming Fundamentals
Download and Install Code Blocks
1. Download Code Blocks.
2. Save it to your computer
3. Double Click the setup and you will see a following dialog box.

Installation of Code Blocks

STEP 1:
Download Setup of Code Blocks 17.12 or any latest Version.
STEP 2
Click on the Code Blocks file that you downloaded in order to install Code Blocks.

STEP 3
Click ―Next to start installation

STEP 4
https://www.youtube.com/watch?v=o1ruNcmG7L0

STEP 5
Start Code Blocks

Department of Computer Science, UMT, Lahore. 3 Riaz Ahmad


Lab Manual: Programming Fundamentals

1) Header Files
A header file is a file with extension .h which contains C++ function declarations and macro
definitions and to be shared between several source files. You request the use of a header file in your
program by including it, with the C preprocessing directive #include like you have seen inclusion of
iostream header file, which comes along with your compiler.
2) Using namespace std;
The namespace creates a declarative region in which various program elements are defined. The using
statement informs the compiler that you want to use the std namespace. If the following line is not
included the cout would not have been executed, as cout is included in the namespace std.
3) Main Function
void main() is the first statement executed whenever the C++ program is run. It is the starting point of
the program. If main function is not included in the program, the compiler will show an error. Void is a
data type of function main, it shows the program is not returning any value.
4) cout<<”Hello World”;
This line is a statement. Statements in C++ always end with semi-colon. Statements are always executed in the
order they appear. The cout correspond to a standard output stream. It is used to display the output on the screen.
The symbol “<<” refers to an insertion operator. Its function is to direct the string constants to cout which
displays it onto the screen.
1.4 Exercises for lab

Exercise 1.1: Type and save the program with the name LAB0Q1.CPP

Exercise 1.2: Compile, Run, and Test the program

/* Volume of a sphere */
#include <iostream >
#include<cmath>
#define PI 3.14159
int main()
{
double radius, volume;
cout<<"enter the radius > "; cin>>radius;
volume = 4.0 / 3.0 * PI * pow(radius,3);
cout<<"the radius of the sphere is :"<< radius; cout<<"the volume of the
sphere is :"<< volume;
return 0;
}

Department of Computer Science, UMT, Lahore. 4 Riaz Ahmad


Lab Manual: Programming Fundamentals

1.5 Home Work


Launch Code Blocks in your computer and run the above program.

Department of Computer Science, UMT, Lahore. 5 Riaz Ahmad


Lab Manual: Programming Fundamentals

Department of Computer Science, UMT, Lahore. 6 Riaz Ahmad

You might also like