Issues compiling

Okay so my program would compile and work fine when I used codeblocks at school but when I use QT or the codeblocks I have at home it no longer works. I believe this is because of my multidimensional array. The program reads in from and input file divides things into arrays converts string to int for one array does some math then prints everything in SVG to make a bar graph.

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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288

#include <iostream>
#include <fstream>
#include <string>
#include <cstring>
#include <cstdlib>

using namespace std;

void in_out_files(ifstream& fin, ofstream& fout1, ofstream &fout2, ofstream &fout3);


void read(ifstream& fin, string Names_first_last[][2], string test_grades[][10], int& max, int &amt_students);

void convert(string test_grades[][10], int test_grades_int[][10], int amt_students, int max);


void average_test(int test_grades_int[][10], double test_avg[], int max, int amt_students);


void student_average(double student_test_avg[],int test_grades_int[][10], int max, int amt_students);

void print_student_avg(double student_test_avg[], ofstream& fout1, int amt_students, string Names_first_last[][2]);




int main()
{
    const int NAMES = 2;
    const int rows = 20;
    int max = 0;
    int amt_students = 0;
    ifstream fin;
    ofstream fout1, fout2, fout3;
    string Names_first_last[rows][NAMES];
    string test_grades[rows][10];
    int test_grades_int[rows][10];
    double test_avg[max];
    double student_test_avg[amt_students];

    in_out_files(fin, fout1, fout2, fout3);
    read(fin, Names_first_last, test_grades, max, amt_students);
    convert(test_grades, test_grades_int, amt_students, max);
    average_test(test_grades_int, test_avg, max, amt_students);
    student_average(student_test_avg,test_grades_int, max, amt_students);
    print_student_avg(student_test_avg, fout1, amt_students, Names_first_last);

    cout << "TEST 2" << endl;
    fin.close();
    fout1.close();

    return 0;
}

void in_out_files(ifstream& fin, ofstream& fout1, ofstream& fout2, ofstream& fout3)
{
    fin.open("gradebook.txt");
    if (fin.fail( ))
    {
        cout << "Input file opening failed.\n";
        exit(1);
    }
    else
    {
        cout << "input opened \n";
    }
    fout1.open("student_avg.svg");
    if (fout1.fail( ))
    {
        cout << "output file 1 opening failed.\n";
        exit(1);
    }
    else
    {
        cout << "output file 1 opened \n";
    }
    fout2.open("test_avg.svg");
    if (fout2.fail( ))
    {
        cout << "output file 2 opening  failed.\n";
        exit(1);
    }
    else
    {
        cout << "output file 2 opened \n";
    }
    fout3.open("sorted test avg.svg");
    if (fout3.fail( ))
    {
        cout << "output file 3 opening failed.\n";
        exit(1);
    }
    else
    {
        cout << "output file 3 opened \n";
    }
}
void read(ifstream& fin, string Names_first_last[][2], string test_grades[][10], int &max, int& amt_students)
{
    string next;
    string grades;
    char ch;
    int row = 0;
    int test_num = 0;
    do
    {
        test_num = 0;
        for(int i = 0; i < 2; i++)
        {
            fin >> next;
            Names_first_last[row][i] = next;
            cout << Names_first_last[row][i] << " ";
        }

        do
        {
            fin.get(ch);
            if(isdigit(ch))
            {

                fin.putback(ch);
                fin >> grades;
                test_grades[row][test_num] = grades;
                cout << test_grades[row][test_num] << " ";
                test_num++;
            }

        }while(ch != '\n');
        if (test_num > max)
        {
            max = test_num;
        }


        cout << endl;
        row++;
        amt_students = row;
        fin.get(ch);
        if (!fin.eof())
        {
            fin.putback(ch);
        }
    }while(!fin.eof());
    amt_students = row;

}
void convert(string test_grades[][10], int test_grades_int[][10], int amt_students, int max)
{
    int row = 0;
    while(row < amt_students)
    {
        for(int i = 0; i < max; i++)
        {
            int temp = atoi(test_grades[row][i].c_str());
            test_grades_int[row][i] = temp;
            cout << test_grades_int[row][i] << " ";
        }
        cout << endl;
        row++;
    }
}
void average_test(int test_grades_int[][10], double test_avg[], int max, int amt_students)
{
    cout <<" MAX " << max << " MAX" << endl;
    double temp_avg = 0.0;
    int column = 0;
    cout <<" amt_students " << amt_students << " amt_students" << endl;

    while(column < max )
    {
        for (int i = 0; i < amt_students; i++)
        {
            temp_avg = (temp_avg + test_grades_int[i][column]);
        }
        test_avg[column] = temp_avg / amt_students;
        cout << "test: " << column << " " << test_avg[column] << endl;

        column++;
        temp_avg = 0;
    }
    cout << " TEST " << endl;

}
void student_average(double student_test_avg[],int test_grades_int[][10], int max, int amt_students)
{
    cout <<" MAX " << max << " MAX" << endl;
    double temp_avg = 0.0;
    int row = 0;
    cout <<" amt_students " << amt_students << " amt_students" << endl;

    while(row < amt_students )
    {
        for (int i = 0; i < max; i++)
        {
            temp_avg = (temp_avg + test_grades_int[row][i]);
        }
        student_test_avg[row] = temp_avg / max;
        cout << "student: " << row << " " << student_test_avg[row] << endl;

        row++;
        temp_avg = 0;
    }
}
void print_student_avg(double student_test_avg[], ofstream& fout1, int amt_students, string Names_first_last[][2])
{
    int Y[amt_students];
    int H[amt_students];
    string last, first;

    fout1 << "<?xml version=\"1.0\" standalone=\"no\"?>"<< endl;
    fout1 << "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\""<< endl;
    fout1 << "\"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">"<< endl;
    fout1 << "<svg width=\"1000\" height=\"1000\""<< endl;
    fout1 << "xmlns=\"http://www.w3.org/2000/svg\">"<< endl;
    fout1 << "<line x1=\"45\" y1=\"0\" x2=\"45\" y2=\"500\""<< endl;
    fout1 << "style=\"stroke:purple;stroke-width:2\"/>"<< endl;
    fout1 << "<line x1=\"45\" y1=\"500\" x2=\"800\" y2=\"500 \""<< endl;
    fout1 << "style=\"stroke:purple;stroke-width:2\"/>"<< endl;
    fout1 << "<svg xmlns=\"http://www.w3.org/2000/svg\"" << endl;
    fout1 << "xmlns:xlink=\"http://www.w3.org/1999/xlink\">\"" << endl;
    fout1 << "<text x=\""<< "200" <<"\" y=\""<< 75 <<"\" >" << endl;
    fout1 << "STUDENT AVERAGES ON TEST" <<endl;
    fout1 << "</text>" << endl;
    fout1 << "<text x=\""<< "0" <<"\" y=\""<< 100 <<"\" >" << endl;
    fout1 << "100%" <<endl;
    fout1 << "</text>" << endl;
    fout1 << "<text x=\""<< "0" <<"\" y=\""<< 200 <<"\" >" << endl;
    fout1 << "75%" <<endl;
    fout1 << "</text>" << endl;
    fout1 << "<text x=\""<< "0" <<"\" y=\""<< 300 <<"\" >" << endl;
    fout1 << "50%" <<endl;
    fout1 << "</text>" << endl;
    fout1 << "<text x=\""<< "0" <<"\" y=\""<< 400 <<"\" >" << endl;
    fout1 << "25%" <<endl;
    fout1 << "</text>" << endl;


    for(int i = 0; i < amt_students; i++)
    {
        H[i] = (student_test_avg[i] / 100) * 400;
        Y[i] = 400 - H[i];
        int Gcolor = 0, Rcolor = 0;
        if (student_test_avg[i] >= 90)
        {
            Gcolor = 255;
            Rcolor = 0;
        }
        else if (student_test_avg[i] >= 80 && student_test_avg[i] < 90)
        {
            Gcolor = 225;
            Rcolor = 75;
        }
        else if (student_test_avg[i] >= 70 && student_test_avg[i] < 80)
        {
            Gcolor = 225;
            Rcolor = 150;
        }
        else if (student_test_avg[i] >= 60 && student_test_avg[i] < 70)
        {
            Gcolor = 200;
            Rcolor = 200;
        }
        else if (student_test_avg[i] < 60)
        {
            Gcolor = 0;
            Rcolor = 255;
        }
        fout1 << "<rect x=\""<< (i * 30) + 50 <<"\" y=\""<< Y[i] + 100 <<"\" width=\"20\" height=\""<< H[i] <<"\""<< endl;
        fout1 << "style=\"fill:rgb("<< Rcolor <<","<< Gcolor <<","<< 0  <<");\"/>"<< endl;
    }

    for(int i = 0; i < amt_students; i++)
    {
        H[i] = (student_test_avg[i] / 100) * 400;
        Y[i] = 400 - H[i];
        last = Names_first_last[i][0];
        first = Names_first_last[i][1];
    fout1 << "<svg xmlns=\"http://www.w3.org/2000/svg\"" << endl;
    fout1 << "xmlns:xlink=\"http://www.w3.org/1999/xlink\">\"" << endl;
    fout1 << "<text x=\""<< (i * 30) + 50 <<"\" y=\""<< 505 <<"\" style=\"writing-mode: tb;\">" << endl;
    fout1 << last <<", " << first << endl;
    fout1 << "</text>" << endl;
    }
    fout1 << "</svg"<< endl;

}
Last edited on
So commenting out line 176 lets the program run and compile without crashing but obviously screws my math up. Anyone able to tell me why?
Last edited on
Line 38 messed me up had a parameter the changed values in there
Topic archived. No new replies allowed.