Lab Report 04
Lab Report 04
Lab Report 04
Title:
Conditional Statements
1ST SEMESTER
Theory :
Relational Expressions :
It consists of constants, variables and arithmetic operations that
are combined by the rational operator. It is used to find the relation between two
expressions. It returns only one value True or False.
Example:
10 < 6 is rational expression with a False value and here < the rational
operator.
Relational operators:
To specify a relation between two expressions or values.
• < Less than
• > Greater than
• <= Less than or equal to
• >= Greater than or equal to
• == Equal to
• != Not equal to
If Statement :
The if statement is used to ignore or execute the set of statements after
testing a condition.
If the condition is true, the statement written below if statement is executed.
If the condition is false, the succeeding statements are ignored and program moves to the
next statements.
If (condition)
Statement 1;
Statement 2;
If Else Statement :
It is another form of If statement. In this statement, one condition and
two blocks of statements are given. If the condition is True, one block executes and if the
condition is False, the other block of statements is executed.
Sometimes code blocks are also succeed the if statement if the required
block has more than one statement.
If (condition)
Statement 1;
Else
Statement 2;
If (condition 1)
{
If (condition 2)
{
Statement 2;
}
Statement 3;
}
If (condition 1)
Statement 1;
Else if (condition 2)
Statement 2;
Else if (condition 3)
Statement 3;
------------------------------------------------------
------------------------------------------------------
Else if (condition m)
Statement m;
Else
Statement n;
Lab Task :
1. Program to calculate the net amount
2. //Program to calculate the net pay
3. #include<iostream>
4. using namespace std;
5. int main() {
6. float bas,hou,med,con,net;
7. cout<<"Enter the basic Pay ";
8. cin>>bas;
9. if(bas<5000)
10. {
11. med=0.05*bas;
12. con=193;
13. hou=0.45*bas;
14. }
15. else
16. {
17. med=0.02*bas;
18. con=96;
19. hou=0.45*bas;
20. }
21. net=bas+hou+con+med;
22. cout<<"The net pay is "<<net;
23. return 0;
24. }
2. Program using nested if else
//Program by using nested If-Else
#include<iostream>
using namespace std;
int main() {
int a,b;
char op;
cout<<"Enter the 1st integer :";
cin>>a;
cout<<"Enter the 2nd integer :";
cin>>b;
cout<<"Enter the operator :";
cin>>op;
if(op=='+')
cout<<"Addition "<<a+b;
else if(op=='-')
cout<<"Subtraction "<<a-b;
else if(op=='*')
cout<<"Multiplication "<<a*b;
else if(op=='/')
cout<<"Division "<<a/b;
else if(op=='%')
cout<<"Remainder "<<a%b;
else
cout<<"Invalid Input";
return 0;
}
Home Task :
1. Program to calculate marks of student and assign grade.
//Program to calculate the relative grade
#include<iostream>
using namespace std;
int main() {
int mar;
cout<<"Muhammad Usama Tariq CMS ID 366451";