You are on page 1of 14

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: 02
Date: 12th Oct, 2022.

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

1 3
2 3
3 3 5
4 3
5 3
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