by Dinesh Thakur Category: Object-oriented programming (OOP)

Escape Sequences

Commonly used escape sequences are \n, \t and \a. The escape sequences are enclosed in single quotes. \n is a new line character and helps in transferring control to the next line. If more than one line is to be skipped, \n is repeated as many times as the number of lines to be skipped. \n can also be combined with any other message string to be displayed. \t is used for giving tab and \a is used for giving a beep.

 

Example

 

Illustrates the use of \t and \a escape sequences.

//newtab.cpp

 

#include <iostream.h>

void main()

{

int i,j,k,m;

cout<<"Enter the value of i, j, k, m \n";

cin>>i>>j>>k>>m;

cout<<endl;

cout<<'\a '<<i<<'\t'<<j<<'\t'<<k<<'\t'<<m<<'\n';

}

 

Input and Output:

 

Enter the value of i, j, k, m

 

1234

 

1          2          3         4

 

Manipulators

These are used for manipulating the display of output in the desired format. Manipulators are used with insertion operator <<. These are included in the <iomanip.h> header file. Hence this header file should be included in the program.

flush Manipulator

This manipulator is used for flushing the buffer.

endl Manipulator

The endl manipulator is used for flushing the buffer and for inserting a new line simultaneously.

setw Manipulator

This manipulator facilitates the user to specify the field width explicitly in order to have better display of output. The syntax is

setw(field width);

The field width must be of int type.

 

Example

 

Illustrates the use of the manipulators flush, endl and setw().

 

//setw.cpp

 

#include <iostream.h>

#include <iomanip.h>

void main()

{

char entryno[10];

char name[10];

int fee;

cout<<"Enter the entry number "<<endl;

cin>>entryno;

cout<<"Enter the name "<<flush<<'\n';

cin>>name;

cout<<"Enter the fees "<<endl;

cin>>fee;

cout<<endl;

cout<<setw(18)<<"Entry number"<<setw(12)<<entryno<<endl;

cout<<setw(1 O)<<"Name "<<setw(20)<<name<<endl;

cout<<setw(10)<<"Fees "<<setw(20)<<fee<<endl;

}

 

Input and Output:

Enter the entry number

MAC0797

Enter the name

Sanjay

Enter the fees

1200

Entry number  MAC0797

Name               Sanjay

Fees                 1200

Following is a program to find the minimum and maximum limits for char, short, int, long int, float, double and long double type of data.

 

Example

 

The Program finds the limit for char, short, int, long int, float, double and long double type of data. The keywords for finding the limits for float, double and long double (written in capital letters in the program) are found in float.h header file. The keywords for finding the limits for other types are found in limits.h header file.

 

#include <iostream.h>

#include <limits.h>

#include <float.h>

void main()

{

cout<<"minimum char value is "<<CHAR_MIN<<"\n" ;

cout<<"maximum char value is "<<CHAR_MAX<<"\n" ;

cout<<"minimum short value is "<<SHRT_MIN<<"\n" ;

cout<<"maximum short value is "<<SHRT_MAX<<"\n" ;

cout<<"minimum int value is "<<INT_MIN<<"\n\n" ;

cout<<"maximum int value is "<<INT _MAX<<"\n'" ,

cout<<"minimum long int value is "<<LONG_MIN<<"\n\n";

cout<<"maximum long int value is "<<LONG_MAX<<"\n";

cout<<"min. no. of significant digits in float is "<<FL T_DIG<<"\n";

cout<<"max. no of bits for mantissa is "<<FLT_MANT_DIG<<"\n";

cout<<" min. exponent value in float is "<<FLT_MIN_10_EXP<<"\n";

cout<<"max. exponent value in float is "<<FLT_MAX_10_EXP<<"\n\n";

cout<<"min. no. of significant \n";

cout<<"digits in double is "<<DBL_DIG<<"\n\n";

cout<<"max. no. of bits for mantissa is "<<DBL_MANT_DIG<<"\n";

cout<<"min. exponent value in double is "<<DBL_MIN_10_EXP<<"\n\n";

cout<<"max. exponent value in double is "<<DBL_MAX_10_EXP<<"\n";

cout<<"min. no. of significant\n";

cout<<"digits in long double "<<LDBL_DIG<<"\n\n";

cout<<"max. no. of bits for mantissa is "<<LDBL_MANT_DIG<<"\n";

cout<<"min. exponent value in long double is n<<LDBL_MIN_10_Exp<<n\n";

cout<<"max. exponent value in long double is n<<LDBL_MAX_10_EXP<<"\n\n";

}

 

Output:

minimum char value is -128

maximum char value is 127

minimum short value is -32768

maximum short value is 32767

minimum int value is -2147483648

maximum int value is 2147483647

minimum long int value is -2147483648

maximum long int value is . 2147483647

min. no. of significant digits in float is 6

max. no. of bits for mantissa is 24

min. exponent value in float is -37

max. exponent value in float is 38

min. no. of significant

 

digits in double is 15

max. no. of bits for mantissa is 53

min. exponent value in double is -307

max. exponent value in double is 308

min. no. of significant

digits in long double 15

max. no. of bits for mantissa is 53

min. exponent value in long double is -307

max. exponent value in long double is 308



About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.



Related Articles