Adilzhan Mustafin Lab2
Adilzhan Mustafin Lab2
Lab Journal - 2
Name: Adilzhan Mustafin
Group #: IT2-2102
Objective:
1) Understanding of relational and equality operators
2) Understanding Control Structures
3) Using if, if/else, multiple ifs/else-if, switch statements and ternary operator
Tools Required:
Task 1 : Give output of the following piece of code (First dry run and type output. After
that compile these codes to see your results.):
1. int a=5, b =10; Output:
0
cout << (a > b) << endl;
1
cout << (a < b) << endl;
cout << (a == b) << endl; 0
cout << (a != b) << endl; 1
('a' != 'b' - 1)
(7 == 7)
(3%2 == 1)
('a' == 97)
3. int a=5, b=10, c=15; ; Output:
0
cout << ((a > b) && (c > b)) <<
1
endl;
cout << ((a > b) || (c > b))<< 1
endl; 1
cout << (a || b) << endl; 1
cout << (a && b) << endl;
cout << !(a > b) << endl;
if number is divisible by 2
print “even”
else
print “odd”
Using if/else statement: Output:
14 int x = 10; 10
cout<<x<<endl; 10
12
cout<<x++<<endl;
12
cout<<++x<<endl; 10
cout<<x--<<endl; 10
cout<<--x<<endl;
cout<<x<<endl;
Note : For all following questions. Type code in compiler. take screenshot of code as well as
output screen.
Task 2 : Write a C++ program that reads an integer and determines and prints whether it is odd
or even using if-else statements.
Task 3 : Write a C++ program that reads an integer and determines and prints whether it is odd
or even using switch statements.
Task 4 : Write a program that reads three non zero integers and determines and prints whether
they could be the sides of a right angle triangle. (Hint* : Pythagorus Theorem a2 + b2 = c2 )
So your program should take three variables a, b and c and check that the sum of square of a and
square of b should be equal to the square of c.
Task 5&6: Write a program for a basic calculator. Your calculator should take two integers.
Then it should display options for different operations and then ask the user for choice. Based on
user’s choice it will perform the operation. The options will be displayed as following
Task 7 : Write a C++ program (use if-else statement) to compute the telephone bill for the city
consumers. The bill computed according to the number of calls.
If numbers of calls are less than and equal to 100, then the rate per call is rs.0.80 and the
meter charges is Rs. 250.
If numbers of calls are greater than 100, then the rate per call is computed is Rs. 1.00 and
the meter charges are minimum Rs.350.
Formula for bill calculation is:
Phone Bill = meter charges + (number of calls x rate per call)
: Always “save as” this file with your name + Registration no and then
submits it as Assignment.
Good Luck 😊
****************************************************