Muhammad Zain Masood Lab 4 Tasks..
Muhammad Zain Masood Lab 4 Tasks..
Muhammad Zain Masood Lab 4 Tasks..
ENROLLMENT : 02-235192-010
Semester : FALL (2019)
Section : BS (IT) 1-A
Subject : Computer Programming
Lab:04 TASK 4
Code:
#include <iostream>
int main ()
int num, a;
float amount, b;
cin>> num;
a=num+amount ;
b=num+amount ;
else
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>
int main()
// declraing varaibales
int a;
//Input
cout << "Enter month in numeric form (1-12) " << endl;
cin >> a;
//If else
if (a == 1)
else if (a == 2)
else if (a == 3)
else if (a == 4)
else if (a == 6)
else if (a == 7)
else if (a == 8)
else if (a == 9)
else if (a == 10)
else if (a == 11)
else if (a == 12)
else
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>
int main()
//Declaring variables
float a, b, c, d ,e,f;
int x;
//Input
cin >> a;
cin >> c;
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;
cin >> x;
//IF else
if (x==1)
//Smallest Number
else
else if ( x==2)
//Largest Number
else
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;
Screen shot:
Code:
#include <iostream>
int main()
//Declaring variables
float a, b, c, d, e;
int x, g, h;
//Input
cin >> a;
cin >> b;
cin >> c;
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;
cin >> x;
//IF else
//Smallest number
g = a;
g = b;
else
g = c;
//Largest
h = 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;
Screen shot: