0% found this document useful (0 votes)
127 views

Fop If Else

The document is a lab report containing questions and code snippets related to conditional (if-else) statements in C++. It contains: 1) Code to check if hours entered is greater than 18 and print a corresponding message. 2) Code to check if a classification variable equals 5, and set a type variable to 'G' or 'U' and print a message. 3) Code to check if a value entered for x is less than or equal to 10 and print "small" or "big". 4) Multiple code snippets with if-else conditions to check values of variables and temperatures entered and print appropriate messages.

Uploaded by

AGN Studios
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
127 views

Fop If Else

The document is a lab report containing questions and code snippets related to conditional (if-else) statements in C++. It contains: 1) Code to check if hours entered is greater than 18 and print a corresponding message. 2) Code to check if a classification variable equals 5, and set a type variable to 'G' or 'U' and print a message. 3) Code to check if a value entered for x is less than or equal to 10 and print "small" or "big". 4) Multiple code snippets with if-else conditions to check values of variables and temperatures entered and print appropriate messages.

Uploaded by

AGN Studios
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Introduction to Computer Programming (EE)

Lab Report on If else Fop


23Oct 2019
LAB REPORT
Question no 1
1. If hours are greater than 18, print a message saying "This is an overload";
otherwise print a message saying "Not an overload".

#include<iostream> //It is preprocessor directive

using namespace std; //It is a grouping identifier

int main() //Main function

int a; //Defining the integer a

cout<< "Enter number of hours = "; //It will display a message to give hours

cin>>a; //It will take input as variable a from user

if(a>18) //condition if a is greater than 18

cout<<" This is an overload "; //It will show a message that it is an overload

else //If the above statement is not satisfied

cout<<"Not an overload"; //It will show a message it is not


an over load}

}
Muhammad Tayyab Gulzar Page 1
Introduction to Computer Programming (EE)

IF hours are greater than 18

If hours are less than 18

Muhammad Tayyab Gulzar Page 2


Introduction to Computer Programming (EE)

Question no 2
2. If classification is equal to 5 then set the character variable Type equal to 'G',
and print a message saying "graduate student"; otherwise set Type equal to 'U'
and print a message saying "undergraduate".

#include<iostream>//It is preprocessor directive

using namespace std;//It is a grouping identifier

int main()//Main function

string Type;

int Classification; //Defining class as integral variable

cout<<"Enter the educational calssification : "; //It will display Statement


inside Inverted commas

cin>>Classification; //Ask value of classifiction from user

if( Classification==5 ) //Condition i.e, if classification =5

{cout<<"Graduate student "; //It will display Graduate Student

Type ="G"; } //String type will be G

else //If above statement is not true

{cout<<"Undergraduate student "; //It will display Undergraduate

Type ="U"; } //String type will be G

Muhammad Tayyab Gulzar Page 3


Introduction to Computer Programming (EE)

If classification is equal to 5

If Classification is not equal to 5

Muhammad Tayyab Gulzar Page 4


Introduction to Computer Programming (EE)

Question no 3

3. After execution of the following code, what will be printed if x is 10?


if (x <= 10)
cout << "small";
else
cout << "big";
ANS:

#include<iostream>//It is preprocessor directive


using namespace std; //It is a grouping identifier
int main()//Main function
{
int x; //Defining variable x
cout<<"Enter value of x : "; //IT WILL DISPLAY enter value of x
cin>>x; //It will ask value of x from user
if (x <= 10) //Condition if x is less than equal to ten
cout << "small"; //It will print small
else //If above condition is not satisfied
cout << "big"; //It will print big
}

If x is 10 then

It will print small

Muhammad Tayyab Gulzar Page 5


Introduction to Computer Programming (EE)

Question no 4
1. After execution of the following code, what will be the value of x?
x = 30;
y = 20;
if (y != (x - 10))
x = x - 5;
else
x = y;
#include<iostream> //It is preprocessor directive

using namespace std; //It is a grouping identifiers

int main() //Main function

int x,y; //Defining variables x and y

x = 30; //value of x is x=30

y = 20; //value of y is y=20

if (y != (x - 10)) //Condition if y is not equal to x-10

x = x - 5; //Then x will be equal to x-5

else //If condition is not satisfied

x = y; //Then x=y

cout<<"Value of x = "<<x; //It will print value of x and show its value

Muhammad Tayyab Gulzar Page 6


Introduction to Computer Programming (EE)

Question no 5

#include<iostream> //It is preprocessor directive

using namespace std; //It is a grouping identifiers

int main() //Main function

int c,f; //Defining integers c and f

cout<<"Enter temperature in Celcius :"; //It will display statement in inverted commas

cin>>c; //It will ask value for c from user

cout<<"Enter temperature in Farenheit :"; //It will display statement in inverted commas

cin>>f; //It will ask value for d from user

if (c>40 || f>60) //Multiple condition

cout<<"It is hot day "; //It will display statement in inverted commas

else if ((c>25 && c<35)|| ( f>30 && f<50 ) ) //Multiple condition

cout<<"Its Normal weather"; //It will display statement in inverted commas

else if (f<60 && c>30) //Multiple condition

cout<<"Its moderate"; //It will display statement in inverted commas

else if (((c> 20) && (c<22)) || ((f>25) && (f<27))) //Multiple condition

{ cout<<"It is Ideal Weather"; //It will display statement in inverted commas

Muhammad Tayyab Gulzar Page 7


Introduction to Computer Programming (EE)

else if (f<28 || c<25) //Multiple condition

cout<<"It is cold day"; //It will display statement in inverted commas

else //If all above statements are unsatisfied

cout<<"Invalid Temperature"; //It will display statement in invalid temperature

a. If temp in C is greater than 40, display “It is hot day”.

b. If temp in C is between 25 and 35 , display “Its Normal weather”

Muhammad Tayyab Gulzar Page 8


Introduction to Computer Programming (EE)

c. If temp in C is less than 25 ,display “ It is cold today”

d. If temp in F is greater than 60 , display “it is hot today”

e. If temp in F is less than 60 than display “It is moderate” if and only if


temp in C is greater than 30.

Muhammad Tayyab Gulzar Page 9


Introduction to Computer Programming (EE)

f. If temp in F is in between 30 and 50, display “ Its Normal weather”

g. If temp in F is less than 28, display “it is cold day” regardless of the
value of C.

h. If temp in C is between 20 and 22 and temp in F is in between 25 and


27 , display “It is Ideal weather”

Muhammad Tayyab Gulzar Page 10


Introduction to Computer Programming (EE)

Question 6

#include<iostream> //It is preprocessor directive

#include<conio.h> //It is preprocessor directive used for getch

using namespace std; //It is a grouping identifiers

int main() //Main function


{

int x; //Defining variable x

cout<<"Enter value of x"<<endl; //It will display statement in inverted commas

cin>>x; //It will ask user for value of x

if(x) //Condition if entered value is an integer

cout<<" Yes"<<endl; //It will display statement in inverted commas

else //If condition is not satisfied

cout<<"NO"<<endl; //It will display No

getch();

If x is an integer

If we put a character

Muhammad Tayyab Gulzar Page 11

You might also like