diff --git a/L3agenda.org b/L3agenda.org new file mode 100644 index 0000000..5751096 --- /dev/null +++ b/L3agenda.org @@ -0,0 +1,13 @@ +* Lecture 3 agenda (January 22nd 2024) + + Venting about being iced in! + + Formatting (a.k.a let's make a table!!!) + + setw + + left + + right + + setfill + + setprecision + + fixed + + Review of while-loops + + Review of if-statements + + A taste of for-loops (and what they're good for) + + Time to work diff --git a/firstSetw.cpp b/firstSetw.cpp new file mode 100644 index 0000000..004ee98 --- /dev/null +++ b/firstSetw.cpp @@ -0,0 +1,39 @@ +#include +#include +using namespace std; + +int main() { + cout << "This is how " << 10 << " things normally appear" << endl; + + cout << "(Now with default alignment and a width of 20)" << endl; + + cout << setw(20) << "This is how " << setw(20) << 10 << setw(20) << " things normally appear" << endl; + + cout << "Why doesn't the last bit look right aligned?" << endl; + + cout << "Now for messing with alignment" << endl; + + cout << left << setw(20) << "This is how " << right << setw(20) << 10 << setfill('*') << left << setw(40) << " things normally appear" << endl; + + cout << endl << endl; + + cout << "Now let's build a table" << endl; + + //we build the top of the table + cout << setfill('-'); + cout << right; + cout << "|" << setw(21); + cout << "|" << setw(21); + cout << "|" << setw(21) << "|" << endl; + cout << setfill(' '); + + cout << left; + + cout << "|" << setw(20) << "Ink name"; + cout << "|" << setw(20) << "Color"; + cout << "|" << setw(20) << "Brand name" << "|" << endl; + + // we can build the rest of the table + + return 0; +}