-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPuzzle.cpp
More file actions
55 lines (42 loc) · 1.03 KB
/
Copy pathPuzzle.cpp
File metadata and controls
55 lines (42 loc) · 1.03 KB
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
#include "Puzzle.h"
Puzzle::Puzzle(std::string fileName)
{
this->correctAnswer = 0;
std::ifstream infile(fileName);
int numOfAns = 0; //number of answers
std::string answer = "";
if (infile.is_open())
{
std::getline(infile, this->question);
infile >> numOfAns;
infile.ignore();
for (size_t i = 0; i < numOfAns; i++)
{
std::getline(infile, answer);
this->answers.push_back(answer);
}
infile >> correctAnswer;
this->correctAnswer = correctAnswer;
infile.ignore();
}
else
throw("Could not open puzzle!");
infile.close();
}
Puzzle::~Puzzle() //virtual deconstructor
{
//something is supposed to go here :P
}
std::string Puzzle::getAsString()
{
std::string answers = "";
for (size_t i = 0; i < this->answers.size(); i++)
{
answers += std::to_string(i+1) + ": " + this->answers[i] + '\n';
}
/*return this->question + '\n' + '\n' +
answers + '\n' +
std::to_string(this->correctAnswer) + '\n';*/
return this->question + '\n' + '\n' +
answers + '\n';
}