You are on page 1of 2

LAB 4– C++ BUILDING BLOCKS-I

Learning Objectives
In today’s lab, you will practice;
1. Indenting your code.
2. Writing comments in your code.
3. Declaring variables (int, float and char).
4. Using two of the C++ language’s most commonly used built-in functions namely cin and
cout with/without using variables.
5. Using basic arithmetic operators available in C++ ( +, - ,* , / ).
6. Using escape sequences in cout statements.

Practice Questions
You can practice the following problems in this lab.
Task 1.1 Declaring Variables
Write a C++ program, which declares integer ‘a’, float ‘b’ and character ‘c’. Ask user for an
integer value and store it in ‘a’, for a float value and store it in ‘b’ and for a character value
and store it in ‘c’. At the end, print the values of these three variables on screen. Your output
should be as below. Indent your code and include comments for improving the readability of
your code.
Enter Integer Value: 448
Enter Float Value: 32.65
Enter Character Value: A
***** You have entered the following values *****
Integer Value is: 448
Float Value is: 32.65
Character Value is: A

Task 1.2 Arithmetic Operations on Variables +, -, *, / , %


Write a C++ program which takes two int values from user and computes their sum, difference,
product, quotient and remainder. At the end, print these results on screen with a beep. Your
output should be as below. Indent your code and include comments for improving the
readability of your code.

Enter Value 1: 50
Enter Value 2: 50
Sum : 50 + 50 = 100
Difference : 50 – 50 = 0
Product : 50 * 50 = 2500
Quotient : 50 / 50 = 1
Remainder : 50 % 50 = 0
Task 1.3 Cout Statement with Escape Sequences
By using different escape sequences, write a C++ program, which displays the following
output. After every line, your program must generate a beep. If you already do not know the
escape sequence for generating a beep, find it out for yourself. Indent your code and include
comments for improving the readability of your code.

MCS
MCS
MCS
MCS

MCS

Task 1.4 Cout Statement with Escape Sequences


Write a C++ program, which generates the following output. After displaying the output, 5
beeps must be generated. Indent your code and include comments for improving the readability
of your code.

This is a test.
He asked, “How are you doing?”
“Education is the most powerful weapon which
you can use to ‘CHANGE’ the world”.
S

Web Resources

http://www.cprogramming.com/
http://www.mycplus.com/featured-articles/top-10-applications-written-in-c-cplusplus/
http://www.cplusplus.com/doc/tutorial/program_structure/
http://www.cplusplus.com/doc/tutorial/variables/
http://www.cplusplus.com/doc/tutorial/constants/
http://www.cs.wustl.edu/~schmidt/C++/

You might also like