Professional Documents
Culture Documents
COMPUTER
PROGRAMMING
Experiment 1
IDE Installation and Running a Simple C++ Program
1
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING
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.
2
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING
1. Text editor
2. Compiler
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.
1. Create a program
2. Compile program
3. Run program
3
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING
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
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
6
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING
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
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
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
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
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
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
13
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING
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
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
6. Add a new empty file to the project using the menu: File -> New -> Empty file.
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
17
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING
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
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