Programming Fundamentals Lab (CL1002) : Laboratory Manual Fall 2021
Programming Fundamentals Lab (CL1002) : Laboratory Manual Fall 2021
(CL1002)
LABORATORY MANUAL
Fall 2021
LAB: 02
Playing with DevC++
______________________________________
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.
Run DevC++ IDE now. Open a new code file and save it as lab02_1.cpp.
#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.
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:
Change:
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;
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
#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:
Task # 8:
Change the condition in while loop so that the variable is printed until it reaches a value of 100.
Change for 100:
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.
}
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.