10.1
Sorry this question is missed. We will try to give this question with solution very soon. Stay with us.
10.2
Will the statement cout.setf(ios::right) work or not?
#include <iostream> using namespace std; void main() { cout.width(5); cout << "99" << endl; cout.setf(ios::left); cout.width(5); cout << "99" << endl; cout.setf(ios::right); cout << "99" << endl; }
Answer
cout.setf(ios :: right) will not work because width() function was not invoked before cout.setf(ios :: right)
10.3
State errors, if any, in the following statements.
- (a) cout << (void*) amount;
- (b) cout << put (“John”) ;
- (c) cout << width();
- (d) int p = cout.width(10);
- (e) cout.width(10).precision(3);
- (f) cout.setf(ios::scientific,ios::left);
- (g) ch = cin.get();
- (h) cin.get().get();
- (i) cin.get(c).get();
- (j) cout << setw(5) << setprecision(2);
- (k) cout << resetiosflags(ios::left lios::showpos);
Answer
- (a) missing
- (b) put ( ) a member function of ostream class. It is used to output a character. Hence it does not return any value; so cout<<(“John”); is not valid. Correction :
cout.put (‘John’); - (c) width ( ) function does not return any value. So cout <Correction : cout.width ( );
- (e) cout.width (10) precision (3); must be written separately
cout.width (10);
cout.preasion (3); - (f) If you want to see output as scientfic format you can acheive this as follow:
cout.setf (ios :: scientific, ios :: floatfield); If you want to see output at left field you can achieve this as flows: cout.setf (ios :: left, ios :: adjustfield); - (g) No error
- (h) cannot be concatenated;
Correction :
cin.get ( )
cin.get ( )
- (i) No error
- (j) No error
- (k) No error
Next Previous