need help to get program to load/read txt file

Below is the code I have and i am in need of help getting program to load a text file so the user can take exam and then display results. I think once if figure out how to do this the program will/should work? i would appreciate and suggestions on how to this? Thanks in advance.

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

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

using namespace std;

class Question
{
private:
	string question, answer;
	int value;
	string questiontype;
public:
	Question() {};
	Question(string theQuestion, int pointValue)
	{
		question = theQuestion;
		value = pointValue;
	}

	string getQuestion()
	{
		return question;
	}
	virtual void setQuestion(string answer, int value)
	{
	}
	virtual void setNewQuestion(string answer, int value)
	{
	}
	int getValue()
	{
		return value;
	}
	virtual string printOptions() { return ""; };
	virtual string getAnswer() { return ""; };

};


class QuestionTF : public Question
{
private:
	string answer;
public:
	QuestionTF(string theQuestion, int pointValue, string theAnswer) : Question(theQuestion, pointValue)
	{
		answer = theAnswer;
	}
	string printOptions()
	{
		return "True / False";
	}
	string getAnswer()
	{
		return answer;
	}
};


class QuestionMC : public Question
{
private:
	string answer;
	string options[6];
public:
	QuestionMC(string theQuestion, int pointValue, string theAnswer) : Question(theQuestion, pointValue)
	{
		answer = theAnswer;
		for (int i = 0; i < 6; i++)
		{
			options[i] = "";
		}
	}
	void addOption(string anOption, int i)
	{

		options[i] = anOption;
	}
	string printOptions()
	{
		string str = "";
		for (int i = 0; i < 6; i++)
		{
			str = str + (char)(65 + i) + "." + options[i] + "\n";
		}
		return str;
	}
	string getAnswer()
	{
		return answer;
	}
};

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;
	}
};

class Examination
{
private:
	vector<Question*> 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 < numberofquestions; i++)
		{
			fin >> questiontype;
			if (questiontype == "TF")
			{
				fin >> pointvalue;
				fin >> extra;
				getline(fin, questiontext);
				extra.append(questiontext);
				fin >> correctanswer;
				QuestionTF* questiontf = new QuestionTF(extra, pointvalue, correctanswer);
				questions.push_back(questiontf);

			}
			else if (questiontype == "MC")
			{

				fin >> pointvalue;
				fin.ignore();
				getline(fin, questiontext);
				int numberofoptions;
				fin >> numberofoptions;
				//cout<<"the no of options"<<numberofoptions<<endl;
				string* answers;
				answers = new string[numberofoptions];
				fin.ignore();
				for (int i = 0; i < numberofoptions; i++)
				{
					getline(fin, answers[i]);
					//cout<<answers[i]<<endl;
				}
				fin >> correctanswer;

				QuestionMC* questionmc = new QuestionMC(questiontext, pointvalue, correctanswer);
				for (int i = 0; i < numberofoptions; i++)
				{
					//cout<<answers[i]<<endl;
					questionmc->addOption(answers[i], i);
				}
				questions.push_back(questionmc);

			}
		}
	}
	int GetNumberOfQuestions()
	{
		return questions.size();
	}
	string getCorrectAnswer(int index)
	{
		return questions[index]->getAnswer();
	}
	void DisplayIthQuestion(int index)
	{
		cout << "Question #" << (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 < questions.size(); i++)
		{
			cout << "Question #" << (i + 1) << ": ";
			cout << questions[i]->getQuestion() << endl;
			cout << questions[i]->printOptions() << endl;
			cout << "Correct Answer: " << questions[i]->getAnswer() << endl << endl;
		}
	}
};


string ConvertToupper(string str)
{
	for (int i = 0; i < str.length(); i++)
	{
		str[i] = toupper(str[i]);
	}
	return str;
};

char DisplayMenu()
{
	char option;
	while (true)
	{
		cout << "\n""Exam Menu:""\n";
		cout << endl;
		cout << "  1. Load Exam" << endl;
		cout << "  2. Take Exam" << endl;
		cout << "  3. Display Results" << endl;
		cout << "  4. Quit" "\n" << endl;
		cout << "Make a Selection: ";
		cin >> option;
		option = toupper(option);
		if (option == '1' || option == '2' || option == '3' || option == '4')
			return option;
		else
			cout << "Enter a valid option." << endl;
	}
};


char DisplayMenu();
string ConvertToupper(string str);

int main()
{

	int numquestions, choice;
	string examName = "Exam.txt ";
	Examination exam;
	char option;
	int totalpoints = 0;
	int totalAvailablePoints = 0;
	option = DisplayMenu();
	Student student;

	while (option != '4')
	{
		switch (option)
		{
		case '1':
		{
			string filename;
			cout << "\n""Enter filename: ";
			cin >> filename;
			ifstream fin;
			fin.open(filename.c_str());
			while (!fin)
			{
				cout << "\n""Error! Input file does not exists. Try again.""\n" << endl;
				cout << "Enter filename: ";
				cin >> filename;
				fin.open(filename.c_str());
			}
			exam.LoadQuestions(fin);

			fin.close();
		}
		break;
		case  '2':
		{
			string answer;

			for (int i = 0; i < exam.GetNumberOfQuestions(); i++)
			{
				cout << endl;
				exam.DisplayIthQuestion(i);
				cout << "\n""Enter correct answer: ";
				cin >> answer;
				answer = ConvertToupper(answer);
				string correct = ConvertToupper(exam.getCorrectAnswer(i));
				if (answer == correct)
				{
					student.SetPointsScored(student.GetPointsScored() + exam.getPointsValue(i));

					cout << "Correct""\n" << endl;
				}
				else
				{
					cout << "Incorrect""\n" << endl;
					cout << "The correct answer is: " << correct << endl;
				}

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

		}
		break;
		case  '3':
		{
			cout << "\n""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();
	}
	getchar();
	return 0;
}
Well, strictly speaking, that's the code you got from Chegg.com
@lastchance,
how did you find out?
Google one of the more esoteric phrases in it. I think I tried one of the weird QuestionMC ones.

It's the sort of code where ... if you'd written the code you wouldn't need to ask the question.

@lastchance,
I see. I found it here also http://www.cplusplus.com/forum/general/185771/
Topic archived. No new replies allowed.