Department of By: Engr.
Farhan Memon
Electrical Engineering Introduction to Computers & C++
Mehran University of Engineering Year 1ST Semester 1st
& Technology Batch 17 Duration 03
Jamshoro Hours
Lab 5: Get familiar with Code::Blocks & writing basic C++ Program
Outlines
· Introduction to Code::Blocks
· Downloading & Installation of Code::Blocks
· Creating a Program in Code::Blocks
· Lab Tasks
Requirements
· Code::Block IDE
1
INTRODUCTION TO CODE::BLOCKS
Code::Block is an open source , free , IDE (Integrated Development Environment) that
supports multiple compilers to write C, C++ and Fortran programs.
It makes possible for a user to be working on multiple projects within your workspace. A
project is a collection of one or more source (as well as header) files.
Source files are the files that contain the source code for your program.
DOWNLOADING & INSTALLATION OF CODE::BLOCKS
You can download it for Windows from following link:
http://sourceforge.net/projects/codeblocks/files/Binaries/16.01/Windows/codeblocks-
16.01mingw-setup.exe
In order to install code::Blocks, Double click on the setup (.exe) file
2
Click Next
Click I Agree.
Take the default settings by pressing Next..
3
Take the default folder to install Code::Blocks to and then select Install and finish
4
CREATING A PROGRAM IN CODE::BLOCKS
1) Create a new file by, File----New----Empty File
02) Save that file with any name and .cpp extension.
5
First C++ Program:
6
Pre-Processor Directive
The C++ language defines several headers, at top of the program starts with the symbol #,
which contain information that is either necessary or useful to your program. Header
<iostream> .
Using Directive
Predefined names in C++ are to be found in the std (standard) namespace. The using
directive allows direct access to the names of the std namespace.
Main Function
Program execution begins with the first instruction in function main(), and this is why each
C++ program must have a main function.
Curly Brackets
Brackets or Curly Brackets are used to surround the body of function.
The next line cout << “Message "; shows the message “Message" to be displayed on the
screen.
The next line return 0; terminates main() function.
Compile & Run:
7
LAB TASKS
1. Write down a program using cout statements to display your Name, Roll
number, Section, Department and University name, each on new line
separately.
2. Write a C++ Program to shape a arrow using * sign.
3. Write a C++ Program to shape a square using * sign.
4. Write a C++ Program to shape a daimond using * sign.
5. Write a C++ Program to shape a rectangle using * sign.
6. Write a C++ Program to make Pakistani Flag using * sign.
SUBMISSION:
In Hard-Format (manual along with exercise), will be checked in the next Lab
The End
8