This document summarizes a lab session on fundamental computer science topics presented by TA Nada Kamel. The agenda includes an introduction to ASCII tables, relational operators like equality and inequality, logical operators like AND and OR, and if/else conditional statements. Examples are provided of single and multiway if/else conditional logic. Hands-on problems are presented for students to practice writing programs that use conditionals to output whether a number is even or odd, and to calculate hospital billing amounts based on room type and optional services.
6. Relational Operators
Relational Operator Description
== Equal to
!= Not equal to
< Less than
> Greater than
<= Less than or equal to
>= Greater than or equal to
Presented by TA. Nada Kamel
12. Boolean Expressions
if (a == 5)
an expression to check if the value of a is equal to 5
if (a*b >= c)
an expression to check if the value of a multiply by b is greater than or equal to
the value of c
if (my_char == ’s’)
an expression to check if the value of my_char is equal to ‘s’
if (a == 8 && b == 3)
an expression to check if the value of a is equal to 8 and the value of
b is equal to 3
Presented by TA. Nada Kamel
14. Multiway if/else
if(boolean_expression_1)
{
// statements to be executed if the first boolean expression is true
}
else if(boolean_expression_2)
{
// statements to be executed if the first boolean expression is false and the
second boolean expression is true
}
..
..
else
{
// statements to be executed if all test expressions are false
}
Presented by TA. Nada Kamel
16. Example
Write a program in C++ that reads three scores of a student in
three tests to compute and display the largest score.
Presented by TA. Nada Kamel
19. Problem 1
Write a program in C++ that reads a positive integer number to
notify the user with a message whether the integer number Even
or Odd.
Presented by TA. Nada Kamel
20.
21. Problem 2
Community Hospital needs a program to compute and print a statement for each
patient.
Charges for each day are as follows:
a) Room charges: private room, $125.00; semiprivate room, $95.00; or ward, $75.00
b) Telephone charge: $1.75
c) Television charge: $3.50
Write a program to get one string of four characters from the keyboard, the first
character is an integer value indicating the number of days spent in the hospital,
and the others are three alphabet characters.
Typical input is: 5PNY
where 5 indicates the number of days spent in the hospital, P represents the room
type (P, S, or W), N represents the telephone option (Y or N), and Y represents the
television option (Y or N).
Presented by TA. Nada Kamel