-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathodev3.cpp
174 lines (124 loc) · 3.19 KB
/
odev3.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
162
163
164
165
166
167
168
169
170
171
172
173
174
/*
2018280056/
Müslüm Berkay Yılmaz
Kullanılan kaynaklar:
https://stackoverflow.com/questions/23726724/reading-string-by-char-till-end-of-line-c-c
http://www.cplusplus.com/doc/tutorial/files/
#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>
*/
using namespace std;
int main () {
string line;
ifstream myfile ("input.txt");
int counter=0, n_questions, notes[100]={0} , student=0;
string answers;
if (myfile.is_open())
{
while ( getline (myfile,line) )
{
cout << line << '\n';
if (counter == 0) {
//n_questions = std::stoi(line);
n_questions = atoi(line.c_str());
}
if (counter == 1) {
answers = line;
}
else {
int question=-1;
int i=9;
while (1) {
if (line[i] == ',' && line[i+1] == ',') {
//If no answer
question += 1;
}
if (line[i] == ',' && line[i+1] != ',' ) {
//If there is an answer
question +=1;
if ( line[i+1] == answers[question*2] ) {
//If the answer is correct
notes[student] += 4;
}
else {
//If the answer is wrong
notes[student] -= 1;
}
}
if(line[i+1] == '\0') {
break;
}
if (question > 10) {
break;
}
i += 1;
}
student += 1;
}
counter += 1;
}
myfile.close();
}
else cout << "-Dosya okunamadi-\n";
//Sorting data and saving students' notes into output file
int notes_sorted[student];
for (int i=0; i<student; i++) {
// Normalizing the data
//(I assume normalizing not meant to be statistically)
if (notes[i] < 0) {
notes[i] = 0;
}
if (notes[i] > 100) {
notes[i] = 100;
}
notes_sorted[i] = notes[i];
}
//Selection-sort used
int mindex, temp;
for (int i=0; i<student; i++) {
mindex = i;
for (int j=i+1; j<student; j++) {
if (notes_sorted[j] < notes_sorted[mindex]) {
mindex = j;
}
temp = notes_sorted[mindex];
notes_sorted[mindex] = notes_sorted[i];
notes_sorted[i] = temp;
}
}
//Saving sorted notes into output file
ofstream output_file ("output.txt");
if (output_file.is_open())
{
cout << "\n\n\n";
for (int i=0; i<student; i++) {
cout << notes_sorted[i] << endl;
output_file << notes_sorted[i] << endl;
}
//Saving the additional info into output file
int min = notes[0];
int max = notes[0], sum=0;
for (int i=0; i< student; i++) {
if (notes[i] < min) {
min = notes[i];
}
if (notes[i] > max) {
max = notes[i];
}
sum += notes[i];
}
int mean = sum / (float) student;
int median = notes_sorted[student / 2];
int range = max - min;
output_file << " En Küçük: " << min;
output_file << " En Büyük: " << max;
output_file << " Ortalama: " << mean;
output_file << " Medyan: " << median;
output_file << " Range: " << range << endl;
output_file.close();
}
else cout << "-Dosya yazilamadi-";
return 0;
}