Getting "Segmentation fault (core dumped)"

I use Ubuntu 12.10 as my operating system, and I'm not sure if this is related to that, but that's what I get when I compile my code - No errors, just get that in my terminal.

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
135
136
137
138
139
140
141
142
143
144
145
#include <iostream>
#include <string>

#include "GradeBook.h"

using namespace std;

int main()
{
    int gradesArray[10] = {99, 58, 78, 93, 84, 81, 75, 91, 78, 85};

    GradeBook myGradeBook("Intro to C++ Programming", gradesArray);

    myGradeBook.displayMessage();
    myGradeBook.processGrades();


    return 0;
}


#include <iostream>
#include <string>
#include <iomanip>

using namespace std;

class GradeBook{

public:

const static int students = 10;


GradeBook(string Name, const int gradesArray[]){

    setCourseName(Name);

    for (int i = 0; i < students; i++)
    grades[i] = gradesArray[i];
}
string getCourseName(){
return courseName;
}

void setCourseName(string Name){
courseName = Name;
}

void displayMessage(){
cout << "\nWelcome to the GradeBook for " << getCourseName() << "!\n";
}

void processGrades(){

outputGrades();

cout << "\nThe highest grade is " << setprecision(2) << fixed << getMaximum() << "\nThe lowest grade is " << getMinimum() << "\nThe average is " << getAverage() << endl;

outputBarChart();

}

void outputGrades(){

cout << "\nThe class grades are: \n";

for (int i = 0; i < students; i++)
cout << "\nStudent " << setw(2) << students + 1 << ": " << setw(3) << grades[i] << endl;

}

void outputBarChart(){

    cout << "\nGrade Distribution: \n";

    const int frequencySize = 11;
    int frequency[frequencySize] = {};

    for (int i = 0; i < frequencySize; i++)
    frequency[grades[i]/10]++;

    for (int k = 0; k < frequencySize; k++)
    {

        if (k == 0)
        cout << " 0-9 ";
        else if (k == 10)
        cout << " 100: ";
        else
        cout << k * 10 << "-" << (k * 10) + 9 << ": ";

        for (int z = 0; z < frequency[k]; z++)
        cout << '*';

        cout << endl;

    }

}

double getAverage(){

    int total = 0;

    for (int i = 0; i < students; i++)
    total += grades[i];

    return static_cast<double>(total)/students;

}

int getMinimum(){

int lowGrade = 100;
for (int i = 0; i < students; i++)

if (grades[i] < lowGrade){
    lowGrade = grades[i];
}

return lowGrade;

}

int getMaximum(){

int highGrade = 0;
for (int i = 0; i < students; i++)

if (grades[i] > highGrade){
    highGrade = grades[i];
}

return highGrade;

}


private:

string courseName = "";
int grades[] = {};

};
Line 143
int grades[] = {};
You did not size your array. Size should be 10 I guess.

Line 77, try const int frequencySize = 10;

You should learn gdb. Also compile and test often.
That was definitely it...Thanks man!
Topic archived. No new replies allowed.