[go: up one dir, main page]

0% found this document useful (0 votes)
373 views32 pages

Programming Using C++: Muhammad Saleem Raza

The document discusses programming in C++ and covers various topics like identifiers, keywords, data types, variables, and integer data types. It provides examples and sample programs to illustrate concepts like declaring and initializing variables, performing arithmetic operations on integer variables, and displaying output. The document is meant as a study guide for a chapter in an Object Oriented Programming using C++ book.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
373 views32 pages

Programming Using C++: Muhammad Saleem Raza

The document discusses programming in C++ and covers various topics like identifiers, keywords, data types, variables, and integer data types. It provides examples and sample programs to illustrate concepts like declaring and initializing variables, performing arithmetic operations on integer variables, and displaying output. The document is meant as a study guide for a chapter in an Object Oriented Programming using C++ book.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 32

GOVERNMENT POSTGRADUATE COLLEGE 0

JHANG 2020
Department of Computer Science

PROGRAMMING IN C++
(It is chapter No. 03,
IT Series book:- Object Oriented
Programming using C++ by Prof. Tasleem Mustafa )
1. Identifiers and their types.
2. Keywords.
3. Data types.
i. Integer Data Type (int) and its qualifiers.
ii. Real Data Type and its qualifiers.
iii. Character Data Type.
4. Integer Underflow and Overflow.
5. Variable, its declaration and initialization.
i. Rules for naming variables.
6. Constants and their types.
7. Operators and their types.
----------------------------------------------------------------------
Note:
Prepare this chapters. If there is any difficulty, contact
me.
Muhammad Saleem Raza
Department of Computer Sciences
Government Postgraduate College, Jhang
0345-4707500,0313-7035400

Programming using c++


smsnanva@gmail.com
AREEHA_ABUTALIB

[COMPANY NAME] | [Company address]

0
GOVERNMENT POSTGRADUATE COLLEGE 1

JHANG
Department of Computer Science

++
PROGRAMMING USING C
QUESTION NO.01:- What is an Identifier? Discuss the two types of
Identifier in C++ Language.
identifier
The unique names used in the program to represent variables,
constants, functions and labels etc. are called Identifiers. We can use number
of characters for the name of an Identifier but only the first 31 characters
are significant to C++-compiler.
Following are the rules for writing a identifier name in C++ language.
First character must be an alphabetic character or underscore.
The identifier name must consist of only alphabet characters, digits or underscore.
The reserved word/keywords cannot be used as identifier name.
TYPES OF IDENTIFIER
There are two types of Identifier in C++-language. These are:
Standard Identifier User defined Identifier
STANDARD IDENTIFIERS
Like keywords, there are many predefined identifiers in C++-language.
The predefined identifier of C++-language used for special purposes in the
source program are called Standard Identifiers.
The names used for standard library functions are standard
Identifiers. In C++-language, cout, cin are objects that are mostly used for
input and output operations. Thus, the objects cin and cout are examples of
Standard Identifiers.
USER DEFINED IDENTIFIERS
The Programmer can define its own identifiers in C++-language
program such as variables, user defined functions and labels etc. The
identifiers defined by the programmer are called user defined identifiers.
Generally, these are the names that a programmer assigns to functions,
variables, data types etc. in the program.
QUESTION NO.02:-What are keywords? Give a list of keywords used
in C++ language.
KEYWORDS C++ -LANGUAGE KEYWORDS
Keywords are the words auto do goto signed Unsigned
break double if sizeof Void
whose meanings have already case else int static Volatile
been explained to the compiler. char enum long struct While
const extern register switch
The keywords are not used for continue float return typedef
default for short union
GOVERNMENT POSTGRADUATE COLLEGE 2

JHANG
Department of Computer Science

variable names in the program. The keywords are also called reserved words.
There are only 32 keywords available in C++ language. Following is the list of
keywords.

QUESTION NO.03:-What is variable? Illustrate with examples.


VARIABLE
A quantity whose value may change during the execution of the program
is called variable. It may be numeric/ non-numeric quantity. It is represented
by a symbol called variable name.

A Variable represents a storage or memory location inside Computer


memory. Data is stored in memory location. Name of the Memory location
i.e. Variable name remains fixed during the program execution but data
stored in that location may changes from time to time.

A variable is also known as object in C++ language. In C++, a variable


name consists of alphabets and digits.

QUESTION NO.04:-Explain the concept of variable name, variable


content and variable address.
Name, content and address of VARIABLE
When any variable is created in the program of C++-language, some
bytes in the computer memory are allocated to it. These bytes are used to
store the value assigned to the variable during the execution of the program.
Suppose we have a variable name “Marks” and data value 75 is
assigned to it. The relationship between variable, content and memory
address is shown.
Variable
0000 content
0001
0002
0003
0004
0008 75
0005
0006
0007
0008 75 Mark
0009
Variable
Address

Memory Memory Locations


Variable
Address Name

Variable name It refers to an Identifier that represents a memory location


Variable content It refers to the value stored in the memory location associated with the variable.
Variable address It refers to the memory location of variable.
GOVERNMENT POSTGRADUATE COLLEGE 3

JHANG
Department of Computer Science

QUESTION NO.05:-Describe Data types used in C++ language.


DATA TYPES
The data type defines a set of values and a set of operations on those
values. Actual values used in a program are called data. Variable type
specifies type of data that can be stored in it. Each variable is declared by its
type. There are 4 basic types of data in C++ language. These are:-
int Integer char Characters
float Floating Point double Large Real Values
DATA TYPES
int 2 Bytes -32,768 to 32,767
short int 2 Bytes -32,768 to 32,767
long int 4 Bytes -2,147,483,648 to 2,147,483,647
unsigned int 2 Bytes 0 to 65,535
unsigned long int 4 Bytes 0 to 4,294,967,295
float 4 Bytes 3.4*10-38 to 3.4* 10+38
long float 8 Bytes 2.2*10-308 to 1.7*10-308
double 8 Bytes 1.7*10-308 to 1.7*10-308
long double 10 Bytes 3.4*10-4932 to 1.1* 10+4932
char 1 Byte -128 to 127

QUESTION NO.06:-Write a note on Integer Data type.


INTEGER DATA TYPE
An integer type data accepts only numeric data. Decimal points and
commas are not allowed in integer data type. There are 5 types of integer
data type in C language. There are:-
 int  short int
 Long int Unsigned int
 Unsigned long
INT
Int data type is used to store integer values. Integer occupies two Bytes
space in the memory and range of values stored in memory is from -32768
to 32767. Maximum and Minimum values for integer data type are specified
in limits.h header file. Minimum integer value is defined by INT_MIN and
Maximum integer value is defined by INT_MAX.
PROGRAM-01
Write a program to assign three values to three integer type variables x,y,z and
display these values on computer screen.
GOVERNMENT POSTGRADUATE COLLEGE 4

JHANG
Department of Computer Science

SOLUTION
#include<conio.h>
#include<iostream.h>
void main(void){ clrscr( );
Value of x is: = 10
int x,y,z; Value of y is: = 15
x=10; Value of z is: = 20

y=15;
z=20;
cout<<" Value of x is:= "<< x<<endl;
cout<<"Value of y is:= "<<y <<endl;
cout<<"Value of z is:= "<<z <<endl;
getch ( ); }
PROGRAM-02
Write a program to perform arithmetic operations on integer data values by using
all arithmetic operators.
SOLUTION
#include<conio.h>
#include<iostream.h>
void main(void){ clrscr( );
int a, b, c, d , r ;
a=5+2; Addition is: = 7
Subtraction is: = 3
b=5-2; Multiplication is: =10
c=5*3; Division is: =2
Remainder is:=1
d=5/2 ;
r=5%2;
cout<<" Addition is :="<< a<<endl;
cout<<" Subtraction is := "<<b<<endl;
cout<<" Multiplication is :="<<c<<endl;
cout<<" Division is :="<<d<<endl;
cout<<" Remainder is :="<<r<<endl;
getch ( ); }

PROGRAM -03
Write a program in C++ language to display Maximum and Minimum Ranges
for integer variable.
SOLUTION Minimum value for int variable is: = -32768
#include<conio.h> Maximum value for int variable is: = 32767
#include<iostream.h>
#include<limits.h>
void main(void) { clrscr( );
GOVERNMENT POSTGRADUATE COLLEGE 5

JHANG
Department of Computer Science

int min, max;


min= INT_MIN;
max =INT_MAX;
cout<<"Minimum value for int variable is:="<<min<<endl;
cout<<"Maximum value for int variable is:="<<max<<endl;
getch( ); }
SHORT INT
Short int data type is used to store integer values. Short int occupies two
bytes space in memory. The range of values stored in the memory for short
int data type is from (-32768 to 32767). Maximum and minimum values for
short int data type are defined in limits.h header file. Minimum short integer
value is defined by SHRT_MIN and Maximum short integer value is defined
by SHRT_MAX.

PROGRAM -04
Write a program in C++ language to display Maximum and Minimum Ranges
for short integer variable.
SOLUTION
#include<conio.h>
#include<iostream.h> Minimum value for short int is: = -32768

#include<limits.h> Maximum value for short int is: = 32767

void main(void) { clrscr( );


short int min, max;
min= SHRT_MIN;
max =SHRT_MAX;
cout<<" Minimum value for short int is:="<<min<<endl;
cout<<"Maximum value for short int is:="<< max<<endl;
getch( ); }
PROGRAM-05
Write a program to display sum and product of two integer numbers of short
data type.
SOLUTION Sum of two numbers is: = 25
#include<conio.h> Product of two numbers is: =150
#include<iostream.h>
void main(void){ clrscr( );
short int a, b;
a=10;
b=15;
GOVERNMENT POSTGRADUATE COLLEGE 6

JHANG
Department of Computer Science

cout<<" Sum of two numbers is := "<<(a+b )<<endl;


cout<<"Product of two numbers is :="<<a*b<<endl;
getch ( ); }

LONG INT
Long int data type is used to store large integer values. Long integer
data type occupies Four Bytes space in memory and range of values stored
in memory is from (-2147483648 to2147483647). Minimum long integer
value is defined by LONG_MIN and Maximum long integer Value is defined
by LONG_MAX.
PROGRAM-06
Write a program to display Maximum and Minimum values for long integer.
SOLUTION
#include<conio.h> Minimum value for long int is: = -2147483648
#include<iostream.h> Maximum value for long int is: = 2147483647
#include<limits.h>
void main(void ) { clrscr( );
long int min, max;
min= LONG_MIN;
max =LONG_MAX;
cout<<"Minimum value for long int is:="<<min<<endl;
cout<<"Maximum value for long int is:="<< max<<endl;
getch( );}

UNSIGNED INT
Unsigned integer can store only positive whole numbers. Unsigned
integer data type occupies two Bytes space in memory. It can store integer
value from 0 to 65,535. Minimum unsigned integer value is 0 and Maximum
unsigned integer value is defined by UINT_MAX.

PROGRAM-07
Write a program to display Maximum value for unsigned integer.
SOLUTION
#include<conio.h>
Maximum value for unsigned int is= 65535
#include<iostream.h>
#include<limits.h>
void main(void) { clrscr( );
unsigned int max;
max =UINT_MAX;
cout<<"Maximum value for unsigned int is:="<< max<<endl;
GOVERNMENT POSTGRADUATE COLLEGE 7

JHANG
Department of Computer Science

getch( ); }

Unsigned long
Unsigned long can store only positive whole numbers. It can store integer
value from 0 to 4294967295. It takes 4 bytes space in the memory. The
unsigned long int is also called unsigned long int.
ULONG_MAX represent the largest value that can be stored in unsigned
long int. it is found in limits.h header file.

PROGRAM-08
Write a program to display Maximum value for unsigned long integer.
SOLUTION Maximum value for unsigned int is= 4294967295
#include<conio.h>
#include<iostream.h>
#include<limits.h>
void main(void) { clrscr( );
unsigned long int max;
max =ULONG_MAX;
cout<<"Maximum value for unsigned long int is:="<< max<<endl;
getch( ); }

QUESTION NO.07:-Describe Real Type of data?


REAL TYPE OF DATA
Real data is a numeric value with decimal point or fraction. Real numbers
are also called Floating point numbers. These numbers contain two parts.
One is integer part and other is non-integer part. Data consisting of Real
numbers is called float type data. There are two types of Real data in C ++
language.
 float
 double
 long double
FLOAT TYPE DATA
float type data is represented in decimal or exponential form. Float type
data may be signed or unsigned. For example, 73.16, 36.29, 0.76,-7.87 are
example of floating variable. It takes 4 Bytes space in memory and range of
values stored in memory is from 3.4*10-38 to 3.4*10+38.
Minimum and Maximum values for float data type are specified in float.h
header file. Minimum float value is defined by FLT_MIN and Maximum float
value is defined by FLT_MAX.
GOVERNMENT POSTGRADUATE COLLEGE 8

JHANG
Department of Computer Science

PROGRAM-09
Write a program in C++ language to show the sum and product of two floating
point numbers.
SOLUTION Sum is: = 11.7
#include<conio.h> Product is: =14.8
#include<iostream.h>
void main(void) { clrscr( );
float a, b;
a=1.45;
b=10.25;
cout<<" Sum is :=" <<(a+b )<<endl;
cout<<" Product is := " <<(a-b)<<endl;
getch ( ); }

PROGRAM-10
Write a program to display Maximum and Minimum values for float variable.
SOLUTION
#include<conio.h>
#include<iostream.h>
#include<float.h>
void main(void) { clrscr( ); Minimum value for float is: = 1.175*10 -38

+38
Maximum value for float is: = 3.40*10
float min, max;
min= FLT_MIN;
max = FLT_MAX;
cout<<"Minimum value for float is:="<<min<<endl;
cout<<"Maximum value for float is:="<< max<<endl;
getch( ); }
DOUBLE TYPE DATA
Double data type is also called a Real data type. It is used to store large
Real values. A double type variable takes 8 Bytes space in memory and can
store Real values from 1.7×10-308 to 1.7×10+308. It is an accurate up to 12
decimal places.
Minimum double value is defined by DBL_MIN and Maximum double
value is defined DBL_MAX. Minimum and Maximum values for double data
type are specified in float.h header file.
PROGRAM-11
Write a program to display Maximum and Minimum values for double type
variable.
GOVERNMENT POSTGRADUATE COLLEGE 9

JHANG
Department of Computer Science

SOLUTION
#include<conio.h>
#include<iostream.h>
Minimum value for double is: = 2.2*10-308
#include<float.h>
Maximum value for double is: = 1.7*10308
void main(void) { clrscr( );
double min, max;
min= DBL_MIN;
max = DBL_MAX;
cout<<"Minimum value for double is:=" <<min <<endl;
cout<<"Maximum value for double is:="<< max <<endl;
getch( ); }
LONG DOUBLE TYPE DATA
Long double type variable is used to store very large Real data values.
Storage capacity for long double variable is 10 bytes. Range of stored long
double type variable values in memory is from (1.1×10-4932 to 1.1×10+4932).
Minimum value for long double variable is defined by LDBL_MIN and
Maximum value for long double variable is defined by LDBL_MAX. Minimum
and Maximum values for long double data type are specified in float.h header
file.

PROGRAM-12
Write a program to display Maximum and Minimum values for long double
variable.
SOLUTION
#include<conio.h>
#include<iostream.h>
#include<float.h>
Minimum value for long double is:= 1.1*10-4932
void main(void) { clrscr( ); Maximum value for long double is: = 1.1*10+4932
long double min, max;
min= LDBL_MIN;
max = LDBL_MAX;
cout<<"Minimum value for long double is:=" <<min <<endl;
cout<<"Maximum value for long double is:="<< max<<endl;
getch( ); }

QUESTION NO.08:-Writ a short note on character type data.


CHAR TYPE DATA
A charter is a single letter, number, or symbol that takes up one byte of
memory. Char stands for character. It is used to declare character type
variable. Storage capacity of a single character is 8-bit or one byte.
GOVERNMENT POSTGRADUATE COLLEGE 10

JHANG
Department of Computer Science

Maximum and Minimum values for chartered data types are specified
in limits header file. Minimum char values are defined by CHAR_MIN and
Maximum value for char value is CHAR_MAX.

PROGRAM-13
Write a program in C++-language to display character value on the computer
screen.
SOLUTION Character constant is= A
#include<conio.h>
#include<iostream.h>
void main(void) { clrscr( );
char num;
num='A' ;
cout<<" Character constant is= " << num<<endl;
getch( ); }

PROGRAM-14
Write a program that displays a single character value on the screen.
SOLUTION
#include<conio.h>
#include<iostream.h>
void main(void) { clrscr( );
char num; Character constant is= A
num= 'AA';
cout<<" Character constant is=" <<num<<endl;
getch( ); }
PROGRAM-15
Write a program that convert character value into integer value and show the
result on the screen.
SOLUTION Character code in integer format is=65
#include<conio.h>
#include<iostream.h>
void main(void) { clrscr( );
char num;
num= 'A';
int num1;
num1=num;
cout<<"Character code in integer format is = "<< num1<<endl;
getch( ); }
GOVERNMENT POSTGRADUATE COLLEGE 11

JHANG
Department of Computer Science

PROGRAM-16
Write a program to display Maximum and Minimum values for char variable.
SOLUTION
#include<conio.h>
#include<iostream.h>
#include<limits.h>
Minimum value for char variable is: = -128
void main(void ) { clrscr( ); Maximum value for char variable is: = 127
int min, max;
min= CHAR_MIN;
max = CHAR_MAX;
cout<<"Minimum value for char variable is:=" <<min <<endl;
cout<<" Maximum value for char variable is:="<< max<<endl;
getch( ); }
QUESTION NO.09:-What is variable? Illustrate with examples.
VARIABLE
A quantity whose value may change during the execution of the program
is called variable. It may be numeric/ non-numeric quantity. It is represented
by a symbol called variable name.
A Variable represents a storage or memory location inside Computer
memory. Data is stored in memory location. Name of the Memory location
i.e. Variable name remains fixed during the program execution but data
stored in that location may changes from time to time.
A variable is also known as object in C++ language. In C++, a variable
name consists of alphabets and digits.
The variables are created in RAM that is temporary memory. That is
why the data stored in RAM is also temporary. It can only be used and
processed during the execution of the program.
The data stored in a variable is automatically removed when program
ends.

QUESTION NO.10:-Explain the concept of variable name, variable


content and variable address.
Name, content and address of VARIABLE
When any variable is created in the program of C-language, some bytes
in the computer memory are allocated to it. These bytes are used to store
the value assigned to the variable during the execution of the program.
GOVERNMENT POSTGRADUATE COLLEGE 12

JHANG
Department of Computer Science

Suppose we have a variable name “Marks” and data value 75 is


assigned to it. The relationship between variable, content and memory
address is shown.
Variable
0000 content
0001
0002
0003
0004
0008 75
0005
0006
0007
0008 75 Mark
0009
Variable
Address

Memory Memory Locations


Variable
Address Name

Variable name It refers to an Identifier that represents a memory location


Variable content It refers to the value stored in the memory location associated with the variable.

Variable address It refers to the memory location of variable.

QUESTION NO.11:-What is meant by declaration of variables?


DECLARATION OF VARIABLE
The process of assigning the name and data type that a variable can
hold is called declaration of variable. All variables that are used in a program
are declared using variable declaration statement.
When a variable is declared, a space of certain number of bytes in
memory are allocated to the variable name. The amount of memory is
allocated according to the type of variable. The value of the variable is stored
in the memory space.
SYNTAX:- Type List of variables where
Type It specifies the data type of list of variables.
List of variables It specifies the list of variables separated by commas.
Different statements are used to declare variables of different data types.
EXAMPLE :- int x;
float num;

QUESTION NO.12:-What is meant by initialization of variables?


INITIALIZATION OF VARIABLE
When a variable is declared, a memory location is assigned to it. A value can
also be assigned to it at the time of its declaration. Assigning a known value to a
variable at the time of declaration is called initializing of variable.
EXAMPLE:- To declare variables a, b, c of integer type and assigning values a=110,
b=20 the statement is written as:
int a=110, b=20, c;
GOVERNMENT POSTGRADUATE COLLEGE 13

JHANG
Department of Computer Science

PROGRAM-17
Write a program in C++ language to show declaration and initialization of
variables.
solution Resultant value of b is:=6.28318
#include<conio.h> Value of integer variable m is=75
#include<iostream.h>
void main(void) { clrscr( );
float p= 3.14159;
int m=75;
float b;
b=2*p;
cout<<"Resultant value of b is:= "<<b<<endl;
cout<<"Value of integer variable m is="<<m<<endl;
getch ( ); }

PROGRAM-18
Write a program in C++ language to assign values to different variables at the
time of declaration. Print the assigned values on the Computer screen.
solution
#include<conio.h> Value of integer variable abc is:=4
#include<iostream.h> Value of integer variable b is=1957;
void main(void) { clrscr( ); Value of floating point variable b is=3.14

int abc=4, b=1957;


float xy=3.14;
cout<<"Value of integer variable abc is:="<<abc<<endl;
cout<<" Value of integer variable b is="<<b<<endl;
cout<<"Value of floating point variable xy is="<<xy<<endl;
getch ( ); }

QUESTION NO.13:-Write rules for writing names of variables.


RULES
Following are the rules for writing a variable name in C++ language.
First character of variable name must be an alphabetic character.
Underscore can also be used as first character of variable name.
Blank spaces are not allowed in variable name.
Special characters such as arithmetic operators, #, @,%,<,> and ^ etc. cannot be
used in the variable name.
Reserved words/keywords cannot be used as variable name.
Maximum length of variable name is up to 31 characters.
GOVERNMENT POSTGRADUATE COLLEGE 14

JHANG
Department of Computer Science

A variable declared for one data type cannot be used for another data type.
C is a case sensitive language. Variable names with same spelling but in different
cases are treated as different variable names. For example rem , Rem and REM are
three different variables.

QUESTION NO.14:-Explain the concept of declaring and defining of


variables?
Declaring and defining VARIABLE
Variable declaration only informs the compiler the name and data type
of the variable that is used in the program. It does not reserve the memory
space for the variable in the memory.
On the other hand, when a variable is defined, a memory location is
also reserved for that variable. The size of memory location reserved for the
variable depends upon the data type of the variable.
In C++-language, variable declaration statement also defines the
variable. Therefore, when a variable is declared in C++-language program, a
memory location is also reserved for that variable.

QUESTION NO.15:-What is constant? Write a note on the different


types of Constants used in C++.
CONSTANT
A quantity that cannot change its value during execution of program is
called constant. This quantity can be stored at any location in the memory of
Computer System.
TYPES OF CONSTANTS
There are four types of constants. These are:
Numeric Constants.  Character Constants
String Constants.
NUMERIC CONSTANT
Numeric constants consist of numbers or numeric values. These may
be positive or negative values. These numeric constants are further divided
into:
Integer Constants. Floating point constants
INTEGER CONSTANTS
A numerical value without a decimal point is called integer constant. Plus
(+) and Minus (-) signs can be used with integer constant. Integer constants
are used in expressions for calculations. 35,+65,-85 are the examples of
integer constants.
GOVERNMENT POSTGRADUATE COLLEGE 15

JHANG
Department of Computer Science

FLOATING POINT CONSTANTS


Floating point constants consist of numerical values with decimals.
These constants are written in two forms:
Fractional Form Exponential Form
Here 3.45,+3.89 and -96.875 are the examples of floating point constants.
Plus(+) and Minus(-) signs can be used with Floating point constants.
CHARACTER CONSTANTS
A single character or digit or special character enclosed in a single
quotation mark is called character constant. For example ‘a’ , ‘/’ and ‘+’
represent character constants. Maximum length of character constant is 1
character.
STRING CONSTANTS
A sequence of characters consisting of alphabets, digits or special
characters enclosed in double quotation marks is called String constants. " I
love Pakistan", " Government Islamia College, Chiniot " are examples of string
constant.
QUESTION NO.16:-What are Symbolic Constants? How they are
defined C++ language program?
SYMBOLIC CONSTANT
A symbolic constant is an identifier that represents a constant value.
There are two methods to define a Symbolic Constant. These are:
Using the " define" Directives
Using the " const" Qualifier
QUESTION NO.17:-What is the “define” Directive?
The “ define ” Directive
It is Preprocessor Directive. It is used to assign a constant value to an
identifier. This Directive can be used anywhere in the program. Its syntax is
given:
#define identifier constant
Where
Identifier It specifies the name of the identifier to which the constant value is to be assigned.
Constant It specifies the constant value that is to be assigned to the identifier.
Define statement does not end with semicolon. Identifier specified in the define directive is not a
variable. Identifier used in define directives does not have any data type. Preprocessor simply replace
all occurrences of the identifier with its value in the statements that follow Directive. For example, in the
following statement, PI has been defined to represent 3.14159. It can be written as:
#define PI 3.14159
NOTE:-Identifier used in Define Directive is always written in upper case letters.
GOVERNMENT POSTGRADUATE COLLEGE 16

JHANG
Department of Computer Science

PROGRAM-19
Write a program C++-language to define the procedure of Define Directive.
SOLUTION
#include<conio.h> Resultant value of b is: =6.28318
#include<iostream.h>
#define PI 3.14159
void main(void) { clrscr( );
float b;
b=2*PI;
cout<<"Resultant value of bis:="<<b<<endl;
getch ( ); }
PROGRAM-20
Write a program in C++-language using Define Directive to find the area of a
circle. Where area=R2
SOLUTION
#include<conio.h> Area of the circle is:=314.159

#include<iostream.h>
#define PI 3.14159
void main(void) { clrscr( );
float area, R;
R=10;
area=PI*R*R;
cout<<"Area of the circle is :="<<area<<endl;
getch ( ); }

QUESTION NO.18:-Define Constant Qualifier? How is it defined in


C language Program?
CONSTANT QUALIFIER
The “const” qualifier is used to define a variable with a fixed value.
Value is assigned to the variable at the time of its declaration. In the following
statement, P has been declared as floating-point variable and a fixed value
3.141593f has been assigned to it at the time of declaration.
SYNTAX:- const float P = 3.14159 ;
PROGRAM-21
“p” has been declares as floating point constant and a value 3.14159 is assigned to
it. Write a program in C++-language to compute b=2*p.
SOLUTION
#include<conio.h>
GOVERNMENT POSTGRADUATE COLLEGE 17

JHANG
Department of Computer Science

#include<iostream.h>
void main(void) { clrscr( ); Resultant value of b is: =6.28318
const float p= 3.14159;
float b;
b=2*p;
cout<<"Resultant value of b is:= "<<b<<endl;
getch ( ); }
PROGRAM-22
Write a program in C++-language to assign three values to three integer type
variables x ,y , z. add variables x ,y and multiply their sum to the variable z.
SOLUTION
#include<conio.h>
#include<iostream.h>
void main( ) { clrscr( );
int x ,y, z, sum;
cout<<" Enter value for X:= ";
Enter value for x:=5
cin>>x; Enter value for y:=10
cout<<" Enter value for Y:= "; Enter value for z:=15
Resultant value is :=225
cin>>y;
cout<<" Enter value for Z:= ";
cin>>z;
sum= x+y;
z*=sum;
cout<<" Resultant value is := "<<z<<endl;
getch( ); }

QUESTION NO.19:-What do you mean by range and precision?


Describe briefly.
Precision
The numbers of digits after the decimal point are called precision or
accuracy of the real number.
Range:
Range is the exponential power of 10.
A float variable has a precision of 6 digits and range of 10-38 to 10+38.
Suppose the speed of light is 299722000. It can be written in scientific
notation as 2.99722×108. This requires a precision of at least 5 digits in the
decimal to accurately represent this quantity. And its range is 8. Similarly
the value 0.123456×10-3has precision 6 digits and a range of -3.
GOVERNMENT POSTGRADUATE COLLEGE 18

JHANG
Department of Computer Science

QUESTION NO.20:-Distinguish between overflow and underflow?


overflow & underflow
Every type of numeric variable has a range of minimum and maximum
values. Any value between the given ranges of values can be assigned to it.
When a value that exceeds the limits is assigned to the variable, an incorrect
value is stored into the variable.
]

An overflow occurs when the value assigned to the variable is more


than the maximum allowable limit. For example, the maximum value for the
integer type variable is 32767. If the assigned value is more than 32767, than
an integer overflow occurs.
Similarly, an underflow occurs when the value assigned to the variable
is less than the minimum allowable limit. For example, the maximum value
for the integer type variable is -32768. If the assigned value is less than -
32768, than an integer underflow occurs.
QUESTION NO.21:-What are operators? List the different operators
used in C++ language.
OPERATORS
An operator is a symbol or Identifier that causes compiler to perform
certain action on data.
operators meanings
In C++ language, there is a variety - Unary
of operators. List of the important + Addition
operators is given below. - Subtraction
* Multiplication
Arithmetic Operators / Division
Relational Operators % Remainder
Logical Operators <>,<=, >=, ==, != Relational operators
&&, ||, ! Logical operators
Assignment Operators ? Conditional operator
Increment and Decrement Operators =,+=,-=,*=,/=,%= Assignment operators
Compound Assignment Operators
QUESTION NO.22:-Differentiate between Binary operators and
Unary operators.
BINARY OPERATORS
The operators that operate on two data items are called Binary Operators.
Arithmetic operators, Relational operators and two logical operators (&& ,
||) are the examples of Binary Operator because these operators take two
operands.
PROGRAM-23
Write a program in C++-language to perform arithmetic operations by using all
Arithmetic Operators.
GOVERNMENT POSTGRADUATE COLLEGE 19

JHANG
Department of Computer Science

SOLUTION
#include<conio.h>
#include<iostream.h> Enter value for a:=10
void main(void) { clrscr( ); Enter value for b:=5
Sum is:=15
int a, b, add, sub, mul , div, rem; Subtraction is:=5
cout<<" Enter value for a:= "; Multiplication is:=50
Division is:= 2
cin>>a; Remainder is:=0
cout<<" Enter value for b:= " ;
cin>>b;
add= a+b;
sub= a-b;
mul=a*b;
div= a/b;
rem= a%b;
cout<<" Sum is:="<< add<<endl;
cout<<" Subtraction is:="<< sub<<endl;
cout<<" Multiplication is:="<< mul<<endl;
cout<<" Division is:="<< div<<endl;
cout<<" Remainder is:="<< rem<<endl;
getch( );}
PROGRAM-24
Write a program which reads two integer values and prints their Sum,
Difference, Product, Division and Remainder as shown in the output on Computer
screen.
SOLUTION
#include<conio.h>
#include<iostream.h> Enter First Integer:=4
void main(void) {clrscr( ); Enter Second integer:= 3
4+3=7
int a,b ; 4 -3=1
cout<<" Enter First Integer:= "; 4*3=12
4/3=1
cin>>a; 4%3=1
cout<<" Enter Second Integer:= ";
cin>>b;
cout<<a<<"+"<<b<<"="<<(a+b)<<endl;
cout<<a<<"-"<<b<<"="<<(a-b)<<endl;
cout<<a<<"*"<<b<<"="<<(a*b)<<endl;
cout<<a<<"/"<<b<<"="<<(a/b)<<endl;
cout<<a<<"%"<<b<<"="<<(a%b)<<endl;
getch( );}
GOVERNMENT POSTGRADUATE COLLEGE 20

JHANG
Department of Computer Science

PROGRAM-25
Write a program in C++-language to interchange the values of two variables
using assignment statement. Print the original and exchanged values on the Computer
screen.
SOLUTION
#include<conio.h>
#include<iostream.h> Values before interchange
Value of a:=10
void main(void) { clrscr( ); Value of b:=20
int a, b, temp ; Values after interchange
Value of a:=20
a=10; Value of b:=10
b=20;
cout<<"Values before interchange "<<endl;
cout<<"Value of a:="<< a<<endl;
cout<<" Value of b:="<< b<<endl;
temp=b;
b=a;
a=temp;
cout<<"Values after interchange “<<endl;
cout<<"Value of a:="<< a<<endl;
cout<<" Value of b:="<< b<<endl;
getch( ) ; }

PROGRAM-26
Write a program in C++ language to assign a numeric value to a variable year.
Calculate the number of months and print the result on Computer screen.
SOLUTION
#include<conio.h>
#include<iostream.h>
void main(void) { clrscr( );
Enter No. of years: = 4
int years, month; Number of months:=48
cout<<"Enter No. of years: = ";
cin>>years;
month=years*12;
cout<<" Number of months:="<<month<<endl;
getch( ); }

UNARY OPERATORS
The operators that need only one data item to operate on are called
unary operators. Minus(-) operator is an example of unary operator. This
operator is used to inverse the sign of the value. Furthermore ++(increment
GOVERNMENT POSTGRADUATE COLLEGE 21

JHANG
Department of Computer Science

operator),--(Decrement operator and logical not operator(!) are examples of


unary operator.

QUESTION NO.23:-What are Arithmetic operators? Explain.


ARITHMETIC OPERATORS
Operators used to perform arithmetic OPERATOR MEANING EXAMPLE
operations on the data are called Arithmetic + Addition a+b
- Subtraction a-b
Operators. These Operators are used in * Multiplication a*b
Arithmetic Expressions. Each arithmetic / Division a/b
% Remainder a%b
operator operates upon two numeric values
and returns a single value.

A list of commonly used Arithmetic Operators in C++ language is shown


in the table form. Remainder operator is called modulus operator. It can only
be used for integer data type. It returns remainder when one integer value
can be divided by another integer value. For example 5%3=2
QUESTION NO.24:-What is the use of Assignment Operator? Explain
with example.
ASSIGNMENT OPERATOR
Operator used to assign a value to a variable is called an assignment
operator. Symbol (=) is used for assignment operator. Expression or
formula is written on the right side of assignment operator. The variable to
which the value of Expression or Formula is to be assigned is written on the
left side of the assignment operator.
Syntax:- variable=Expression
Variable It is the name of the variable to which the value of expression is assigned.
= It is assignment operator used to assign the value to the variable.
Expression It specifies an arithmetic expression or a single value.

QUESTION NO.25:-What do you meant by Arithmetic Assignment


Operators?
ARITHMETIC ASSIGNMENT OPERATORS
Arithmetic Assignment operator is OPERATOR MEANING EXAMPLE
an operator which combines Arithmetic = Equal a==b
operator and assignment operator and +- Addition a+=b
eliminate the repeated operands. -= Subtraction a-=b
*= Multiplication a*=b
Following are arithmetic assignment
/= Division a/=b
operators corresponding to assignment %= Remainder a%=b
operators.
GOVERNMENT POSTGRADUATE COLLEGE 22

JHANG
Department of Computer Science

Example:- a+=15; same as a=a+15;


if we have a=a+10; then this statement can be a-=255; same as a=a-255;
written as: a+=10;.Consider the examples of compound a*=115; same as a=a*115;
a/=75; same as a=a/75;
Assignment Expressions.
a%=18; same as a=a%18;

PROGRAM-27
Write a program in C++ language that uses arithmetic assignment operators.
SOLUTION
#include<conio.h>
#include<iostream.h> Enter any No.:=5
Resultant value is := 20
void main(void) { clrscr( ); Resultant value is :=10
int ans; Resultant value is :=250
Resultant value is := 14
cout<<" Enter any No. := "; Resultant value is :=4
cin>>ans;
ans+=15;
cout<<" Resultant value is :="<<ans<<endl;
ans-=10;
cout<<" Resultant value is := "<<ans<<endl;
ans*=25;
cout<<" Resultant value is := "<<ans<<endl;
ans/=17;
cout<<" Resultant value is := "<<ans<<endl;
ans%=5;
cout<<" Resultant value is := "<<ans<<endl;
getch( ); }

QUESTION NO.26:-Define Increment and Decrement Operators.


INCREMENT OPERATOR
Operator used to add 1 to the value of the variable is called Increment
Operator. It is denoted by ++ symbol. It is unary operator and work with single
operand.
DECREMENT OPERATOR
Operator used to subtract 1 to the value of the variable is called
Decrement operator. It is denoted by -
Operator Meaning Example
- symbol. It is unary operator and work ++ Increment a++,++a
with single operand. Consider a list - - Decrement a- -, - -a
Increment and Decrement Operators.
Note:-Only variables can be incremented or decremented. Constants and
expressions cannot be incremented or decremented.
GOVERNMENT POSTGRADUATE COLLEGE 23

JHANG
Department of Computer Science

QUESTION NO.27:-Define Increment Operator. Differentiate


between Prefix and Postfix Increment operators.
INCREMENT OPERATOR
The Increment Operator is represented by double plus (++) sign. This
operator is used to add 1 to the value of the variable. This operator can be
used before and after the variable name.
PREFIX INCREMENT OPERATOR
If Increment operator is written before the name of variable then it
called Prefix Increment operator. For example b=++a; It is equivalent to:
a=a+1;
b=a;
POSTFIX INCREMENT OPERATOR
If Increment Operator is written after the name of variable then it called
Postfix Increment operator. For example b=a++; It is equivalent to:
b=a;
a=a+1;
PROGRAM-28
Write a program that uses the Prefix Increment operator.
Solution
#include<conio.h> Enter any positive No.:=15
Original number is :=15
#include<iostream.h> Number after increment is :=16
void main( ) {clrscr( );
int num , a;
cout<<"Enter any positive No. := ";
cin>>num;
cout<<"Original number is :="<< num<<endl;
a=++num;
cout<<" Number after increment is :="<< a<<endl;
getch( ); }
PROGRAM-29
Write a program in C++-language to evaluate an expression “a+b++”.
Suppose the value of a=5 and value of b=10. Print the resultant value and values of
a and b before and after execution of expression.
SOLUTION
#include<conio.h>
#include<iostream.h>
void main(void) { clrscr( );
int a,b, res;
GOVERNMENT POSTGRADUATE COLLEGE 24

JHANG
Department of Computer Science

a=5;
b=10;
Values before evolution
cout<<"Values before evolution "<<endl; Value of a:=5
cout<<"Value of a:="<< a<<endl; Value of b:=10
Resultant value:=15
cout<<" Value of b:="<< b<<endl; Values after evolution
res=a+b++; Value of a:=5
Value of b:=11
cout<<"Values after evolution "<<endl; Resultant value is:=15
cout<<"Value for a:="<< a<<endl;
cout<<" Value for b:="<< b<<endl;
out<<" Resultant value is:="<<res<<endl;
getch( ) ; }

PROGRAM-30
Write a program in C-language to evaluate an expression “++a+b++”.
Suppose the value of a=5 and value of b=10. Print the resultant value and values of
a and b before and after execution of expression.
SOLUTION
Values before evolution
#include<conio.h>
Value of a:=5
#include<iostream.h> Value of b:=10
void main(void) { clrscr( ); Resultant value:=16
Values after evolution
int a,b, res; Value of a:=6
a=5; Value of b:=11
Resultant value is:=15
b=10;
cout<<"Values before evolution "<<endl;
cout<<"Value of a:="<< a<<endl;
cout<<" Value of a:="<< a<<endl;
res=++a+b++;
cout<<"Values after evolution "<<endl;
cout<<"Value for a:="<< a<<endl;
cout<<" Value for b:="<< b<<endl;
cout<<" Resultant value is:="<<res<<endl;
getch( ) ; }
QUESTION NO.28:-What is Decrement operator? Differentiate
between Prefix and Postfix Decrement operators.
DECREMENT OPERATOR
Decrement operator is represented by double Minus (- -) sign. This
operator is used to subtract 1 from the value of the variable. This operator
can be used before and after the variable name.
GOVERNMENT POSTGRADUATE COLLEGE 25

JHANG
Department of Computer Science

PREFIX DECREMENT OPERATOR


If the Decrement operator is written before the name of variable then
it called Prefix Decrement Operator. For Example b=- -a; It is equivalent to:
a=a-1;
b=a;
POSTFIX DECREMENT OPERATOR
If Decrement operator is written after the name of variable then it
called Postfix Decrement Operator. For example b=a--; It is equivalent to:
b=a;
and a=a-1;

PROGRAM-31
Write a program in C++-language to evaluate an expression “- -a+b- -”.
Suppose the value of a=5 and value of b=10. Print the resultant value and values of
a and b before and after execution of expression.
SOLUTION Values before evolution
# include<conio.h> Value of a:=5
#include<iostream.h> Value of b:=10
Resultant value:=14
void main(void) { clrscr( );
Values after evolution
int a,b, res; Value of a:=4
Value of b:=9
a=5;
Resultant value is:=14
b=10;
cout<<"Values before evolution "<<endl;
cout<<"Value of a:="<< a<<endl;
cout<<" Value of b:="<< b<<endl;
res= - -a+b- -;
cout<<"Values after evolution "<<endl;
cout<<"Value for a:="<< a<<endl;
cout<<" Value for b:="<< b<<endl;
cout<<" Resultant value is:="<<res<<endl;
getch( ) ; }
QUESTION NO.29:-What
is Compound Assignment Operator?
COMPOUND ASSIGNMENT OPERATOR
An assignment operator used to assign one value to more variables is
called Compound Assignment Operator. Compound assignment operators
are used to perform mathematical operations more easily.

PROGRAM-32
Write a program that uses the compound assignment statement.
GOVERNMENT POSTGRADUATE COLLEGE 26

JHANG
Department of Computer Science

SOLUTION
# include<conio.h>
#include<iostream.h>
void main(void) { clrscr( );
int a, b , c ,d; Result of multiplication is :=1000
a=b=c=10;
d=a*b*c;
cout<<"Result of multiplication is :="<<d<<endl;
getch( ); }
PROGRAM-33
Suggest the output of the following program.
SOLUTION
#include<conio.h> Resultant value of c is :=65
#include<iostream.h> Resultant value of j is :=250

void main(void) { clrscr( );


int a=10, b=15, c=40, j=10, k=12, m=20;
c+=a+b;
j*=k=m+5;
cout<<"Resultant value of c is :="<<c<<endl;
cout<<"Resultant value of j is :="<< j<<endl;
getch( ); }

PROGRAM-34
Evaluate following expressions and display result on computer screen.
solution
#include<conio.h>
#include<iostream.h>
Resultant value of a is: =13
void main(void) { clrscr( );
Resultant value of b is :=12
int a=1,b=2,c=3; Resultant value of c is :=10
a+=b+=c+=7;
cout<<"Resultant value of a is :="<<a<<endl;
cout<<"Resultant value of b is :="<< b<<endl;
cout<<"Resultant value of c is :="<<c<<endl;
getch( ); }
QUESTION NO.30:-What is the Order of Precedence? Explain the
Order of Precedence of Arithmetic Operators.
ORDER OF PRECEDENCE
C++ language treats arithmetic operators with different importance,
known as order of precedence of arithmetic operators. Furthermore, order
GOVERNMENT POSTGRADUATE COLLEGE 27

JHANG
Department of Computer Science

of precedence is defined as the order in which different operators are


evaluated in the expression. It is also known as hierarchy of the operators.

Each operator has a fixed order in which it is evaluated in the


Expression. Operators with higher precedence order are evaluated first than
that of the operators with lower precedence order. When an arithmetic
expression is evaluated, Computer performs only one operation at a time. In
C++ -language, arithmetic operators are evaluated according to the following
sequence.

Parenthesis in Expression are computed from left to right.


When parentheses are used within an expression then expressions within
parenthesis are evaluated first from left to right.
All multiplication and division are performed first from left to right.
All additions and subtractions are performed from left to right.
QUESTION NO.31:-What is expression? Explain with Examples.
EXPRESSION
An Expression is combination of operators, operands and constants.
It is used for calculating the value of formula. It is formed by combining
different operands and operators. It returns a single value. Operands may
be constants, variable names or punctuations etc. Parenthesis may also be
used in Expression.

EXAMPLE:-In order to calculate the volume of a box with sides x, y, z, We use the
following formula. Volume=x*y*z Where x ,y , z are variables and known as
operands and multiplication sign is called operator.

QUESTION NO.32:-Enumerate different types of Expressions.


TYPES OF EXPRESSIONS
Following are the different types of Expressions used in C++ language.
 Arithmetic Expression.  Relational Expression.
 Logical Expression.
ARITHMETIC EXPRESSIONS
Expressions used to calculate the values of arithmetic formulae are
called Arithmetic Expressions.
EXAMPLES
C= (F-32)*5/9 , VOLUME=4/3*PI*R*R*R
S= A*A+2*A*B+B*B , DISC = sqrt(B*B-4*A*C)
GOVERNMENT POSTGRADUATE COLLEGE 28

JHANG
Department of Computer Science

RELATINAL EXPRESSIONS
Relational Expressions are used to compare between two or more
values and show the result which value is greater or least. In these
expressions, Relational operators are used. Relational operators are
<,>,<=,>=, != etc.
LOGICAL EXPRESSIONS
Logical Expressions are used to compare between two or more
Relational Expressions. Three operators AND (&&), OR (||) and NOT (!) are
used in Logical Expressions.
QUESTION NO.33:-What are Relational Operators?
RELATIONAL OPERATORS
Operators used to specify a Operator Symbol Example
relation between two Expressions or Grater than > a>b
Greater than or equal to >= a>=b
two variables are called Relational Less than < a<b
Operators. Relational Operators are Less than or equal to <= a<=b
Equal to == a==b
used to compare two expressions. Not equal to != a!=b
The expressions used with Relational
Operators may be constants, variables or arithmetic operators. Following is
list of Relational operators commonly used in C++ Language.

QUESTION NO.34:-Write a note on logical operators used in C++-


language.
LOGICAL OPERATORS
Logical operators are used for mathematical purpose. Furthermore,
these operators are used to form compound condition. A compound
condition is one in which two or more conditions are compared. C++-language
allows the usage of three logical operators.
&&( Read as AND )
||( Read as OR )
! (Read as NOT)
AND LOGICAL OPERATOR
AND(&&) logical operator is used to combine two or more relational
expressions. Logical AND CONDITION 1 CONDITION 2 AND OPERATOR ANSWER
operator returns true answer if all F F F && F F
conditions are true. If any one of F T F && T F
the condition is false, it produces T F T && F F
T T T && T T
the false result as shown in the
following truth table.
GOVERNMENT POSTGRADUATE COLLEGE 29

JHANG
Department of Computer Science

In the above truth table F= False and T= True.


OR LOGICAL OPERATOR
OR(||) logical operator is used to combine two or more relational
expressions. Logical OR CONDITION 1 CONDITION 2 OR OPERATOR ANSWER
operator returns true answer if F F F || F F
all conditions are true or any F T F || T T
T F T || F T
one condition from two is true. T T T|| T T
It produces false output when
all inputs are false as shown in the following truth table.
NOT LOGICAL OPERATOR
This logical operator produces false result if the condition is true. On
the other hand this operator produces true result if the condition is false. It
is also known as unary operator.
PROGRAM-35
Evaluate the following Expressions if the initial values of the integer
variables a and b are a=24 and b=7.
SOLUTION
#include<conio.h>
#include<iostream.h> Resultant value of c is:=3
void main(void) { clrscr( ); Resultant value of d is:=3
Resultant value of e is:=3
int a,b,c,d,e,f; Resultant value of a is:=2
a=24,b=7; Resultant value of b is:=7

c=a%b;
d=a/++b;
e=(++a)/(b--);
a/=b+=2;
b+= -a;
cout<<" Resultant value of c is:="<<c<<endl;
cout<<" Resultant value of d is:="<<d<<endl;
cout<<" Resultant value of e is:="<<e<<endl;
cout<<" Resultant value of a is:="<<a<<endl;
cout<<" Resultant value of b is:="<<b<<endl;
getch( ); }

QUESTION NO.35:-Differentiate between L-Values and R-values.


R-value :-
R-value is an operand that can be written on the right side of
assignment operator (=). It can be constant value, a variable or an
expression.
GOVERNMENT POSTGRADUATE COLLEGE 30

JHANG
Department of Computer Science

L-value :-
L-value is an operand that can be written on the left side of assignment
operator (=). It must be a variable or an expression.
QUESTION NO.36:-What are comments? Write in detail.
COMMENTS
Comments are non-executable statements. These are used to add
remarks in the program. These are usually written to explain the logic of the
program. Compiler ignores comments written in the program. Compiler does
not take any action on the comment statement.
TYPES OF COMMENTS
Comments are of two types. These types are:
Single line commentsMultiple line comments
SINGLE LINE COMMENTS
Single line Comments consist of a single line non-executable statement.
These Comments are also called Double Slash Comments. In order to make
a single line non-executable comment, we use double slash (//).
PROGRAM-36
Write a program in C++ language to explain single line comments.
SOLUTION
#include<conio.h> Government Islamia College, Chiniot
#include<iostream.h>
void main(void) { clrscr( ); // This is a simple program.
cout<<" Government Islamia College, Chiniot "<<endl;
getch( ); }
EXPLANATION
In the above program, a single line comment is added. When we will
compile program, it will print " Government Islamia College, Chiniot " on the
monitor screen. The statement starting with double slash "This is a simple
program." Will not be executed.
MULTIPLE LINE COMMENTS
Multiple line comments consist of more than one line non-executable
statements. These comments help us to write a paragraph or set of
statements to explain the working of the program. We can write multiple line
comments using following structure.
/*-------------------------------
……………………………..
………………………………
………………………………
---------------------------------- */
GOVERNMENT POSTGRADUATE COLLEGE 31

JHANG
Department of Computer Science

Statements written between /* and */ will become comments. These


lines have dim color as compared to other lines.
PROGRAM-37
Write a program in C++ language that uses multiple line comments.
SOLUTION
#include<conio.h>
#include<iostream.h>
void main(void) { clrscr( ); /* This is a multiple line comment. This
comment provides information that
program will print my address */
cout<<"Muhammad Saleem Raza "<<endl;
cout<<"Assistant Professor, Computer Science"<<endl;
cout<<"Government Islamia College Chiniot "<<endl;
getch( ); }

PROGRAM-38
Write a program in C++-language to find the volume of a cylinder by using
const qualifier. Where volume=R2H.
SOLUTION
#include<conio.h>
#include<iostream.h>
void main(void) { clrscr( );
float R, H, Vol;
const float PI=3.1415; Volume of Cylinder is: =741.237

R=5.5;
H=7.8;
Vol=PI*R*R*H;
cout<<"Volume of Cylinder is: ="<< Vol<<endl;
getch(); }

SYED MUHAMMAD SALEEM RAZA


ASSISTANT PROFESSOR (Comp.Sc)
GOVERNMENT POSTGRADUATE COLLEGE, JHANG

You might also like