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

ICTLab07_SettingUpTheEnvironment

This laboratory manual provides instructions for setting up the DevC++ environment on a Windows PC, including installation, writing, compiling, and running basic C++ programs. It emphasizes the importance of saving work and backing up files to prevent data loss. The manual also covers debugging techniques and common errors encountered in C++ programming.

Uploaded by

Iqra Inayat
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

ICTLab07_SettingUpTheEnvironment

This laboratory manual provides instructions for setting up the DevC++ environment on a Windows PC, including installation, writing, compiling, and running basic C++ programs. It emphasizes the importance of saving work and backing up files to prevent data loss. The manual also covers debugging techniques and common errors encountered in C++ programming.

Uploaded by

Iqra Inayat
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 14

Application of ICT Lab

(CL1009)
LABORATORY MANUAL
Spring 2024

LAB: 07
SETTING UP THE ENVIRONMENT (DEV C++)

Iqra Inayat 24I-6515 CE-A

STUDENT NAME ROLL NO SEC

______________________________________

LAB ENGINEER'S SIGNATURE & DATE


Engr. Muhammad Hammad

MARKS AWARDED: /10


____________________________________________________________________
NATIONAL UNIVERSITY OF COMPUTER AND EMERGING SCIENCES (NUCES), ISLAMABAD
Prepared by: Engr. NIMRA FATIMA, Engr. MOMAL BUKHARI Version: 3.0

Verified by: Engr. AAMER MUNIR

Lab Learning Objectives:


Setting up the Environment (DEV C++) LAB: 07

In this lab session you will:


1. Learn how to install DevC++ on a Windows based personal computer (PC).
2. Write basic codes in DevC++, compile and run them.
3. Learn how to debug your program.

Tools needed:
1. PC running Windows Operating System (OS)
2. Internet access
3. Manual

Important Tip # 1:
Students must backup all work saved on the
computer to a cloud server (e.g. Google Drive,
OneDrive, DropBox, etc.). Any work stored in any
folder in the lab computer (including desktop) is
deleted if the power goes down or when you log out
of the station. Without your backup, you will lose
your work. More about this in Lab 02.

Also note use of USBs is highly discouraged in the


labs or other public computers because of the
possiblity of virus contamination in either
direction.

Turn on the PC and log into it using your student account information. What is this? Before
you can begin programming a PC, i.e., develop a software, and run it, you need to prepare
the PC and set up an Integrated Development Environment (IDE) that allows you to write a
program (code) using a specific language, find errors in it, prepare it to run on the computer
(compile it) and even help you troubleshoot (debug) it.

Note:
In case the the system requires admin password to uninstall, contact the lab assistant.

Setting up DevC++:
Now we will reinstall up an IDE known as DevC++ to be able to create basic programs
(software) for a Windows based PC.

The various steps needed to set up DevC++ are:


1. Download DevC++:
Open your Web Browser (Firefox, Chrome or Internet Explorer) and write the
following URL field: https://sourceforge.net
Write down Dev C++ in the search field.

OR
Use this link directly:
https://sourceforge.net/projects/orwelldevcpp/files/latest/download

Click the green Download button to download Installables folder Dev-Cpp 5.11
TDM-GCC 4.9.2 Setup.exe file.

2. Install it:
Run the downloaded file. It required at least 346.8 MB space on your computers
hard disk's drive C to install it. Continue the installation with default options.

ICT LAB NUCES, ISLAMABAD Page 2 of 14


Setting up the Environment (DEV C++) LAB: 07

The whole installation process typically takes less than 5 minutes (after the file has
been downloaded and run).

Click Finish and then click Next on the next screens and a final OK to finally run the
DevC++ IDE.

ICT LAB NUCES, ISLAMABAD Page 3 of 14


Setting up the Environment (DEV C++) LAB: 07

If you close the IDE, you can run it again through the DevC++ icon on Windows
desktop or by clicking Start button and locating the DevC++ program and clicking it.

Writing code in DevC++, compiling and running it:

Run DevC++ IDE.

1. Opening a new code file:

Click File --> New --> Source File or press keys Ctrl+N (i.e., Ctrl key and N key
simultaneously). A new Untitled1 file will open ready to receive code:

2. Saving code:
For first time save, click File-->Save As to save the file into work folder of your hard
drive or your USB Drive. Give the file a descriptive name e.g. lab1_1.cpp. Code
files of C++ programming language usually end in .cpp extension. This name will
replace the Untitled1 in the tab above the file content area. For subsequent saves,
just press keys Ctrl+S.

ICT LAB NUCES, ISLAMABAD Page 4 of 14


Setting up the Environment (DEV C++) LAB: 07

Important Tip # 2:
Develop a habit of pressing Ctrl+S or click File--
>click Save whenever you make changes to your
code, because if you don’t do so and the computer
accidentally shuts down you will loose work done
since the last save command.

3. Writing first DevC++ Code:


Write the following C++ code verbatim into the file and save it. Note that you are not
supposed to write line numbers with the code. They are given to refer to a particular
line of code.

1 #include <iostream>
2 using namespace std;
3
4 int main()
5 {
6 cout<<"HELLO WORLD"<<endl;
7 return 0;
8 }
Code: lab01_1.cpp

1. Compiling the code:


After writing a code we need to compile it. Click Execute-->Compile or press F9 key
to compile.
If it is error free the compilation process will create a file with the same name as the
.cpp file but extension changed to .exe within the same folder the original .cpp file is
placed in. This is the software, program or the application (or app in short) you have
created. Its type will be marked Application in Windows Explorer.

Successful compilation results in showing that there are no errors, no warnings and
the name (path) of the application file. For example:

ICT LAB NUCES, ISLAMABAD Page 5 of 14


Setting up the Environment (DEV C++) LAB: 07

2. Run the code/application:


It is not the code that runs, but the application (.exe file) created through
compilation process. But we usually say 'run the code' to mean the same thing. You
can run the code (actually the application) within DevC++ IDE by clicking Execute--
>Run or press F10 key. You can also run an application by double clicking it in
Windows Explorer to run it. Try all three ways of running your program.
An alternate way is to compile and run it at the same time: Execute->Compile &
Run or F11 key shortcut.

Important Tip # 3:
Remember the shortcut keys of the tasks you
repetetively do, for example, saving a file
(Ctrl+S), compiling a file (F9), running a code
(F10), compile & run (F11) etc. This will save you
development time.

3. I/O Console:
When you run lab01_1.exe from within DevC++ a black window, called a console
window, appears and handles the input/output (I/O) for the application. In this
course we will only be developing console applications.

Task # 1:
Your task now is to run the lab01_1.exe and write the console output (write everything you
see in the black window):

HELLO WORLD

4. Writing a meaningful DevC++ Code:

Run DevC++ IDE now. Open a new code file and save it as lab01_2.cpp.

1. Write the following code verbatim into it and save it.

ICT LAB NUCES, ISLAMABAD Page 6 of 14


Setting up the Environment (DEV C++) LAB: 07

#include <iostream>
using namespace std;

int main()
{
int a,b,sum;
cout<<"Enter the 1st number: ";
cin>>a;
cout << "Enter the 2nd number: ";
cin>>b;
sum=a+b;
cout<< endl << "Sum of two numbers:"<< sum << endl;
return 0;
}
Code: lab02_1.cpp

This code performs a particular task. Try to understand what it does by running and
interacting with it.

Task # 2:
Run the code lab01_2.cpp with several different inputs and explain what it does.
Inputs Outputs

7,3 10, sum of 7 and 3


11,12 23, sum of 11 and 12
10,7 17, sum of 10 and 7

Task # 3:
Change the code lab01_3.cpp so that it also includes the functionality of subtraction. The
code should display the results as well.

ICT LAB NUCES, ISLAMABAD Page 7 of 14


Setting up the Environment (DEV C++) LAB: 07

Let’s try another one…

Task # 4:

1 #include <iostream>
2 using namespace std;
3
4 int main()
5 {
6 int x = 10, y = 4.5, z;
7
8 cout << "Enter a number less than 10: ";
9 cin >> z;
10
11 y = x / z + y * 2;
12
13 cout << "y = " << y << endl;
14
15 return 0;
16 }
Code: lab01_4.cpp

Repeat the procedure for running the Program but this time you are also required to enter
an input number in console window.
Enter 6 and check the output. Write the value of Y in the box.

Enter a number less than 10.


Y= 9

Now solve the same code with your Calculator (or by hand) and write the answer in
the box.

ICT LAB NUCES, ISLAMABAD Page 8 of 14


Setting up the Environment (DEV C++) LAB: 07

119101 Y=10.6667

Do both answers match?

No, they don’t match

There must be some type of error in the code:

Errors in C/C++
 Syntax Error.
 Run-Time Error.
 Logical Error.

As the program didn’t show any error at compile and run-time, it means there is a
Logical error in the program.
Finding a Logical error and correcting it is known as Debugging.

5. Set DevC++ for Debugging:

Do the following steps to enter the debug mode:

1) Go to <Tools>, Select <Compiler Options>: Select TDM-GCC 4.9.2 64-bit


Debug (or 32-bit Debug based on your computer, whether it is 64 bit or 32 bit)
2) In the General tab, check the checkbox 'Add the following commands when calling
the compiler'. Write -g in both the editable fields, as shown below.
3) Click Settings Tab --> Click Linker Tab:
4) Select Yes after Generate debugging information (-g3).
5) Click OK.

ICT LAB NUCES, ISLAMABAD Page 9 of 14


Setting up the Environment (DEV C++) LAB: 07

 Now click on Debug, as shown in the image below.


ICT LAB NUCES, ISLAMABAD Page 10 of
14
Setting up the Environment (DEV C++) LAB: 07

 Select a break point, by clicking on the number of desired line. This would be
considered as the starting line for debugging.
This would make the whole line RED coloured.

 Now click on <Debug> present in small boxes, on the left of <Add Watch>.
 The line immediate after break point would turn blue, shwoing current line
(that is going to be execute).
 A Console output Screen would appear.
ICT LAB NUCES, ISLAMABAD Page 11 of
14
Setting up the Environment (DEV C++) LAB: 07

 The execution has stopped just before line is to be executed (Blue Line).

 Click Next line (or press Alt + N) in the lower pane of the IDE.

 Line background will become red and the blue arrow and blue background will
move to the next line. This means line has just been executed.

 In order to know what effect a particur instruction (line) has on the state of the
program, we can add a watch window.

 In the lower pane click Add watch and enter variable names in it and click OK.

 Add all the variables used in your program to the watch window by a similar
process.
 Also enter next line till you reach the end of program.
 Study the change in values of variable each time you press next line and try to
understand the error in the program.

ICT LAB NUCES, ISLAMABAD Page 12 of


14
Setting up the Environment (DEV C++) LAB: 07

What was the value of Y that you assigned in program?

4.5

What was the value of Y that was stored in memory?

What do you think was the Error in the program?

Datatype error: We used ‘int' which is only appropriate for whole numbers.
We will replace int with float as we are dealing with decimals. This type of error
can be corrected by declaring the proper datatype

ICT LAB NUCES, ISLAMABAD Page 13 of


14
Setting up the Environment (DEV C++) LAB: 07

ICT LAB NUCES, ISLAMABAD Page 14 of


14

You might also like