problem based on setw, setf and unsetf – Computer Sir Ki Class
  

Login
[lwa]



Solved Problem #CPP#4321    siteicon   siteicon  

Problem Statement - problem based on setw, setf and unsetf

print the following table of temperature record of a patient properly using setw,setf,unsetf methods.

 

Readings   Values
-----------------
Morning     100.4
Afternoon    99.8
Evening      98.8

 

Solution

TC++ #4321

#include 
#include
#include
int main()
{
clrscr();
cout<<"Readings Values"< cout<<"-----------------"< cout.setf(ios::left);
cout< cout.setf(ios::right);
cout< cout.unsetf(ios::right);
cout.setf(ios::left);
cout< cout.setf(ios::right);
cout< cout.unsetf(ios::right);
cout.setf(ios::left);
cout< cout.setf(ios::right);
cout< getch();
return 0;
}
 

Test it !

Run Output

Readings   Values
-----------------
Morning 100.4
Afternoon 99.8
Evening 98.8

Common Errors

  • Commonly learners forget that setf has a persistent behaviour unlike setw.


Suggested Filename(s): setwsetf.cpp



Share

sunmitra| Created: 15-May-2018 | Updated: 15-Sep-2018|






Back