0% found this document useful (0 votes)
10 views8 pages

Adilzhan Mustafin Lab2

The document outlines Lab 2 for System Level Programming, focusing on understanding relational and equality operators, control structures, and various conditional statements in C++. It includes tasks that require students to analyze code outputs, differentiate operators, and write programs for specific scenarios such as determining odd/even numbers and implementing a basic calculator. Additionally, it provides guidelines for submitting the lab journal with specific naming conventions.

Uploaded by

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

Adilzhan Mustafin Lab2

The document outlines Lab 2 for System Level Programming, focusing on understanding relational and equality operators, control structures, and various conditional statements in C++. It includes tasks that require students to analyze code outputs, differentiate operators, and write programs for specific scenarios such as determining odd/even numbers and implementing a basic calculator. Additionally, it provides guidelines for submitting the lab journal with specific naming conventions.

Uploaded by

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

Lab 2

System Level Programming Lab

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:

a) PC with Windows 7 Professional or onwards


b) Visual Studio 2013 onwards

Attempt the following tasks:

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

Print the output of following expressions Output:


2. 00111
(each line of code) as 1 and 0 (1 for “True”
and 0 for “False”).
(5 + 4 < 3)

('a' != 'b' - 1)

(7 == 7)

System Level Programming


Page 1
Lab 2

(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;

4. Differentiate between = and ==. “=” is assignment operator and “==” is


equality operator
5. int x = 25; Output:
if (x / 2 == 12) I likeapples
{
cout << "I ”;
cout << "like";
}
else
{
cout << "I ";
cout << "don’t like";
}
cout << "apples";

6. double Max =12.7; Output:


if(Max>=12) French
cout<<”French”;
else
cout<<”Fries”;

7. int x = 12; Output:


if(x!=12) No
cout << “Yes”;
else
cout << “No”;

System Level Programming


Page 2
Lab 2

8. int x = 13; Output:


if(x>12) BlueJeans
{
if(x<15)
cout<<”Blue”;
}
Else
{
cout<<”Green”;
}
cout<<”Jeans”;

9. int x = 20; Output:


if(x>10) Happy Day!
{
if(x<25)
cout<<”Happy ”;
}
Else
{
cout<<”Not Happy ”;
}
cout<<” Day!”;
10. Write C++ statement for following pseudocode:

if number is divisible by 2
print “even”
else
print “odd”
Using if/else statement: Output:

int number; depends on input prints odd or even


cin >> number;
if(number % 2 == 0)
cout << "even";
else
cout << "odd";

System Level Programming


Page 3
Lab 2

11. cout<<”Hi there!\n”; Hi there!


goto Label; Hope you are good!
cout<<”How are you?\n”;
cout<<”Are you feeling better?\n”;
label:
cout<<”Hope you are good!”;

12. cout << "I'm at line 1\n"; I'm at line 1


goto Point1; I'm at line 4
cout << "I'm at line 2\n";
cout << "I'm at line 3\n";
Point1:
cout << "I'm at line 4\n";

13. int x = 10; 10


cout<<x<<endl; 11
12
x++;
11
cout<<x<<endl; 10
++x;
cout<<x<<endl;
x--;
cout<<x<<endl;
--x;
cout<<x<<endl;

14 int x = 10; 10
cout<<x<<endl; 10
12
cout<<x++<<endl;
12
cout<<++x<<endl; 10
cout<<x--<<endl; 10

System Level Programming


Page 4
Lab 2

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.

System Level Programming


Page 5
Lab 2

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.

System Level Programming


Page 6
Lab 2

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

Press 1 for addition


Press 2 for subtraction
Press 3 for multiplication
Press 4 for division
Press 5 for finding the remainder

Note: Perform Task 5 with both if-else and switch statements.

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.

System Level Programming


Page 7
Lab 2

 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 😊
****************************************************

System Level Programming


Page 8

You might also like