It seems your teacher wants you to work on input/output manipulators for a while.
So:
a) copy that table in a list of lines to be displayed on screen.
Ok, I’ve already done it for you:
1 2 3 4 5 6 7 8 9 10 11
|
#include <iostream>
int main()
{
std::cout << "NFC East team" << " W" << " L" << " T" << " Pct" << " PF" << " PA\n";
std::cout << "Dallas Cowboys" << 13 << 3 << 0 << 813 << 421 << 306 << '\n';
std::cout << "New York Giants" << 11 << 5 << 0 << 688 << 310 << 284 << '\n';
std::cout << "Washington Redskins" << 8 << 7 << 1 << 531 << 396 << 383 << '\n';
std::cout << "Philadelphia Eagles" << 7 << 9 << 0 << 438 << 367 << 331 << '\n';
return 0;
}
|
(Check if there are errors, please)
Now, if you execute the above code, the result is far from legible:
NFC East team W L T Pct PF PA
Dallas Cowboys1330813421306
New York Giants1150688310284
Washington Redskins871531396383
Philadelphia Eagles790438367331 |
Can you see the problem? Spaces between columns are missed.
So:
b)
See how close you can get to this table using the formatting tools we discussed in class |
You should know what the ‘formatting tools’ are, but I’m giving you three hints:
http://en.cppreference.com/w/cpp/io/manip
https://www.youtube.com/watch?v=TmFNZxDw9mk
A code to start with:
1 2 3 4 5 6 7 8 9 10 11 12
|
#include <iomanip>
#include <iostream>
int main()
{
std::cout << std::setw(20) << std::left << "NFC East team" << " W" << " L" << " T" << " Pct" << " PF" << " PA\n";
std::cout << std::setw(20) << std::left << "Dallas Cowboys" << 13 << 3 << 0 << 813 << 421 << 306 << '\n';
std::cout << std::setw(20) << std::left << "New York Giants" << 11 << 5 << 0 << 688 << 310 << 284 << '\n';
std::cout << std::setw(20) << std::left << "Washington Redskins" << 8 << 7 << 1 << 531 << 396 << 383 << '\n';
std::cout << std::setw(20) << std::left << "Philadelphia Eagles" << 7 << 9 << 0 << 438 << 367 << 331 << '\n';
return 0;
}
|
c) Teachers usually feel depressed when they discover their students ask for assignment solutions on forums, and they also browse forums to catch them.
I suppose nobody has ever told it you, otherwise you wouldn’t have posted with your real name (ok, maybe that isn’t your real name).
Also, a lot of people on forums disapprove those who give solutions to assignments.
I think you'd better ask for help on errors on your code than for entire solutions.