-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexam_paper.cpp
161 lines (147 loc) · 3.71 KB
/
exam_paper.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
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
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include "exam_paper.h"
using namespace std;
vector<problem*> exam_paper::mypro;
void exam_paper::add(selection *sel){
if(!pro)
pro = new problem*[num_pro];
if(element == num_pro)
return;
pro[element++] = sel;
total += sel->tscore();
}
void exam_paper::add(judgement *jud){
if(!pro)
pro = new problem*[num_pro];
if(element == num_pro)
return;
pro[element++] = jud;
total += jud->tscore();
}
void exam_paper::remove(int i){
if(!pro || i >= element)
return;
delete pro[i];
pro[i] = 0;
}
void exam_paper::givescore(int pos, int ans){
//int last = pro[pos]->hscore();
pro[pos]->judge(ans);
//if(!last)
gets += pro[pos]->hscore();
// else {
// if(!(pro[pos]->hscore()))
// gets -= last;
// }
}
//bool exam_paper::write_to_file(){
// char name[20];
// sprintf_s(name, "%dt", ID);
// ifstream fin;
// fin.open(name, ios::in);
// if(!fin)
// return false;
// ofstream fout(name, ios::out);
// fout << total << " " << num_pro << endl;
// for(int i = 0; i < num_pro; i++)
// fout << pro[i]->Type() << endl << pro[i]->show_comment() << "----" << endl;
// fout.close();
// sprintf_s(name, "%da", ID);
// fout.open(name, ios::out);
// for(int i = 0; i < num_pro; i++)
// fout << pro[i]->show_answer() << " ";
// fout.close();
// return true;
//}
bool exam_paper::read_from_file(){
char name[20];
sprintf_s(name, "%dt", ID);
ifstream fin;
fin.open(name, ios::in);
if(!fin)
return false;
string buffer, comment;
fin >> total >> num_pro;
pro = new problem*[num_pro];
int type;
fin >> type;
while(getline(fin, buffer)){
if(buffer == "----"){
if(type == 1)
pro[element] = new judgement;
else if(type == 2)
pro[element] = new selection;
pro[element]->set_problem(comment);
comment = "";
fin >> type;
element++;
}
else{
comment += buffer+"\n";
}
}
fin.close();
sprintf_s(name, "%da", ID);
fin.open(name, ios::in);
int ans;
element = 0;
while(fin>>ans)
pro[element++]->set_answer(ans);
for(int i = 0; i < num_pro; i++)
cout << pro[i]->show_answer() << "\n";
fin.close();
return true;
}
problem* exam_paper::get(int i){
return pro[i];
}
exam_paper::~exam_paper(){
for(int i = 0; i < num_pro; i++)
delete pro[i];
delete[] pro;
}
void exam_paper::add(problem* p){
exam_paper::mypro.push_back(p);
}
void exam_paper::removes(int i){
exam_paper::mypro.erase(mypro.begin()+i);
}
bool exam_paper::write_to_file(std::string filename){
// ifstream fin;
// fin.open(filename+"t", ios::in);
// if(!fin)
// return false;
// else
// fin.close();
ofstream fout_t(filename+"t", ios::out);
ofstream fout_s(filename+"a", ios::out);
int total = 0;
for(auto it = exam_paper::mypro.begin(); it != exam_paper::mypro.end(); ++it)
total += (*it)->tscore();
fout_t << total << " ";
total = (int)exam_paper::mypro.size();
fout_t << total << "\n";
for(auto it = exam_paper::mypro.begin(); it != exam_paper::mypro.end(); ++it){
fout_t << (*it)->Type() << "\n" << (*it)->show_comment() << "\n" << "----" << "\n";
fout_s << (*it)->show_answer() << " ";
}
fout_t.close();
fout_s.close();
// for(auto it = mypro.begin(); it != mypro.end(); it++)
// delete *it;
// exam_paper::mypro.erase(exam_paper::mypro.begin(), exam_paper::mypro.end());
return true;
}
problem* exam_paper::get_m(int i){
if(i > (int)mypro.size() || i < 0)
return NULL;
return mypro.at(i);
}
void exam_paper::give_up(){
for(auto it = mypro.begin(); it != mypro.end(); it++)
delete *it;
mypro.erase(mypro.begin(), mypro.end());
}