Both endl and flush are ________.
- AFunctions
- BOperators
- CManipulators
- DObjects
endl and flush are stream manipulators that act on the output stream.
MCQs, short and long questions from lecture 36.Lecture 36 ki MCQs, short aur long sawal.
8 MCQs · 2 short · 2 long questions · 8 MCQs from past papers8 MCQs · 2 short · 2 long sawal · 8 MCQs past papers se
Both endl and flush are ________.
endl and flush are stream manipulators that act on the output stream.
What will be the output of the following statement? cout << setbase(16) << 52 ;
setbase(16) prints in hexadecimal and 52 decimal is 0x34.
Which header file should be included in the program to use stream manipulators?
Parameterized manipulators such as setw and setprecision are declared in iomanip.h.
width() is member function of _____________
width() is a member of the ios base class, so both input and output streams have it.
When we use manipulators in our program then which header file should be included?
Parameterized manipulators are declared in iomanip.h.
setprecision is a parameter less manipulator.
setprecision takes an argument, so it is a parameterized manipulator.
setw is a parameterized manipulator.
setw takes a width argument.
dec, hex, oct are all __________
dec, hex and oct take no arguments.
No MCQs match this filter.Is filter mein koi MCQ nahi.
Write a C/C++ statement to print a floating point number 1.234 in a 9-digit field with preceding zeros.
cout << setfill('0') << setw(9) << 1.234; // needs #include <iomanip>; prints 00001.234
What are manipulators? Give one example.
Manipulators are special functions/objects inserted into (or extracted from) a stream with << or >> to change the format or state of the stream, e.g. width, precision, fill or base. Example: cout << setw(10) << x << endl; here setw(10) sets the field width and endl inserts a newline and flushes the stream.
Write a program which defines three variables of type double which store three different values including decimal points, using setprecision manipulators to print all these values with different numbers of digits after the decimal point.
#include <iostream> #include <iomanip> using namespace std; int main() { double x1 = 12345624.72345; double x2 = 987654.12345; double x3 = 1985.23456; cout << fixed; // precision now means digits after the decimal point cout << setprecision(1) << x1 << endl; // 12345624.7 cout << setprecision(3) << x2 << endl; // 987654.123 cout << setprecision(5) << x3 << endl; // 1985.23456 return 0; }
Write a program which defines two variables var1 and var2 of type int and stores two different values in these variables. Print the values of these variables in three different number systems using manipulators dec, hex, oct.
#include <iostream> using namespace std; int main() { int var1 = 100, var2 = 255; cout << "Decimal: " << dec << var1 << " " << var2 << endl; // 100 255 cout << "Hexadecimal: " << hex << var1 << " " << var2 << endl; // 64 ff cout << "Octal: " << oct << var1 << " " << var2 << endl; // 144 377 cout << dec; // restore decimal base return 0; }