-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStore.cpp
More file actions
155 lines (122 loc) · 3.34 KB
/
Store.cpp
File metadata and controls
155 lines (122 loc) · 3.34 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
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
#include <simplecpp>
#include <fstream>
#include "Control.h"
#include <string>
#include <cstdlib>
#include <ctime>
void view(string name)
{
/*For refreshment of the window*/
Rectangle RW(500,400,1000,800);
RW.setColor(COLOR(255,255,255));
RW.setFill(True);
Circle L(500,200,400);
L.setColor(COLOR("gold"));
L.setFill(true);
Circle L2(500,200,200);
L2.setColor(COLOR("silver"));
L2.setFill(true);
Text Ach(400,50,"Statistics:"); /*Title*/
Text User(400+textWidth("Statistics")+textWidth(name)/2,50,name);/*Username*/
Rectangle Quit_help(500,700,200,100); /*Quit button*/
Text Quit_h(500,700,"Quit");
Text l[50]; /*Labels*/
Text n[50]; /*Actual data*/
int H=textHeight();
/* Code to read the stored data regarding score,etc */
ifstream fin("records.dat");
if (!fin.is_open()){
exit(EXIT_FAILURE);
}
string word; /*To store the currently read data*/
string day,month,date,timeinst,year; /* To read the date and time */
string timeinfo[10]; /* Array store the currently read date and time */
long int Max=0,Min=pow(2,31)-1,score=0,total=0,freq=0;
/* For extracting total score and highest score of the current user*/
while(!fin.eof())
{
fin>>word>>day>>month>>date>>timeinst>>year>>score;
if(word==name)
{
total+=score;
freq+=1;
if(score>Max)
{
Max=score;
timeinfo[0]=day;
timeinfo[1]=month;
timeinfo[2]=date;
timeinfo[3]=timeinst;
timeinfo[4]=year;
}
if(score<Min)
{
Min=score;
timeinfo[5]=day;
timeinfo[6]=month;
timeinfo[7]=date;
timeinfo[8]=timeinst;
timeinfo[9]=year;
}
}
}
fin.close();
/* Display total score */
l[0].reset(200,100,"Total score: ");
if(freq>1)
{
n[0].reset(350,100,total-score);
}
else
{
n[0].reset(350,100,"NA");
}
/* Display average score */
l[1].reset(200,150,"Average score: ");
if(freq>1)
{
n[1].reset(350,150,float(total-score)/(freq-1));
}
else
{
n[1].reset(350,150,"NA");
}
/* Display maximum score and time of scoring */
l[2].reset(200,200,"Maximum Score: ");
if(freq>1)
{
n[2].reset(350,200+0*H,Max);
}
else
{
n[2].reset(350,200+0*H,"NA");
}
n[3].reset(400,200,"("+timeinfo[0]);
n[4].reset(450,200,timeinfo[1]);
n[5].reset(490,200,timeinfo[2]);
n[6].reset(550,200,timeinfo[4]);
n[7].reset(650,200,timeinfo[3]+")");
/* Display minimum score and time of scoring */
l[3].reset(200,250,"Minimum score: ");
if(freq>1)
{
n[8].reset(350,250,Min);
}
else
{
n[8].reset(350,250,"NA");
}
n[9].reset(400,250,"("+timeinfo[5]);
n[10].reset(450,250,timeinfo[6]);
n[11].reset(490,250,timeinfo[7]);
n[12].reset(550,250,timeinfo[9]);
n[13].reset(650,250,timeinfo[8]+")");
/* To exit the help section */
while (true)
{
int t=getClick();
if (Click(Quit_help,t)){
break;
}
}
}