Lab Manual 02 - Single & Multi Line Comment, Cout & Cin Statements
Lab Manual 02 - Single & Multi Line Comment, Cout & Cin Statements
Lab- 02 Manual
Lab Instructor: Riaz Ahmad
Department of Computer Science
Email: [email protected]
Lab 02: Single Line Comment, Multi line Comment, cout and cin Statements
Table of Contents............................................................................................................................1
2.1 Objective:...............................................................................................................................................2
2.2 Scope:.....................................................................................................................................................2
2.3 Useful Concepts:....................................................................................................................................2
2.4 Examples................................................................................................................................................3
2.5 Lab Exercise:.........................................................................................................................................7
2.6 Home Work:..........................................................................................................................................7
Lab Rubrics
2.1 Objective:
To familiarize the students with the use of single line comment, multi- line comment cout and
cin statements.
2.2 Scope:
The student should know the following at the end of this lab:
1. Problem Solving
2. How to use cout and cin statements
3. Single & Multi line comments
4. Invalid nesting of multi line comments
5. Writing Complete Programs
2.3 Useful Concepts:
Cout: The statements cout is used to print the “character, string, float, integer, octal and
hexadecimal values” onto the output screen.
Escape character (\)
Special characters used to control the format of the output.
Characters are not displayed in the output.
Always begin with backslash "\".
backslash ( \ ) is called an escape character.
2.4 Examples
Example 2.1: This program demonstrates the use of cout and the basic structure
of a C++ program.
Example 2.2: This program illustrates the use of single line (//text) and multiline
comments (\* text *\).
Example 2.3: This program illustrates the use of nested multi line comments in cout
statements.
Example 2.4: This program illustrates the use of cin for integer value.
Example 2.5: This program illustrates integer addition. Also note the syntax
necessary for the use of cin.
Example 2.6: This program illustrates more examples of cin and cout statements.
Exercise 2.2: Write a program that prints the following diagram using cout statement.
*********
* *
* *
*********
2.6 Home Work:
Task 1: Write a program that take six subjects marks from user and display the sum of all marks.
Task 2: Write a program to calculate and print the area of circle where as radius is equals to 3.