-
Notifications
You must be signed in to change notification settings - Fork 0
/
question.cc
62 lines (51 loc) · 1.03 KB
/
question.cc
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
// question.cc
#include "question.h"
#include <string.h>
using namespace std;
QUESTION::QUESTION()
{
question_text[0] = '\0';
version = 1;
}
QUESTION::QUESTION(char *qtext)
{
strncpy(question_text, qtext, 1023);
question_text[1023] = '\0';
version = 1;
}
void QUESTION::settext(char *newtext)
{
strncpy(question_text, newtext, 1023);
question_text[1023] = '\0';
}
char * QUESTION::gettext()
{
return strdup(question_text);
}
void QUESTION::print()
{
cout << "Question, version " << version << "\n[" << question_text << "]\n";
}
void QUESTION::pversion()
{
cout << "QUESTION CLASS version " << version << "\n";
}
// overloaded operators
void QUESTION::operator=(QUESTION q1)
{
strncpy(question_text, q1.gettext(), 1023);
question_text[1023] = '\0';
}
void QUESTION::readFromDisk(FILE *fp)
{
fscanf(fp, "%d", &version);
fscanf(fp, "\n");
fgetstr(fp, question_text);
fscanf(fp, "\n");
}
void QUESTION::writeToDisk(FILE *fp)
{
fprintf(fp, "%d\n", version);
fputstr(fp, question_text);
fprintf(fp, "\n");
}