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

Programming Fundamentals Lab (CL1002) : Laboratory Manual Fall 2021

This document is a laboratory manual for a programming fundamentals lab that provides examples of C++ code for students to run and experiment with in the DevC++ IDE. The lab objectives are to run pre-written code examples and understand their functionality. The document includes 5 code examples that perform tasks like calculating the sum of two numbers, finding the area and perimeter of a rectangle, checking if a character is a vowel, using a while loop to print values, and reversing a number. Students are instructed to run and modify the code examples to understand their logic and demonstrate their learning.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
114 views

Programming Fundamentals Lab (CL1002) : Laboratory Manual Fall 2021

This document is a laboratory manual for a programming fundamentals lab that provides examples of C++ code for students to run and experiment with in the DevC++ IDE. The lab objectives are to run pre-written code examples and understand their functionality. The document includes 5 code examples that perform tasks like calculating the sum of two numbers, finding the area and perimeter of a rectangle, checking if a character is a vowel, using a while loop to print values, and reversing a number. Students are instructed to run and modify the code examples to understand their logic and demonstrate their learning.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Programming Fundamentals Lab

(CL1002)

LABORATORY MANUAL
Fall 2021

LAB: 02
Playing with DevC++

________________________________________ __________ ____

STUDENT NAME ROLL NO SEC

______________________________________

LAB ENGINEER'S SIGNATURE & DATE


Maryam Wasim
Moomal Bukhari

MARKS AWARDED: /10


____________________________________________________________________
______
NATIONAL UNIVERSITY OF COMPUTER AND EMERGING SCIENCES (NUCES), ISLAMABAD
Prepared by: Engr. Sana Saleh, Engr. Ifrah Maqsood Version: 1.1

Verified by: Engr. Azhar Rauf


Playing with DevC++ LAB: 02
Lab Learning Objectives:
In this lab session you will:
1. Run pre-written codes provided as examples in DevC++and experiment with it.

Tools needed:
1. PC running Windows Operating System (OS)
2. Connection to the Internet.

Turn on the PC and log into it using your student account information.

Important Tip # 1:
Instead of using USB drive to copy your work done in the lab,
log into your nu.edu.pk email id and copy the data to the
associated GoogleDrive. The reason is that since USB drives get
plugged into lots of systems, their probability of carrying a
virus increases. It wouldn't only risk the lab computer, but in
case the lab system contains viruses, your USB drive will carry
it and infect your home computer/laptop too!
Save your work by pressing Ctrl+S on the PC and enable auto-
sync feature to syncit to your GoogleDrive automatically. This
way, if a power failure occurs, your work would be saved. Even
if the PC's HardDisk crashes irretrievably, your work would
still be safe.

Writing a meaningful DevC++ Code:

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

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

#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 # 1:
Run the code lab02_1.cpp with several different inputs and explain what it does.

ITC LAB NUCES, ISLAMABAD Page 2 of 7


Playing with DevC++ LAB: 02
Inputs Outputs

Task # 2:
Change the code lab02_1.cpp so that it also includes the functionality of subtraction, multiplication
and division. The code should display the results as well.

2. Write the following code in DevC++ and try to find the logic of the code.

#include <iostream>
using namespace std;
int main()
{
double length, width, answer;
cout << "Enter length and width of a rectangle\n";
cin >> length >> width;
answer = length * width;
cout << "Area of rectangle is " << answer << endl;
return 0;
}
Code: lab02_2.cpp

Task # 3:

ITC LAB NUCES, ISLAMABAD Page 3 of 7


Playing with DevC++ LAB: 02
By making a small change in this program, you can calculate perimeter. Try it. Mention the changes
you perform to obtain desired result
Code for Area:

Change:

Code for Perimeter:

3. Write the following code to find out what does this code do.

#include <iostream>
using namespace std;
int main()
{
char test_alphabet;
cout << "Enter an alphabet to check if it is a vowel: ";
cin >> test_alphabet; // Taking Input character;

if(test_alphabet == ’a’ || test_alphabet==’e’ || test_alphabet


==’i’ || test_alphabet==’o’|| test_alphabet== ‘u’)
{
cout<<”alphabet entered is a vowel”<<endl;
}
else
{
cout << "alphabet is not a vowel”<<endl;
return 0;
}
}
Code: lab02_3.cpp

ITC LAB NUCES, ISLAMABAD Page 4 of 7


Playing with DevC++ LAB: 02
Task # 4:

Test above code with different inputs. Enter several vowels (e.g “i”) and several consonants (e.g “b”)
to test the code.
INPUT OUTPUT

Task # 5:

Now try some capital vowel letters (e.g. “A”) and indicate the outputs?
INPUT OUTPUT

Task # 6:

Can you modify the code so that it works for upper- as well as lower-case letters?
Change in code:

INPUT : OUTPUT

ITC LAB NUCES, ISLAMABAD Page 5 of 7


Playing with DevC++ LAB: 02
4. Given the below template run it in IDE and try to understand what it does.

#include <iostream>
using namespace std;
int main()
{
int i=1;
while(i<=15)
{
cout<<"Value of variable i is: "<<i<<endl;
i=i+1;
}
}
Code: lab02_4.cpp

Task # 7:

Explain what the above code does.


Explanation:

Task # 8:

Change the condition in while loop so that the variable is printed until it reaches a value of 100.
Change for 100:

ITC LAB NUCES, ISLAMABAD Page 6 of 7


Playing with DevC++ LAB: 02

Task # 9:

Change the condition in while loop so that the variable is printed until it reaches a value of 99
(keeping the tested value in the code as 100).
Change for 99:

5. Write the following code to find out what does this code does.

#include <iostream>
using namespace std;
int main()
{
int Number, Reverse = 0;
cout << "Input a Number to Reverse and press Enter: ";
cin >> Number; // Taking Input Number in variable number.

while( Number!= 0 ) //while loop for repetition.


{
Reverse = Reverse * 10;
Reverse = Reverse + Number%10;
Number = Number/10;
}
cout << "New Reversed Number is: "<< Reverse << endl;
return 0;

}
Code: lab02_5.cpp

Task # 10:

Test above code. Explain what does this code do. Are there any limitations of this code. If ‘Yes’,
mention them.

ITC LAB NUCES, ISLAMABAD Page 7 of 7


Playing with DevC++ LAB: 02

ITC LAB NUCES, ISLAMABAD Page 8 of 7

You might also like