// mysetw.cxx
#include<iomanip.h>
#include<iostream.h>
#include<string>
void print(string fn, char mi, string ln, string id, double s);
main()
{
string firstName, lastName, id;
string middleInitial;
double salary;
for(int i = 0; i < 3; i++)
{
cout << "Enter a first name, middle initial, last name, id, and salary:\n";
cin >> firstName >> middleInitial >> lastName >> id >> salary;
print(firstName, middleInitial[0], lastName, id, salary);
}
}
void print(string fn, char mi, string ln, string id, double s)
{
cout << setw(13) << fn.c_str()
<< ' ' << mi << ". "
<< setw(20) << ln.c_str()
<< setiosflags(ios::right) << setw(6) << id.c_str()
<< setw(14)
<< setprecision(2) << setiosflags(ios::fixed | ios::showpoint) << s
<< '\n';
}
This page was last updated on 04.05.03.