PF Lab 4
PF Lab 4
CONDITIONAL STATEMENTS II
Tasks
1. Write a Program that converts an upper case letter into a lower case letter.(Hint :
upper case letter + 32 gives lower case)
CODE
#include<iostream>
#include<conio.h>
using namespace std;
void main()
{
char x,y;
cout<<"enter upper case letter=";
cin>>x;
y=x+32;
cout<<"lower case letter="<<y;
getch();
}
OUTPUT
2. Write a program for a simple calculator .The program should take two float values and the
operation to be performed (char) from the user. The calculator should perform addition, subtraction,
multiplication and division.
Example execution
Enter first number: 4
Enter Second number: 10
Enter operation to be performed (Select from +,-,*, /): +
Result: 14.
CODE
#include<iostream>
#include<conio.h>
using namespace std;
void main()
{
float x,y,s,t,v,n;
char z;
cout<<"enter first number=";
cin>>x;
cout<<"enter second number=";
cin>>y;
cout<<"Enter operation to be performed (Select from +,-,*, /):";
cin>>z;
if(z=='+')
{
s=x+y;
cout<<"sum="<<s;
}
else if(z=='-')
{
t=x-y;
cout<<"subtraction="<<t;
}
else if(z=='*')
{
v=x*y;
cout<<"multiplication="<<v;
}
else if(z=='/')
{
n=x/y;
cout<<"division="<<n;
}
getch();
}
OUTPUT
3. Write a program for an insurance company that allows only people from a certain age group to be
eligible for a specific insurance scheme. If the age is greater than 45 or less than 25 it says you are
not eligible. Else it prints you are eligible.
CODE
#include<iostream>
#include<conio.h>
using namespace std;
void main()
{
int x;
cout<<"enter age=";
cin>>x;
if(x>45||x<25)
{
cout<<"you are not eligible";
}
else
{
cout<<"you are eligible";
}
getch();
}
OUTPUT
4. The following table shows telephone area codes in the state of Georgia along with the largest city
in each area
else if(code==478)
{
cout<<"city is Macon";
}
else if(code==706||code==762)
{
cout<<"city is coiumbus";
}
else if(code==912)
{
cout<<"city is Savannah";
}
getch();
}
OUTPUT
5. Write a program that determines the wages of a person based on working hours. If a person works
for less than 5 hours his wage per hour is Rs.400.if he works for more than 5 and less than 8 hours
wage per hour increases to Rs.560.an addition of Rs.2000 are given as overtime for workers who
work up till 12 hours
CODE
#include<iostream>
#include<conio.h>
using namespace std;
void main()
{
int x,y;
cout<<"enter hours=";
cin>>x;
if(x<5)
{
y=x*400;
cout<<"wages="<<y;
}
else if(x>5&x<8)
{
y=x*560;
cout<<"wages ="<<y;
}
else if(x>=12)
{
y=x*560+2000;
cout<<"wages="<<y;
}
getch();
}
OUTPUT