0% found this document useful (0 votes)
49 views25 pages

CP Lab 1 and 2 .....

The document is a lab journal from Bahria University's Department of Software Engineering documenting Tayyab Aamir Ali's work on tasks from Computer Programming Lab 1 and 2. It includes 7 tasks from Lab 1 on topics like calculating area of a circle, printing values, and arithmetic operations. Lab 2 includes 5 problems on topics like calculating telephone bills, determining even/odd numbers, and using switch statements. It concludes with 2 additional optional tasks on checking eligibility for government jobs and determining if a number is prime.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
49 views25 pages

CP Lab 1 and 2 .....

The document is a lab journal from Bahria University's Department of Software Engineering documenting Tayyab Aamir Ali's work on tasks from Computer Programming Lab 1 and 2. It includes 7 tasks from Lab 1 on topics like calculating area of a circle, printing values, and arithmetic operations. Lab 2 includes 5 problems on topics like calculating telephone bills, determining even/odd numbers, and using switch statements. It concludes with 2 additional optional tasks on checking eligibility for government jobs and determining if a number is prime.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 25

Bahria University Islamabad

Department of Software Engineering

Computer Programming Lab


(Fall-2022)
Teacher: Engr. M Waleed Khan

Student Tayyab Aamir Ali


Enrollment : 01-131222-048

Lab Journal: 01 and 02


Date: 6th Oct, 2022.

Documentation
Task Wise Marks Total
Task Marks
Marks
No:
Assigned Obtained Assigned Obtained (20)

1 3
2 3
3 3 5
4 3
5 3

INTRODUCTION TO COMPUTER PROGRAMMIN


Comments:

Signature
CP LAB 1 AND 2

INTRODUCTION:
Basic structure of C++ programs and some examples of C++ program.
TOOLS USED:
Dev C++
TASK 1:

Write a program to calculate area and circumference of a circle

#include<iostream>
using namespace std;
int main(void)
{

float pi = 3.14;
float r;
float a;
float c;
cout << "Enter Radius of circle \n";
cin >> r;
a = pi*r*r;
cout << "**************************"<< endl;
cout << "Area of Circle is:"<< a << endl;
cout << "**************************"<< endl;
c= 2*pi*r*r;
cout << "Circumference is: "<< c<< endl;
cout << "**************************"<< endl;
return 0;
}
TASK 2:
Print the assigned values on computer screen

#include <iostream>
using namespace std;
int main(void) {

int integer = 9;
float decimal = 9.112;
char character = 'T';
cout << "Integer Entered was: "<< integer << endl;
cout << "Decimal Entered was: "<< decimal << endl;
cout << "Character Entered was: "<< character << endl;
return 0;
}

TASK 3:
Write a program to perform Arithmetic operations

#include <iostream>
using namespace std;
int main() {
char operation;
int sum,difference,product,division,mod,n1,n2;
cout << "Enter your 1st Number = ";
cin >> n1;
cout << "Enter your 2nd Number = ";
cin >> n2;
while (operation!='e'){
cout << "Select Operation (+,-,/,x,%) = ";
cin >> operation;
if (operation == '+'){
sum = n1+n2;
cout << "Sum Of Numbers = "<<sum<<endl;
}
else if (operation == '-'){
difference = n1-n2;
cout << "Subtraction Of Numbers = "<<difference<<endl;
}
else if (operation == '/'){
division = n1/n2;
cout << "Division Of Numbers = "<<division<<endl;
}
else if (operation == 'x'){
product = n1*n2;
cout << "Product Of Numbers = "<<product<<endl;
}
else if (operation== '%'){
mod = n1%n2;
cout << "Modulus Of Numbers = "<<mod<<endl;
}
else {
cout << "Enter a Valid operator!"<< endl;
}
}
return 0;
}
TASK 4:
Write a program to print message using cout object

#include <iostream>
using namespace std;
int main () {
cout << "Hello Sir \n";
cout << "How May I help you";
return 0;
}
Task5:

Write a program in which you will swap the values of two integers.
#include <iostream>
using namespace std;
int main () {
int temp, n1, n2;
cout << "Enter your 1st Number: ";
cin >> n1;
cout << "Enter your 2nd Number: ";
cin >> n2;
temp = n1;
n1 = n2;
n2 = temp;
cout << "Swapped first number: "<<n1<<endl;
cout << "Swapped second number: "<<n2<<endl;
return 0;
}

TASK6:
Display the name of person, CNIC, Address and age.
#include <iostream>
using namespace std;
int main() {
string name;
string cnic;
string address;
int currentyear;
int birthyear;
int age;
cout<<"enter the name=";
cin>>name;
cout<<"\nenter the cnic=";
cin>>cnic;
cout<<"\nenter the address=";
cin>>address;
cout<<"\nenter the current year=";
cin>>currentyear;
cout<<"\nenter the birth year=";
cin>>birthyear;
age=currentyear-birthyear;
cout<<"name of person="<<name;
cout<<"\ncnic of person="<<cnic;
cout<<"\naddress of person="<<address;
cout<<"\nage of person="<<age;
return 0;
}
TASK 7:

Display the introduction and hobbies.


#include <iostream>
using namespace std;
int main() {
cout<<"My name is Tayyab Aamir Ali I have completed my fsc from joint staff ";
cout<<"right now i am doing BS Software engineering and my hobbies are reading books and
running.";
return 0;
}

Conclusion :
We learnt about basics of c++ and performed the tasks mentioned above using basics of
C++.

CP LAB 02
PROBLEM #1: Computation of telephone bill. (3 marks)
#include<iostream>
using namespace std;
int main()
{
float tbill;
int ncall;
cout<<"number of calls= ";
cin>>ncall;
if(ncall<=100)
{tbill=(0.80*ncall)+250;
cout<<"total bill= "<<tbill;
}
else if((ncall>100)&&(ncall<=250))
{tbill+(1.00*ncall)+350;
cout<<"total bill= "<<tbill;
}
else if(ncall>250)+500;
{tbill=(1.25*ncall)+500;
cout<<"total bill= "<<tbill;
}
return 0;
}
PROBLEM #2: Find whether given number is even or odd using if-else statement. (3
marks)
#include<iostream>
using namespace std;
int main()
{
int num;
cout<<"Enter any number= ";
cin>>num;
if(num%2==0)
{cout<<"The number is an even number";
}
else
{cout<<"The number is an odd number";
}
return 0;
}

PROBLEM # 3: Write a program to find the grades of the students using if-else statement.
(3 marks)
#include<iostream>
using namespace std;
int main()
{
int marks;
cout<<"Enter your marks= ";
cin>>marks;
if((marks>=90)&&(marks<=100))
{cout<<"\n you got A1 grade ";}
else if((marks>=80)&&(marks<=90))
{cout<<"\n you got A grade ";}
else if((marks>=70)&&(marks<=80))
{cout<<"\n you got B grade ";}
else if((marks>=60)&&(marks<=70))
{cout<<"\n you got C grade ";}
else if(marks<=50)
{cout<<"\n you are fail ";}

return 0;

}
PROBLEM # 4: Perform arithmetic operations using switch statement. (3marks)
#include<iostream>
using namespace std;
int main()
{
int num1,num2;
char op;
cout<<"Enter first number","operator","Enter second number= ";
cin>>num1>>op>>num2;
switch(op)
{
case'+':
cout<<"addition of two integers "<<num1 + num2;
break;
case'-':
cout<<"subtraction of two integers "<<num1-num2;
break;
case'*':
cout<<"multiplication of two integers "<<num1*num2;
break;
case'/':
cout<<"division of two integers "<<num1/num2;
break;
}

return 0;

}
PROBLEM # 5: Display the color using switch statement. (3 marks)
#include<iostream>
using namespace std;
int main()
{

char colour;
cout<<"Enter first letter of colour= ";
cin>>colour;
switch(colour)
{
case'G':
cout<<"colour is green ";
break;
case'W':
cout<<"colour is white ";
break;
case'I':
cout<<"colour is indigo ";
break;
case'P':
cout<<"colour is purple ";
break;
}

return 0;

}
Extra tasks:
Task 1: Create a program that decides that whether you are eligible for governmental job. The
max age limit for grade 17 job is 35 years if the person is differently abled then provide a relaxation
of 2 years and if retired officer then adds an extra relief of 1 year. The program should input some
information from the user.

include<iostream>
using namespace std;
int main()
{
int age;
char gov,disable;
cout<<"\n Enter your age= ";
cin>>age;
cout<<"\n Are you a retired employee of a government? =";
cin>>gov;
cout<<"\n Are you disable? =";
cin>>disable;
if(age<=35)
{
{cout<<"\n you are eligible for job";}
}
if(disable=='y')
{
if(age<=37)
{cout<<"\n you are eligible for job";
}
else
{cout<<"\n you are not eligible for job}
}
if (gov=='y')
if(age<=36)
{cout<<"\n you are eligible for job ";}
else
{cout<<"you are not eligible for job ";}

return 0;
}
Task 2: Create a program in which checks if the number entered is prime number or natural
number.

#include<iostream>
using namespace std;
int main()
{
int num;
int i;
int prime;
cout<<" Enter any number = ";
cin>>num;
prime=0;
for(i=1;num>i;i++)
{
if(num%i==0)
{prime++;}
}
if(prime==1)
{cout<<"\n the number is a prime number ";}
else
{ cout<<"\n the number is a natural number ";}

return 0;
}
Conclusion :
We learnt about basics of c++ and performed the tasks mentioned above using using if else
and some of its basics.

You might also like