-
Notifications
You must be signed in to change notification settings - Fork 0
/
ques.cpp
54 lines (47 loc) · 1.15 KB
/
ques.cpp
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
#include "quiz.hpp"
int num_subs;
sub subs[SUB_MAX];
void init_ques(int lvl, int sub, int q_num, question& ques)
{
ifstream subfile(subs[sub].fname);
//gotoline
int curr_line = 1; subfile.seekg(ios::beg);
int desired_line = 1 + 1; int lines_per_q = 7;
for(int i = 0; i < lvl; i++)
{
desired_line += lines_per_q * subs[sub].q_per_level[i]; //Navigating to beginning of the questions of level lvl
}
desired_line += (q_num) * lines_per_q; //Navigating to that question
char line[350];
while(desired_line > curr_line)
{
subfile.getline(line, 350);
curr_line++;
}
// end of gotoline
subfile.getline(ques.q, 200);
for(i = 0; i < 4; i++)
{
subfile.getline(ques.options[i], 200);
}
subfile >> ques.correct;
ques.correct--; //Making it zero indexed
subfile.ignore(100, '\n');
}
void init_qinfo()
{
ifstream qinfo("q_info.txt");
qinfo >> num_subs;
qinfo.ignore(100, '\n');
for(int i = 0; i < num_subs; i++)
{
qinfo.getline(subs[i].fname, 50);
qinfo.getline(subs[i].sub_name, 75);
qinfo.getline(subs[i].short_name, 50);
ifstream subfile(subs[i].fname);
for(int j = 0; j < 3; j++)
{
subfile >> subs[i].q_per_level[j];
}
}
}