0% found this document useful (0 votes)
2 views

Lab Manual 02 - Single & Multi Line Comment, Cout & Cin Statements

The Lab Manual for Programming Fundamentals at the University of Management and Technology outlines objectives, scope, and useful concepts related to single line and multi-line comments, as well as cout and cin statements. It includes examples, lab exercises, and homework assignments to reinforce learning. The manual also provides a rubric for assessing students' understanding of programming structures and problem-solving skills.

Uploaded by

irha.mustafa2011
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)
2 views

Lab Manual 02 - Single & Multi Line Comment, Cout & Cin Statements

The Lab Manual for Programming Fundamentals at the University of Management and Technology outlines objectives, scope, and useful concepts related to single line and multi-line comments, as well as cout and cin statements. It includes examples, lab exercises, and homework assignments to reinforce learning. The manual also provides a rubric for assessing students' understanding of programming structures and problem-solving skills.

Uploaded by

irha.mustafa2011
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/ 7

Lab Manual: Programming Fundamentals

University of Management and Technology,


Lahore Campus

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

Identify key programming


Areas Problem Understanding structures such as variables, Design/ Development of Solutions
Assesse loops, and functions.
d (CLO 1) (CLO 2) (CLO 3)
No able to identify key
Not able to understand Not able to Model a solution for a
Poor programming structures such as
Problem given problem
variables, loops, and functions.

Partially able identify key Modeled an average solution


Able to partially
Average programming structures for a given problem using
understand the
such as variables, loops, and programming principles
problem
functions.

Thoroughly identify key


Modeled a proper solution for a
Very Good Fully Understand the problem programming structures
given problem using programming
such as variables, loops, and
principles
functions.

Department of Computer Science, UMT, Lahore. 1 Riaz Ahmad


Lab Manual: Programming Fundamentals

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.

Escape Sequences Character


*
\b Backspace 1 2 3 4 5
**
\f Form feed / new page *** 6 7 8 9 10
\n Newline ****
\r Return Pakistan is my country
\t Horizontal tab Islamabad is its capital
\v Vertical tab
\a Alert
\\ Backslash
\' Single quotation mark
\" Double quotation mark
\? Question mark
\0 Null character

Department of Computer Science, UMT, Lahore. 2 Riaz Ahmad


Lab Manual: Programming Fundamentals
Cin: The statements cin obtains a value from the user using standard input (usually
keyboard) When executing the program, the user responds to the cin statement by
typing in a character from keyboard, then pressing the enter (return) key. A variable
is used to store the entered value.

Single line comments


 Text after // till next line is ignored by computer.
 Used to describe program.
Multi line comments
 Text surrounded by /* and */
 Used to describe program.

2.4 Examples

Example 2.1: This program demonstrates the use of cout and the basic structure
of a C++ program.

Here’s the program’s output:

Department of Computer Science, UMT, Lahore. 3 Riaz Ahmad


Lab Manual: Programming Fundamentals

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.

Department of Computer Science, UMT, Lahore. 4 Riaz Ahmad


Lab Manual: Programming Fundamentals

Here’s the program’s output:

Example 2.4: This program illustrates the use of cin for integer value.

Here’s the program’s output:

Department of Computer Science, UMT, Lahore. 5 Riaz Ahmad


Lab Manual: Programming Fundamentals

Example 2.5: This program illustrates integer addition. Also note the syntax
necessary for the use of cin.

Here’s the program’s output:

Example 2.6: This program illustrates more examples of cin and cout statements.

Here’s the program’s output:

Department of Computer Science, UMT, Lahore. 6 Riaz Ahmad


Lab Manual: Programming Fundamentals

2.5 Lab Exercise:


Exercise 2.1: Write a program to display:
Your name:
Your ID:
Your Course name:

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.

Department of Computer Science, UMT, Lahore. 7

You might also like