Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

someone give me a hint to program this in C/C++ histogram input 1 57 51 31 68 98

ID: 3804463 • Letter: S

Question

someone give me a hint to program this in C/C++

histogram input

1
57
51
31
68
98
6
82
16
79
8
89
64
44
9
60
59
75
58
10
0
30
65
34
80
31
75
79
52
72
92
14
47
71
42
76
67
12
54
97
93
60
10
58
17
4
17
83
20
86
46
17
67
21
82
72
97
40
70
70
1
51
37
47
46
61
30
49
14
39
24
55
24
35
17
12
75
21
59
49
2
93
99
46
44
42
20
15
62
44
54
44
12
4
83
81
20
14
25
87
86
53
74
55
4
19
33
69
8
15
28
72
18
72
62
78
31
16
2
11
42
48
55
13
68
20
14
51
10
31
63
89
60
63
7
62
35
81
92
58
8
89
36
73
29
44
58
41
51
20
58
13
61
17
66
52
38
82
65
24
38
15
25
9
73
16
54
79
25
93
20
65
16
96
30
29
83
52
68
2
43
17
42
7
20
14
65
19
18
11
29
33
37
41
24
98
29
79
51
75
14
38
58
95
91
39
2
50
48
1
8
65
59
59
80
78
17
41
12
45
95
72
28
7
35
0
1
87
28
12
12
16
38
32
39
15
98
24
59
70
95
99
0
45
18
37
83
43
87
95
65
64
69
32
36
3
22
56
88
68
52
58
64
3
40
84
8
32
34
12
15
78
56
64
91
20
95
60
45
99
82
37
82
77
89
21
5
13
1
39
57
25
68
43
81
85
51
96
76
10
85
87
50
63
42
28
18
72
53
99
86
58
49
5
48
56
3
62
74
28
18
99
91
83
50
7
88
60
10
26
5
84
44
43
53
37
36
74
96
2
89
60
14
34
20
56
13
5
15
11
18
11
41
33
7
21
12
32
64
31
0
57
17
13
89
38
24
67
98
73
60
23
21
48
69
37
95
5
80
75
44
21
58
82
81
71
76
80
14
50
80
80
77
89
7
69
100
93
30
91
83
60
18
16
3
17
41
85
16
47
10
0
97
32
8
68
98
86
84
81
32
14
6
80
57
24
81
58
27
91
29
82
6
6
75
92
76
87
4
96
13
68
48
97
49
69
75
39
17
92
83
39
92
29
16
54
73
38
67
28
69
4
76
19
71
77
49
71
56
58
19
14
70
93
46
30
24
22
38
17
58
84
22
85
46
90
7
36
84
7
14
43
32
40
10
26
28
42
28
38
62
49
56
11
13
66
0
37
61
29
45
46
51
70
11
45
69
77
19
81
97
22
65
76
41
79
18
38
80
59
96
77
26
93
93
56
97
9
86
98
73
51
53
36
65
76
40
31
22
50
44
22
63
21
22
4
50
56
34
56
37
47
67
2
75
73
28
5
17
92
69
32
47
81
11
74
65
27
99
68
82
11
38
92
13
32
94
26
91
19
35
82
58
15
70
74
18
67
37
28
54
77
69
73
71
48
83
86
7
83
56
30
3
54
58
78
99
4
69
54
1
82
11
17
14
42
35
89
30
80
75
11
34
86
15
20
54
81
17
8
66
20
33
49
60
72
53
8
93
13
76
23
93
58
17
17
25
2
40
44
62
22
93
27
57
78
87
36
12
6
11
0
98
64
4
11
96
28
98
44
38
40
7
92
94
25
43
56
84
13
67
10
18
14
61
91
91
86
65
62
53
92
77
51
2
88
8
64
75
98
15
45
83
100
11
11
98
17
83
84
49
74
48
13
3
78
86
81
82
76
64
49
97
58
96
53
97
4
47
17
77
33
0
79
63
59
60
72
99
69
64
97
38
8
74
91
48
74
1
58
18
22
25
54
75
38
28
56
79
19
58
92
21
74
75
16
5
83
7
93
94
27
16
25
76
13
34
54
40
45
90
36
8
87
2
20
85
43
36
19
74
19
15
31
29
59
29
43
50
73
53
31
22
57
63
84
30
76
26
25
46
32
37
26
36
100
33
8
10
89
52
21
22
94
18
60
77
46
90
80
59
19
54
71
84
45
72
46
91
58
21
51
80
43
41
29
68
90
100
36
20
84
79
18
4
63
93
30
69
3
5
88
63
39
38
88
58
95
69
31
12
93
55
99
1
86
70
20
42
10
72
93
46
42
35
84
13
89
15
72
86
80
21
96
95
13
38
23
25
93
66
36
94
29
86
27
34
89
86
99
69
65
63
3
92
5
86
17
7
38
67
63
92
24
60
16
8
54
18
53
61
31
91
50
80
3
49
85
17
59
38
71
12
42
91
4
43
69
16
7
69
44
55
27
91
24
8
82
57
84
55
54
59
35
62
30
21
0
15
41
27
88
50
33
24
41
29
36
82
21
31
81
9
35
58
59
5
21
68
54

Write a program that reads a list of a numbers and generates a histogram of the values. Your program must automatically determine the range of values that will go into each histogram "bucket" so that you have ten total buckets in the final histogram with an approximately equal range in each bucket. Plot your final histogram using Xs to create a series of horizontal bars, as shown below. The output should be scaled so that the largest histogram value consists of twenty Xs, and everything else is scaled appropriately. Use the histogram-input. txt file available on moodle to test your program. Recall that you can use the Unix input redirection command, to read a file. 10-19: XXXXXXXXXXXXXXXXXXXX 20-29 XXXXXXXXX

Explanation / Answer


#include <fstream>
#include <iostream>
#include <vector>
using namespace std;


int main()
{

// Declaring vector
vector<int> vec;
int num;
// defines an input stream for the data file
ifstream dataIn;

// Opening the input file
dataIn.open("D:\histogram-input.txt");

/* Getting the values from the file
* and stored into the vector
*/
while (!dataIn.fail())
{
// Getting the number from th file
dataIn >> num;

// populate into vector
vec.push_back(num);
}

// Closing the input stream
dataIn.close();

int count1 = 0, count2 = 0, count3 = 0, count4 = 0, count5 = 0;
int count6 = 0, count7 = 0, count8 = 0, count9 = 0, count10 = 0;
for (int i = 0; i < vec.size(); i++)
{
if (vec[i] >= 1 && vec[i] <= 9)
count1++;
else if (vec[i] >= 10 && vec[i] <= 19)
count2++;
else if (vec[i] >= 20 && vec[i] <= 29)
count3++;
else if (vec[i] >= 30 && vec[i] <= 39)
count4++;
else if (vec[i] >= 40 && vec[i] <= 49)
count5++;
else if (vec[i] >= 50 && vec[i] <= 59)
count6++;
else if (vec[i] >= 60 && vec[i] <= 69)
count7++;
else if (vec[i] >= 70 && vec[i] <= 79)
count8++;
else if (vec[i] >= 80 && vec[i] <= 89)
count9++;
else if (vec[i] >= 90 && vec[i] <= 100)
count10++;
}

// Displaying histogram
cout << "1-9: ";
for (int i = 1; i < count1 / 10; i++)
cout << 'X';
cout << " 10-19: ";
for (int i = 1; i < count2 / 10; i++)
cout << 'X';
cout << " 20-29: ";
for (int i = 1; i < count3 / 10; i++)
cout << 'X';
cout << " 30-39: ";
for (int i = 1; i < count4 / 10; i++)
cout << 'X';
cout << " 40-49: ";
for (int i = 1; i < count5 / 10; i++)
cout << 'X';
cout << " 50-59: ";
for (int i = 1; i < count6 / 10; i++)
cout << 'X';
cout << " 60-69: ";
for (int i = 1; i < count7 / 10; i++)
cout << 'X';
cout << " 70-79: ";
for (int i = 1; i < count8 / 10; i++)
cout << 'X';
cout << " 80-89: ";
for (int i = 1; i < count9 / 10; i++)
cout << 'X';
cout << " 90-100: ";
for (int i = 1; i < count10 / 10; i++)
cout << 'X';
return 0;
}

____________________

histogram-input.txt (save the file under D Drive .Then the path of the file pointing to it is D:\histogram-input.txt)