From 9d53d8857eaa1c9405894a88ca75bc4657e42f35 Mon Sep 17 00:00:00 2001 From: msglm Date: Sat, 14 Jan 2023 05:31:48 -0600 Subject: Inital Commit --- C++/manipulatorPractice/manipulatorPractice.cpp | 56 +++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 C++/manipulatorPractice/manipulatorPractice.cpp (limited to 'C++/manipulatorPractice/manipulatorPractice.cpp') diff --git a/C++/manipulatorPractice/manipulatorPractice.cpp b/C++/manipulatorPractice/manipulatorPractice.cpp new file mode 100644 index 0000000..c53a14d --- /dev/null +++ b/C++/manipulatorPractice/manipulatorPractice.cpp @@ -0,0 +1,56 @@ +// Manipulator practice +// Ch 3: Input/Output +// The purpose of this program is to practice using the some of the manipulators +// covered in Ch 3: fixed, showpoint, setprecision, setw + +#include +#include +#include // needed to use manipulators + +using namespace std; + +int main() +{ + // Variable declarations + string name1, name2; + double score1, score2; + + // Program title and description + cout << "MANIPULATOR PRACTICE" << endl; + cout << "The purpose of this program is to practice using the some of the\n"; + cout << "manipulators covered in Ch 3: fixed, showpoint, setprecision, setw" + << endl << endl; + + // User directions + cout << "You will be asked to enter 2 first names and a score for each.\n"; + cout << "Then you will determine how to print the results in a \n"; + cout << "column format." << endl << endl; + + // Collect user input + cout << "Enter first name for student #1: "; + cin >> name1; + cout << "Enter score for student #1: "; + cin >> score1; + + cout << "Enter first name for student #2: "; + cin >> name2; + cout << "Enter score for student #2: "; + cin >> score2; + + // Instructions for output: + // Determine how to print the results in columns + // Use column headings to label each column + // Determine appropriate alignment for each column + // Determine which manipulators are needed to control numerical output + + // Output results + + //This solution doesn't really work with super long names or super long scores + //I don't know if this is a problem for this assignment or not + //If long names were important, then i'd get the length of the name, add 3 to it, and set that as what setw's value would be. + cout << left << setw(13) << "Name" << right << setw(13) << "Score" << endl; + cout << left << setw(13) << name1 << right << setw(13) << score1 << endl; + cout << left << setw(13) << name2 << right << setw(13) << score2 << endl; + + return 0; +} -- cgit v1.2.3