You are on page 1of 19

UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA

FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING

SOFTWARE ENGINEERING DEPARTMENT

COMPUTER
PROGRAMMING
Experiment 1
IDE Installation and Running a Simple C++ Program

CLO 2. Use modern tools and languages for solving problems of


varying complexities

CLO 3. Construct the experiments/projects of varying


complexities.

CLO 4. Demonstrate unique solution of problem under discussion.

1
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING

SOFTWARE ENGINEERING DEPARTMENT

Purpose
This experiment provides an introduction Fundamentals of a basic C++ Program. Students will
compile and run programs consisting of C++ building blocks.

Objectives:
At the end of this experiment you will:
1) Get familiar with the basic structure of C++ Program.
2) Able to run and check different but related programs consisting of C++ building blocks.

Equipment and Components:


3) Dev-C++ 5.0 Beta 9.2 (4.9.9.2) 9.0 MB with Minge/GCC 3.4.2
4) Code::Blocks IDE 20.03

2
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING

SOFTWARE ENGINEERING DEPARTMENT

How to Install Code:: Blocks on Windows

To create and run programs you need two things:

1. Text editor
2. Compiler

A text editor is where you write your programs.

A compiler translates your program into a binary stream of 1s and 0s which computer understands.

So whenever you compile a program, the compiler creates a new binary file called executable
(having .exe extension in Windows) which computer can execute.

Steps you need to follow while writing C/C++ programs.

1. Create a program
2. Compile program
3. Run program

3
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING

SOFTWARE ENGINEERING DEPARTMENT

Why uses an IDE?


IDE (integrated development environment) allows you to create, compile and run programs from a
single environment. Code Blocks comes with a compiler called GCC to compile C and C++
programs.

Introduction
CodeBlocks is an open-source, cross-platform (Windows, Linux, MacOS), and free C/C++ IDE.
Code::Blocks is an Integrated Development Environment (IDE) used by many C++ software
engineers and developers. An IDE is like a text editor with added features. It runs on the major
platforms including Linux, OS-X and Windows. Code::Blocks is free, open source and configurable
for use with different compilers including GCC/G++ using MinGW. The mother site of CodeBlocks
is www.codeblocks.org

Installing Code::Blocks
Follow these instructions carefully. Do NOT just continue without completely reading
each step of the instructions carefully or you will probably not install the software
correctly. If in doubt ask a classmate or the instructor to verify what you are doing. If
you cannot create a project after installing, then you will need to reinstall following these
instructions more carefully.

4
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING

SOFTWARE ENGINEERING DEPARTMENT

1. Download the codeblocks-20.03mingw-setup.exe binary for your computer


from www.codeblocks.org/downloads/binaries or sourceforge.net/projects/code
blocks/files/Binaries/.

The mingw-setup version includes the gcc/g++ compiler preconfigured and


makes our installation easier.

2. Run the setup file after it finishes downloading and press the Next
> button after reading the dialog.

5
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING

SOFTWARE ENGINEERING DEPARTMENT

3. Read the license and press the I Agree button.

6
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING

SOFTWARE ENGINEERING DEPARTMENT

4. Choose the default components as shown and press the Next > button.

For Windows, if you do not see minGW go back to step 1 and download the
correct file.

7
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING

SOFTWARE ENGINEERING DEPARTMENT

5. Choose an installation folder (C:\CodeBlocks) as shown below and press


the Install button.

Do NOT use the default location or you may have problems later in the
installation of SFML or the creation of a project. Instead, install
at C:\CodeBlocks to make working at the command line and with SFML easier.

8
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING

SOFTWARE ENGINEERING DEPARTMENT

6. Choose to run Code:Blocks now by pressing the Yes button.

This step allows us to immediately configure the compiler. You can come back
to this step if you decide to run Code::Blocks later.

7. Select the GNU GCC Compiler as shown, press the Set as default button and then
press the OK button.
9
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING

SOFTWARE ENGINEERING DEPARTMENT

If you have previously installed Code::Blocks, you may not see this dialog. If you
are changing the compiler, you will need to manually set the compiler path
(Settings -> Compiler -> Toolchain executables -> Compiler's installation
directory).

8. Make a choice for the file association and press the OK button.

Choosing to associate Code::Blocks with C++ files means that Code::Blocks will
start automatically whenever a C++ file is selected, such as by double-clicking an
icon on Windows. If unsure, select "No, leave everything as it is (but ask me again
next time)".

10
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING

SOFTWARE ENGINEERING DEPARTMENT

9. Exit Code::Blocks (File -> Quit) and then press the Finish button to exit the installer.

10. Test the installation by creating a project as shown in the next section.

11
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING

SOFTWARE ENGINEERING DEPARTMENT

C. Creating a Project
1. Start Code::Blocks and click the "Create a new project" link or use the
menus: File > New > Project.

2. In the New from template dialog select the Empty project template.

12
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING

SOFTWARE ENGINEERING DEPARTMENT

3. In the "Empty project" start screen press the Next button.

13
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING

SOFTWARE ENGINEERING DEPARTMENT

4. Continuing through the Empty project wizard, enter a project title and folder path
and then press the Next button.

14
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING

SOFTWARE ENGINEERING DEPARTMENT

5. Continuing through the Empty project wizard, verify the GNU GCC compiler is
selected and then press the Finish button.

15
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING

SOFTWARE ENGINEERING DEPARTMENT

6. Add a new empty file to the project using the menu: File -> New -> Empty file.

7. If you get the following dialog press the Yes button.

8. Save the file using an appropriate file name (hello.cpp) and press the Save button.

16
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING

SOFTWARE ENGINEERING DEPARTMENT

9. Confirm the multiple selection and press the OK button.

17
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING

SOFTWARE ENGINEERING DEPARTMENT

10. In the file tab (hello.cpp), copy and paste the following program code.

#include <iostream>
using namespace std;

int main()
{
cout << "Hello, World!\n";
return 0;
}

11. In the project workspace, build and run the project (Build -> Build and run).

12. Verify you get a console window like the following after running the program.

18
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING

SOFTWARE ENGINEERING DEPARTMENT

You should see both Hello, World! and that the process returned 0. Any value
other than 0 means there is a problem. If you have problems ask the instructor or
a classmate for help. Make sure the console has focus and then press any key to
close the console.

19

You might also like