Lab#5

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

LAB NO.

5 DD/MM/YYYY

CONDITIONAL STATEMENTS (if, else, else if)


Lab outcomes:
After completing this lab, students will be able to:
 Implement if, else, and else if statements in C++.

Corresponding CLO and PLO:


 CLO-2, PLO-3 (Design and Development of Solutions)
Theory:
Conditional statements are used in programming to make decisions based on certain conditions.
In C++, the most commonly used conditional statements are if, else, and else if.
The if statement is used to execute a block of code if a certain condition is true. The basic syntax
of the if statement in C++ is as follows:
if (condition) {
// code to be executed if condition is true
}
The condition is an expression that evaluates to either true or false. If the condition is true, the
code inside the curly braces will be executed.
The else statement is used in conjunction with the if statement to execute a block of code if the
condition in the if statement is false. The basic syntax of the if-else statement in C++ is as
follows:
if (condition) {
// code to be executed if condition is true
} else {
// code to be executed if condition is false
}
If the condition in the if statement is false, the code inside the else block will be executed.
The else if statement is used to test multiple conditions. It is used when there are multiple
possible outcomes based on different conditions. The basic syntax of the if-else if statement in
C++ is as follows:
if (condition1) {
// code to be executed if condition1 is true
} else if (condition2) {
// code to be executed if condition2 is true
} else {
// code to be executed if all conditions are false
}
If condition1 is true, the code inside the first if block will be executed. If condition1 is false and
condition2 is true, the code inside the else if block will be executed. If both conditions are false,
the code inside the else block will be executed.

Activities:
Activity 5.1: Write a C++ program to input two numbers from user and find maximum
between two numbers using if else.
Code:
Please write or paste your code snap here.
Output:
Please paste your output screenshot here with your Name and CMS mentioned in it.

Activity 5.2:Write a C++ program to check whether a number is even or odd using if else.
Code:
Please write or paste your code snap here.
Output:
Please paste your output screenshot here with your Name and CMS mentioned in it.
Activity 5.3:Write a program to check whether an integer is positive, negative or zero.
Code:
Please write or paste your code snap here.
Output:
Please paste your output screenshot here with your Name and CMS mentioned in it.
Activity 5.4: Write a C++ program that prompts the user to enter the hour in 24-hour
format and then determines the time of the day. If the entered hour is between 0 and 11
(inclusive), the program should display "Good morning!". If the hour is between 12 and 17
(inclusive), it should display "Good afternoon!". For hours between 18 and 23 (inclusive), it
should display "Good evening!". If the entered hour is outside the valid range, the
program should output "Invalid hour!".
Code:
Please write or paste your code snap here.
Output:
Please paste your output screenshot here with your Name and CMS mentioned in it.

Activity 5.5: Write a program that ask user to enter three numbers, and find the largest
number among them using nested if else.

Code:
Please write or paste your code snap here.
Output:
Please paste your output screenshot here with your Name and CMS mentioned in it.

Observations:
Please write your observation after conducting this lab, you have to write in few lines, what did
you learn in this lab.
Rubrics
Absent Student is Student can Student has Student has Student
unable to understand followed constructed perfectly
follow the the provided instructions to the implemented a
provided laboratory construct the functional/ working
instructions instructions fundamental working model/ logic/
and familiar schematic/ schematic/ circuit/ block
properly.
The student can with the lab block model/ block diagram/ code
name the environment diagram/ diagram/ and
\ hardware or (Trainer/ code/ model code, and successfully
Demonstration simulation software/ on the have executed the
platform, but IDE), but protoboard/ successfully lab objective
unable to cannot trainer/ executed the in Realtime or
implement implement on simulation program/ in a
anything the software. run circuit simulation
practically or platform on software environment
on the software practically or platform and produced
on the the desired
software results
Category Ungraded Very Poor Poor Fair Good Excellent
Percentage [0] [1-20] [21-40] [41-60] [61-80] [81-100]
Marks 0.0 0.01 - 0.20 0.21 - 0.40 0.41 - 0.60 0.61 - 0.80 0.81 - 1.0
Date Total Marks Instructor’s Signature

Report not Plagiarized Requirements Observations Appropriate Correctly


submitted content are listed and are recorded computations drawn
experimental or numerical
presented or along with conclusion
analysis is
Laboratory incomplete procedure is detailed with
performed
Reports submission presented procedure exact results
and complete
report in all
respects

Category Ungraded Very Poor Poor Fair Good Excellent


Percentage [0] [1-20] [21-40] [41-60] [61-80] [81-100]
Marks 0.0 0.01 - 0.20 0.21 - 0.40 0.41 - 0.60 0.61 - 0.80 0.81 - 1.0
Date Total Marks Instructor’s Signature

You might also like