Page - - . What are modifiers? What is the use of modifiers? .
What is wrong with the following C++ statement: long float x; . What is a variable ? Why is a variable called symblolic variable? .
What do you mean by dynamic initialization of a variable? Give an exmple. . What is wrong with the following statement?
const int x; ? Evaluate Yourself . Formatting Output Formatting output is very important in the development of output screens for easy reading and understanding. Manipulators are used to format the output of any C++ program.
Manipulators are functions specifically designed to use with the insertion (<<) and extraction(>>) operators. C++ offers several input and output manipulators for formatting. Commonly used manipulators are: endl, setw, setfill, setprecision and setf . In order to use these manipulators, you should include the appropriate header file.
endl manipulator is a member of iostream header file. setw, setfill, setprecision and setf manipulators are members of iomanip header file. endl (End the Line) endl is used as a line feeder in C++. It can be used as an alternate to ‘\n’.
In other words, endl inserts a new line and then makes the cursor to point to the beginning of the next line. There is a difference between endl and ‘\n’, even though they are performing similar tasks. • endl – Inserts a new line and flushes the buffer (Flush means – clean) • ‘\n’ - Inserts only a new line. Example: cout << " \n The value of num = " << num; cout << "The value of num = " << num << endl; Both these statements display the same output.
setw ( ) setw manipulator sets the width of the field assigned for the output. The field width determines the minimum number of characters to be written in output. Syntax: setw(number of characters) Chapter Page - - #include <iostream> #include <iomanip> using namespace std; int main() float basic, da, hra, gpf, tax, gross, np; char name[ ]; cout << "\n Enter Basic Pay: "; cin