the good ol EXPECTED unqualified ID before 'public'

this error has my program completely hung

code in q:

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
#include <iostream>

#include <string>

#include <fstream>

#include <cstdlib>

#include <vector>

using namespace std;


class Question

public:
{
              Question();

              Question(std::string theQuestion, int pointValue);
					{
             question=theQuestion;

              value=pointValue;
              }


              std::string getQuestion();
              {
                return question;
              }


              int getValue();
              {
                return value;
              }

              virtual std::string printOptions(){return "";};

              virtual std::string getAnswer(){return "";};
private:


              std::string question;

              int value;
};


Its taking me to this class when I attempt to compile it.


Any help would be great. Or maybe point me in the right direction. I can upload the full source code if that would help but it said it was to long.

1
2
3
4
5
6
Question(std::string theQuestion, int pointValue);
					{
             question=theQuestion;

              value=pointValue;
              }


you should remove semicolon after function signature, present also in other functions.
Perhaps you should consider moving "public:" to after the opening brace of the class?

Here's as far as I made it.

Still throwing mad errors.....


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
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
#include <iostream>

#include <string>

#include <fstream>

#include <cstdlib>

#include <vector>

using namespace std;


class Question
{

public:


Question(std::string theQuestion, int pointValue)
{
question=theQuestion;

value=pointValue;
}


std::string getQuestion()
{
return question;
}


int getValue()
{
return value;
}

virtual std::string printOptions(){return "";};

virtual std::string getAnswer(){return "";};

private:
std::string question;
int value;
};


class QuestionMC : public Question
{


public:


QuestionMC(std::string theQuestion, int pointValue, std::string theAnswer) : Question(theQuestion, pointValue)
{

answer = theAnswer;

for (int i=0; i<6; i++)

{

options[i] = "";

}
private:

std::string answer;

std::string options[6];
}

void addOption(string anOption)

{

for (int i=0; i<6; i++)

{

if (options[i]=="")

{

              options[i] = anOption;

              break;

}

}

}

string printOptions()

{

string str = "";

for (int i=0; i<6; i++)

{

if (options[i] != "")

{

              str = str + (char)(65+i) + ". " + options[i] + "\n";

}

else

{

              break;

}



}

return str;

}

string getAnswer()

{

return answer;

}

};



class QuestionTF : public Question

{

private:

string answer;

public:

QuestionTF(string theQuestion, int pointValue, string theAnswer) : Question(theQuestion, pointValue)

{

answer = theAnswer;

}

string printOptions()

{

return "True or False";

}

string getAnswer()

{

return answer;

}

};



class Examination

{

private:

vector questions;

public:

void LoadQuestions(ifstream &fin)

{

questions.clear();

int numberofquestions;

string questiontype;

string questiontext;

string correctanswer;



int pointvalue;



fin >> numberofquestions;



string extra;

char ex;

for (int i=0; i;)

{

fin >> questiontype;

if (questiontype == "TF")

{

              fin >> pointvalue;

              fin >> extra;

              getline(fin, questiontext);



              fin >> correctanswer;

              QuestionTF *questiontf = new QuestionTF(questiontext, pointvalue, correctanswer);

              questions.push_back(questiontf);                                                     

}

else if (questiontype == "MC")

{



              fin >> pointvalue;

              fin.ignore();

              getline(fin, questiontext);

              int numberofoptions;

              fin >> numberofoptions;

              string *answers;

              answers = new string[numberofoptions];

              fin.ignore();

              for (int i=0; i;)

              {

                            getline(fin, answers[i]);

             

              }

              fin >> correctanswer;

              QuestionMC *questionmc = new QuestionMC(questiontext, pointvalue, correctanswer);

              for (int i=0; i<1; i;)

              {

                            questionmc->addOption(answers[i]);

              }

              questions.push_back(questionmc);

}

}

}

int GetNumberOfQuestions()

{

return questions.size();

}

string getCorrectAnswer(int index)

{

return questions[index]->getAnswer();

}

void DisplayIthQuestion(int index)

{

cout << "Question Number" << (index+1) << ": ";

cout << questions[index]->getQuestion() << endl;

cout << questions[index]->printOptions() << endl;

}

int getPointsValue(int i)

{

return questions[i]->getValue();

}

void DisplayQuestions()

{

for (int i=0; i;i++)

{

cout << "Question Number" << (i+1) << ": ";

cout << questions[i]->getQuestion() << endl;

cout << questions[i]->printOptions() << endl;

cout << "Correct Answer: " << questions[i]->getAnswer() << endl << endl;

}

}

};


class Student

{

private:

int pointsAvailable;

int pointsScored;

public:

Student()

{

pointsAvailable = 0;

pointsScored = 0;

}

void SetPointsScored(int point)

{

pointsScored = point;

}

int GetPointsScored()

{

return pointsScored;

}

void SetPointsAvailable(int point)

{

pointsAvailable = point;

}

int GetPointsAvailable()

{

return pointsAvailable;

}

};



char DisplayMenu();

string ConvertToupper(string str);



int main()

{

Examination exam;

char option;

int totalpoints = 0;

int totalAvailablePoints = 0;

option = DisplayMenu();

Student student;

while (option != 'Q')

{

switch (option)

{

case 'L':

{

string filename;

cout << "Enter the filename: ";

cin >> filename;

ifstream fin;

fin.open(filename.c_str());

while (!fin)

{

cout << "Error: Input file does not exists. Try again." << endl;

cout << "Enter the filename: ";

cin >> filename;

fin.open(filename.c_str());

}

exam.LoadQuestions(fin);

fin.close();

}

break;

case  'T':

{

string answer;

for (int i=0; i<1; i++)

{

cout << endl;

exam.DisplayIthQuestion(i);

cout << "Enter correct answer: ";

cin >> answer;

answer = ConvertToupper(answer);

string correct = ConvertToupper(exam.getCorrectAnswer(i));

cout << "The correct answer is: " << correct << endl;

if (answer == correct)

{

student.SetPointsScored (student.GetPointsScored() + exam.getPointsValue(i));

cout << "Good job here!" << endl;

}

else

{

cout << "Better luck next time...." << endl;

}

student.SetPointsAvailable (student.GetPointsAvailable() + exam.getPointsValue(i));

}


}

break;

case  'S':

{

cout << "Total points available: " << student.GetPointsAvailable() << endl;

cout << "Total points scored: " << student.GetPointsScored() << endl;

cout << "Percentage of points: " << ((double)student.GetPointsScored()/(double)student.GetPointsAvailable()) * 100.0 << endl;

}

break;

}

option = DisplayMenu();

}

return 0;

}



string ConvertToupper(string str)

{

for (int i=0 ;i;)

{

str[i] = toupper(str[i]);

}

return str;

}

char DisplayMenu()

{

char option;

while (true)

{

cout << endl << "\tL - Load an Exam" << endl;

cout << "\tT -Take an exam Exam" << endl;

cout << "\tS - Show exam results" << endl;

cout << "\tQ - Quit" << endl;

cout << "Enter an option: ";

cin >> option;

option = toupper (option);

if (option == 'L' || option == 'T' || option == 'S' ||option == 'Q')

return option;

else

cout << "ERROR: Input a valid option." << endl;

}
}


Essentially it's supposed to be a program that displays a menu and allows the user to pick from a set of options

1.load exam
2.take exam
3.show exam
4.quit

In other sections we created a program that creates the "exams" I mentioned which just names the text file "exam.txt"

At this point I am thinking that I should've just wrote the program from scratch instead of using this really buggy sample code.


Anyway....If anyone wants to try to figure it out have at it.
This semester (as far as this class goes) is toast.
Source code from the previous project. Apparently there is supposed to be a bit of synergy between these two but for some reason, I can't see it.

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
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
//Week 4 Sample Solution to build upon in Week 5

//CS 215

//Dr. Howard Evans



#include <iostream>

#include <string>

#include <fstream>

#include <cstdlib>



using namespace std;











class Question // super class

{

public:



string getQuestion()//gets the question

{

return question;

}



virtual int getValue() //gets the point value of the question

{

return value;

}



virtual string getQuestionType()// gets the type of question

{

return questiontype;

}





virtual void setQuestion(string answer, int value)

{

}

virtual void setNewQuestion(string answer, int value)

{

}

virtual void printOptions()

{

}



virtual string getAnswer()

{

return answer;

}



private:

string question,  answer;

int value;

string questiontype;

};





class QuestionTF: public Question// class for true and false questions

{

public:

void setQuestion(string theQuestion, int pointValue)

{

string theAnswer;

questiontype = "TF";

question = theQuestion;

value = pointValue;

options = "true/false";

//get the answer from the file

getline(cin,theAnswer);

answer = theAnswer;

}



void setNewQuestion(string theQuestion, int pointValue)

{

string theAnswer;

questiontype = "TF";

question = theQuestion;

value = pointValue;

options = "true/false";

//get the answer from user

cout<<"Enter answer true/false\n";

getline(cin,theAnswer);

answer = theAnswer;

}



int getValue() //gets the point value of the question

{

return value;

}



string getQuestionType()// gets the type of question

{

return questiontype;

}



void printOptions()//prints the options for that question

{

cout<<question<<endl;

cout<<answer<<endl;

}



string getAnswer()//outputs the answer for that question

{

return answer;

}

private:

string question, questiontype;

string answer;

string options;

int value;

};







class QuestionMC: public Question//class for multiple choice

{

public:

void setQuestion(string theQuestion, int pointValue)

{

string line;

questiontype = "MC";

getline(cin,line);

numberOfOptions = atoi(line.c_str());

cout<<numberOfOptions<<endl;

question = theQuestion;

value = pointValue;

//get the individual choice lines and load to options array

for (int count = 0; count<numberOfOptions;count++){

getline(cin,line);

options[count] = line;

}

//get the answer from the file and load into answer

getline(cin, line);

answer = line;

}



void setNewQuestion(string theQuestion, int pointValue)

{

string line;

questiontype = "MC";

//get the number of choices from the user

cout<<"Enter the number of choices:  ";

getline(cin,line);

numberOfOptions = atoi(line.c_str());



question = theQuestion;

value = pointValue;

//get the individual choice lines and load to options array

for (int count = 0; count<numberOfOptions;count++){

cout<<"\nEnter next option:  ";

getline(cin,line);

options[count] = line;

}

//get the answer from the user and load into answer

cout<<"\nEnter Answer:  ";

getline(cin, line);

answer = line;

}

void printOptions()// prints the questions, options, and answer

{

//char first = 'A';

cout<<question<<endl;

for(int count = 0; count<numberOfOptions;count++){

cout<<options[count]<<"\n";

}

cout<< answer << "\n";

}



int getValue() //gets the point value of the question

{

return value;

}



string getQuestionType()// gets the type of question

{

return questiontype;

}



string getAnswer()// prints the answer

{

return answer;

}

private:

int numberOfOptions;

string question, answer;

string options[6];

string questiontype;

int value;

};



class Exam

{

public:

int loadExam()

{

//ifstream infile;

//string examName = exam;

ifstream infile("exam.txt");

streambuf *cinbuf = cin.rdbuf();       //save old buf

cin.rdbuf(infile.rdbuf());             //redirect std::cin to infile.txt!



string line, theQuestion, questiontype, theAnswer;

int  questionvalue;



//get the number of questions from the first line in the file

getline(cin,line);

numquestions = atoi(line.c_str());

for(int count = 0; count<numquestions;count++){

getline(cin,line);

//get the next line with the question type and the value of the question

int npos = line.size();

int prev_pos = 0;

int pos = 0;

while( line[pos]!=' ')

pos++;

questiontype = line.substr(prev_pos, pos-prev_pos);

prev_pos = ++pos;

questionvalue = atoi(line.substr(prev_pos, npos-prev_pos).c_str()); // Last word



//process a true/false question

if (questiontype == "TF")

{

myQuestions[count] = new QuestionTF;

getline(cin,theQuestion);

myQuestions[count]->setQuestion(theQuestion,questionvalue);

}

//process a multiple choice question

if (questiontype =="MC")

{

myQuestions[count] =new QuestionMC;

getline(cin,theQuestion);

myQuestions[count]->setQuestion(theQuestion,questionvalue);

}



}

cin.rdbuf(cinbuf);   //restore cin to standard input

return numquestions;

}



void displayExamQuestions(int numquestions)

{

string qtype;

//print out the questions that have been processed

for(int count = 0; count<numquestions;count++)

{

qtype=myQuestions[count]->getQuestionType();

cout<<qtype<<" "<<myQuestions[count]->getValue()<<"\n";

myQuestions[count]->printOptions();

cout<<"\n";

}

}





private:



Question *myQuestions[10];

int numquestions;

};



int displayMenu();   //function prototype







int main() {



Exam myExam;

int numquestions, choice;

string examName = "exam.txt";
string outputfilename;
string choice2;





while((choice = displayMenu())!=3)

switch(choice)

{

case 1: numquestions = myExam.loadExam();
if (choice = 1){

cout<<"Which exam file would you like to load?\n";
cin>>choice2;


}


break;

case 2: myExam.displayExamQuestions(numquestions);

break;

default: cout<<"Invalid choice.  Try again.\n";

}



getchar();

return 0;

}



int displayMenu()

{

int choice;



cout<< "Enter your choice for this Exam."<<endl;

cout<< "1.   Load Exam "<<endl;

cout<< "2.   Display Exam "<<endl;

cout<< "3.   Quit"<<endl;

cin>>choice;

return choice;


cin.ignore();

}



Last edited on
Also, sorry about the wack indentations....this is sample code.

Thanks again everyone.
Please fix the "wack indentations" and remove most of those "wack double spacing".

Part of your problems should be much easier to identify if you properly use some indentation style (no indentation is not a style).

You seem to be missing at least one closing brace, proper indentation should help identify where.

Also in future when you have " mad errors....." post the errors, all of them, exactly as they appear in your development environment. These messages should tell you exactly where to start looking for the errors and should even tell you what the errors actually are.

It looks like you tried to write the program in one big chunk instead of compiling early and often, usually after as little as one change/addition to the code.

Topic archived. No new replies allowed.