summaryrefslogtreecommitdiffstats
path: root/C++/manipulatorPractice/manipulatorPractice.cpp
blob: c53a14d8ab9a173091e99741a7951193e9dfd14b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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;
}