summaryrefslogtreecommitdiffstats
path: root/C++/manipulatorPractice
diff options
context:
space:
mode:
Diffstat (limited to 'C++/manipulatorPractice')
-rw-r--r--C++/manipulatorPractice/manipulatorPractice.cpp56
1 files changed, 56 insertions, 0 deletions
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 <iostream>
+#include <string>
+#include <iomanip> // 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;
+}