C++ IO streams
Simple IO
io manipulations (iomanip)
width, setw, left, right // red ones are most commonly used in formatting
fill, setfill
Pyramid exercise below will get you some practice on controlling the printout. Another good exercise is to print a calendar (one month or one year). Hmmm, how do you compute day of the week?
uppercase, boolalpha
showbase, oct, hex (what's this? number systems, octal, binary, hex)
scientific, fixed (what's this? data types, int, float, bool, unsigned)
cin.eof(), clear, ignore
Unformatted IO
high level (formatted IO) vs low level (unformatted IO)
cout.write(buf, size) versus count << buf;
cin.get(buf, size) versus cin >> i
cin.getline(buf, size)
cin.read
Pyramid example: (refer to pyramid lab)
#include <iomanip>
#include <iostream>
using namespace std;
void pyramidR(int=10);
void pyramidL(int=10);
void main() {
pyramidR(5);
pyramidL();
}
void pyramidR (int n)
{
cout << endl;
while (n>0)
cout << setw(n--) << setfill('*') << right << "" <<endl;
}
void pyramidL (int n)
{
cout << endl;
for (int i=0; i<n; i++) {
for (int k=0; k<n; k++)
if (k < i) cout << " "; else cout << "#";
cout << setw(n-i) << setfill('*') << "" ;
cout << endl;
}
}
Things to know from Pyramid
various iomanip
simple function call with parameter
while loop and for loop
if then else
function declaration with default parameter
FYC -- For Your Consideration
In programming, it is important to learn what works. But, it is even more important to know what won't work. Average programmer handles the first chunk. Experienced programmers are better at the later part. I highly encourage you to try various possibilities and explore.