Muhammad Zain Masood Lab 4 Tasks..

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 61

Name : Muhammad Zain Masood

ENROLLMENT : 02-235192-010
Semester : FALL (2019)
Section : BS (IT) 1-A
Subject : Computer Programming
Lab:04 TASK 4

Code:
#include <iostream>

using namespace std;

int main ()

int num, a;

float amount, b;

cout<<"enter your number : " ;

cin>> num;

cout<<"enter the amount : " ;


cin>> amount;

a=num+amount ;

b=num+amount ;

// using if else statement

if ( a>16 && b> 16)

cout<<"value of a & b > 16" ;

else

cout<<"value of a & b < 16" ;

Screen shot:

code:
#include <iostream>
using namespace std;
int main()
{
int a,b,c ;
cout<<"enter the first value : " ;
cin>>a;
cout<<"enter the second value : " ;
cin>>b;
cout<<"enter the third value : " ;
cin>>c;
cout<< endl ;
//using if else statement
if (a<b && a<c)
{
cout<<" the smallest value is : " <<a <<endl ;
if (b<a && b<c)
cout<<"the smallest number is : " <<a <<endl ;
}
else
cout<<"the smallest number is : " <<c ;
}
Screen shot:

Code:
#include <iostream>
using namespace std;
int main ()
{
char a,e,i,o,u ;
cout<<"enter the alphabet : " ;
cin>>a ;
if (a=a)
{
cout<< "the alphabet is vowel" ;

if (a=e)
cout<< " the alphabet is vowel ";

if (a=i)
cout<< "the alphabet is vowel " ;

if (a=o)
cout<< " the alphabet is vowel" ;

if(a=u)
cout <" the alphabet is vowel" ;
}
else
cout<< " the alphabet is constant " ;
}
Screen shot:

Code:
#include <iostream>
using namespace std;
int main()
{
int a ;
cout<< "enter the number : " ;
cin>>a;
cout<< endl;
if (a%2)
cout<<"it is odd number " ;
else
cout<<"it is even number " ;

}
Screen shot:
Code:
#include <iostream>

using namespace std;

int main()

// declraing varaibales

int a;

//Input

cout << "Enter month in numeric form (1-12) " << endl;

cin >> a;

//If else

if (a == 1)

cout << "January" << endl;

else if (a == 2)

cout << "February" << endl;

else if (a == 3)

cout << "March" << endl;

else if (a == 4)

cout << "April" << endl;


else if (a == 5)

cout << "May" << endl;

else if (a == 6)

cout << "June" << endl;

else if (a == 7)

cout << "July" << endl;

else if (a == 8)

cout << "August" << endl;

else if (a == 9)

cout << "September" << endl;

else if (a == 10)

cout << "October" << endl;

else if (a == 11)

cout << "November" << endl;

else if (a == 12)

cout << "December" << endl;

else

cout << "Enter valid number" << endl;

Screen shot:
Rewrite program 5 again using switch statement:
Code:
#include <iostream>
using namespace std;
int main()
{
int a;
//Input
cout << "Enter month in numeric form (1- till 12) "
<< endl;
cin >> a;
//Switch
switch (a)
{
case 1:cout << "January" << endl;
break;
case 2:cout << "February" << endl;
break;
case 3:cout << "March" << endl;
break;
case 4:cout << "April" << endl;
break;
case 5:cout << "May" << endl;
break;
case 6:cout << "June" << endl;
break;
case 7:cout << "July" << endl;
break;
case 8:cout << "August" << endl;
break;
case 9:cout << "September" << endl;
break;
case 10:cout << "October" << endl;
break;
case 11:cout << "November" << endl;
break;
case 12:cout << "December" << endl;
break;
default :cout << "Enter valid number" << endl;
}

}
Screen shot:
Code:
#include <iostream>

using namespace std;

int main()

//Declaring variables

float a, b, c, d ,e,f;

int x;

//Input

cout << " Enter first number " << endl;

cin >> a;

cout << " Enter 2nd number " << endl;


cin >> b;

cout << " Enter 3rd number " << endl;

cin >> c;

cout << endl;

cout << endl;

cout << endl;

cout << "# Enter 1 to find out smallest number" << endl;

cout << "# Enter 2 to find out Largest number" << endl;

cout << "# Enter 3 to find out sum of numbers" << endl;

cout << "# Enter 4 to find out average of number" << endl;

cout << "# Enter number to select the function = ";

cin >> x;

cout << endl;

cout << endl;

cout << endl;

//IF else

if (x==1)

//Smallest Number

cout << endl;

if ((a < b) && (a < c))

cout << a << " is the smallest number" << endl;


else if ((b < a) && (b < c))

cout << b << " is the smallest number" << endl;

else

cout << c << " is the smallest number" << endl;

else if ( x==2)

//Largest Number

cout << endl;

if ((a > b) && (a > c))

cout << a << " is the largest number" << endl;

else if ((b > a) && (b > c))

cout << b << " is the largest number" << endl;

else

cout << c << " is the largest number" << endl;

else if (x == 3)

//Average

d = a + b + c;

e = d / 3;

cout << e << " is the average of given numbers " << endl;
}

else if (x == 4)

//Sum

f = a + b + c;

cout << f << " is the sum of the 3 given numbers" << endl;

else

cout << " Enter right values or I cant run (*_*)" << endl;

cout << endl;

Screen shot:
Code:

#include <iostream>

using namespace std;

int main()

//Declaring variables

float a, b, c, d, e;

int x, g, h;

//Input

cout << " Enter first number " << endl;

cin >> a;

cout << " Enter 2nd number " << endl;

cin >> b;

cout << " Enter 3rd number " << endl;

cin >> c;

cout << endl;

cout << "# Enter 1 to find out smallest number" << endl;

cout << "# Enter 2 to find out Largest number" << endl;

cout << "# Enter 3 to find out sum of numbers" << endl;
cout << "# Enter 4 to find out average of number" << endl;

cout << "# Enter number to select the function = ";

cin >> x;

cout << endl;

//IF else

//Smallest number

if ((a < b) && (a < c))

g = a;

else if ((b < c) && (b < a))

g = b;

else

g = c;

//Largest

if ((a > b) && (a > c))

h = a;

else if ((b > c) && (b > a))

h = b;

else

h = c;

//Sum

d = a + b + c;

//Average
e = d / 3;

//Switch

switch (x)

case 1: cout << g << " is the smallest number " << endl;

break;

case 2: cout << h << " is the largest number " << endl;

break;

case 3: cout << d << " is the sum of given numbers " << endl;

break;

case 4: cout << e << " is the average of numbers " << endl;

break;

default:

cout << "Enter a the right values or other wise we cant operate " <<
endl;

cout << endl;

Screen shot:

You might also like