blob: 2796a5c31f7ec6e8903848af28d24eaa937d8dba (
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
|
// Musa Ahmed [email protected]
#include <iostream>
#include <iomanip>
#include <string>
#include <list>
#include <bitset>
#include <vector>
#include <math.h>
using std::cout;
using std::ios;
using std::cin;
using std::endl;
using std::string;
using std::to_string;
int main()
{
// All the name strings
string n1;
string n2;
string n3;
string n4;
// all the income floats
float c1;
float c2;
float c3;
float c4;
// All the age ints
int a1;
int a2;
int a3;
int a4;
// spacer for all values on table
int spacer;
// Ask user for first input
cout << "Enter a Name: " << endl;
cin >> n1;
cout << "Enter a Age: " << endl;
cin >> a1;
cout << "Enter an Income: " << endl;
cin >> c1;
// Ask user for second input
cout << "Enter a Name: " << endl;
cin >> n2;
cout << "Enter a Age: " << endl;
cin >> a2;
cout << "Enter an Income: " << endl;
cin >> c2;
// Ask user for third input
cout << "Enter a Name: " << endl;
cin >> n3;
cout << "Enter a Age: " << endl;
cin >> a3;
cout << "Enter an Income: " << endl;
cin >> c3;
// Aks user for fourth input
cout << "Enter a Name: " << endl;
cin >> n4;
cout << "Enter a Age: " << endl;
cin >> a4;
cout << "Enter an Income: " << endl;
cin >> c4;
// PART 2
// Average all the lengths of the names and use this as the spacer
spacer = (n1.size() + n2.size() + n3.size() + n4.size()) / 4 + 5;
// Display the headers of the table
cout.setf(ios::left);
cout.width(spacer);
cout << "Name";
cout.width(spacer);
cout << "Age";
cout.width(spacer);
cout << "Income" << endl;
cout.precision(3);
// Display the first profile
cout.width(spacer);
cout << n1;
cout.width(spacer);
cout.precision(3);
cout << a1;
cout.width(spacer);
cout << c1 << endl;
// Display the first profile
cout.width(spacer);
cout << n2;
cout.width(spacer);
cout.precision(3);
cout << a2;
cout.width(spacer);
cout << c2 << endl;
// Display the first profile
cout.width(spacer);
cout << n3;
cout.width(spacer);
cout.precision(3);
cout << a3;
cout.width(spacer);
cout << c3 << endl;
// Display the first profile
cout.width(spacer);
cout << n4;
cout.width(spacer);
cout.precision(3);
cout << a4;
cout.width(spacer);
cout << c4 << endl;
return 0;
}
|