You are on page 1of 11

Name: Abdullah Khan

Roll No: 19-EE-154


Section: “B”
Submitted To: Sir Shahwar Ali
Task no 1:
Program:
#include <iostream>
using namespace std;
int main()
{
int p,q;
cout<<"Enter first number : ";
cin>>p;
cout<<"Enter second number : ";
cin>>q;
cout<<"\nRESULT: "<<endl;
switch(p > q)
{
case 0:
cout<<q<<" is Maximum number";
break;
case 1:
cout<<p<<" is Maximum number";
break;
}
return 0;
}

Output:

Task no 2:
Program:
#include <iostream>
using namespace std;
int main()
{
cout<<"Checking Even and Odd Numbers using Switches: \n";
int a;
cout<<"Enter the number : ";
cin>>a;
cout<<"\nRESULT: "<<endl;
switch(a%2==0)
{
case 0:
cout<<a<<" is Odd Number";
break;
case 1:
cout<<a<<" is Even Number";
break;
}
return 0;
}
Output:
Task no 3:
Program:
#include <iostream>
using namespace std;
int main()
{
cout<<"Checking grade of student using Switches:\n";
int marks;
cout<<"Enter the percentage : ";
cin>>marks;
cout<<"\nRESULT: "<<endl;
switch(marks/10)
{
case 10:
cout<<"Your Grade is A."<<endl;
break;
case 9:
cout<<"Your Grade is A."<<endl;
break;
case 8:
cout<<"Your Grade is B."<<endl;
break;
case 7:
cout<<"Your Grade is C."<<endl;
break;
case 6:
cout<<"Your Grade is D."<<endl;
break;
default:
cout<<"You are fail."<<endl;
break;}
return 0;
}

Output:
Task no 4:
Program:
#include <iostream>
#include <math.h>
using namespace std;
int main()
{
cout<<"enter any operator and number to perform
operation:"<<endl;
char a;
int x,y;
cout<<"\nInput the operation tou want to perform : ";
cin>>a;
cout<<"Enter the first number : ";
cin>>x;
cout<<"Enter the second number : ";
cin>>y;
cout<<"\nResult:"<<endl;
switch(a)
{
case '/':
cout <<"The Solution of operation is : "<<x/y;
break;
case '*':
cout << "The Solution of operation is : "<<x*y;
break;
case '+':
cout << "The Solution of operation is : "<<x+y;
break;
case '-':
cout <<"The Solution of operation is : "<<x-y;
break;
case '%':
cout <<"The Solution of operation is : "<<x % y;
break;
default:
cout << "The operator you entered is not correct";
break;
}
return 0;
}
Output:

Task no 5:
Program:
#include<iostream>
using namespace std;
int main()
{
cout<<"Giving the state of water at given temperature"<<endl;
float t;
cout<<"\nEnter the temperature in degree celcius : ";
cin>>t;
cout<<"\nResult:"<<endl;
switch(t<0)
{
case 1:
cout<<"The water is in the state of ice at "<<t<<" degree
celcius."<<endl;
break;
case 0:
switch(t>100)
{
case 1:
cout<<"The water is in the state of stream at "<<t<<" degree
celcius."<<endl;
break;
default:
cout<<"The water is in the state of liquid at "<<t<<" degree
celcius."<<endl;
}
}
return 0;
}
Output:

You might also like