-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprogress_app.cpp
194 lines (160 loc) · 4.03 KB
/
progress_app.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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
//paper progress
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <time.h>
//#include <fcntl.h>
#define REQUIRED_PAGES 30
#define DEADLINE 21
//#define PAUSE printf("Press Enter key to continue..."); fgetc(stdin);
using namespace std;
int getpages(){
FILE *readpointer;
int month;
float date;
float progress;
float finish_progress = 0;
readpointer = fopen("progress.txt", "r");
if(readpointer == NULL){
printf("error file\n");
exit(-1);
}
//fscanf(readpointer, "%d%d%d", &read1, &read2, &read3);
while(fscanf(readpointer, "%d%f%f", &month, &date, &progress) != EOF){
finish_progress += progress;
}
fclose(readpointer);
return finish_progress;
}
void today_progress(){
FILE *filepointer;
int month;
int date;
float progress;
printf("Month: ");
scanf("%d", &month);
printf("Date: ");
scanf("%d,", &date);
printf("Progress Today: ");
scanf("%f,", &progress);
filepointer = fopen("progress.txt", "a");
if(filepointer == NULL){
printf("error file\n");
exit(-1);
}
fprintf(filepointer, "%d %d %.1f\n", month, date, progress);
fclose(filepointer);
printf("!!!!!!!!!!!!!!!!\n\n");
printf("%d/%d \n", month, date);
printf("Today's Progress: %.1f\n", progress);
printf("\n!!!!!!!!!!!!!!!!\n\n\n");
}
void progress_calculate(){
float remaining_pages = REQUIRED_PAGES;
float remaining_days;
float avg;
time_t timep;
struct tm *p;
time (&timep);
p = gmtime(&timep);
int date_now = p->tm_mday;
float hour_now = p->tm_hour;
float today = (24-hour_now)/24;
if(getpages() == 0){
printf("!!!!!!!!!!!!!!!!\n\n");
printf("No Record to Calculate\n");
printf("Please Insert Your First Record\n");
printf("\n!!!!!!!!!!!!!!!!\n\n\n");
return;
}
remaining_pages -= getpages();
remaining_days = DEADLINE - date_now + today;
avg = remaining_pages/remaining_days;
printf("!!!!!!!!!!!!!!!!\n\n");
printf("You still have %.1f pages to go within %.1f days. \n"
, remaining_pages, remaining_days);
printf("Write at least %.2f pages tomorrow!\n", avg);
printf("\n!!!!!!!!!!!!!!!!\n\n\n");
}
void history(){
int month;
float date;
float page = -1;
FILE *readpointer;
readpointer = fopen("progress.txt", "r");
if(readpointer == NULL){
printf("error file\n");
exit(-1);
}
printf("\nHistory below: \n");
fscanf(readpointer, "%d%f%f", &month, &date, &page);
if(page == -1){
printf("!!!!!!!!!!!!!!!!\n\n");
printf("No History\n");
printf("Please Insert Your First Record\n");
printf("\n!!!!!!!!!!!!!!!!\n\n\n");
fclose(readpointer);
}else{
printf("!!!!!!!!!!!!!!!!\n\n");
do{
printf("%d/%.1f Progress Today: %.1f\n", month, date, page);
}while(fscanf(readpointer, "%d%f%f", &month, &date, &page) != EOF);
printf("\n!!!!!!!!!!!!!!!!\n\n\n");
fclose(readpointer);
}
}
void refresh(){
FILE *filepointer;
filepointer = fopen("progress.txt", "w");
if(filepointer == NULL){
printf("error file\n");
}
fclose(filepointer);
printf("!!!!!!!!!!!!!!!!\n\n");
printf("Refresh Now\n");
printf("\n!!!!!!!!!!!!!!!!\n\n\n");
}
int main(){
char option;
while(1){
printf("****************\n");
printf("1. Progress\n");
printf("2. Remaining Work\n");
printf("3. History\n");
printf("4. Refresh\n");
printf("5. Quit\n");
printf("****************\n");
printf("Enter your choice: ");
//cin >> option;
scanf("%c", &option);
getchar();
switch(option){
case '1': today_progress();
break;
case '2': progress_calculate();
break;
case '3': history();
break;
case '4': refresh();
break;
case '5':
exit(-1);
default:
printf("error option\n");
printf("try it again\n");
break;
}
printf("* * **** **** **** **** **** * * * ****\n");
printf("* * * * * * * * * * ** * *\n");
printf("** *** *** **** * ** * * * * * * * **\n");
printf("* * * * * * * * * * * ** * *\n");
printf("* * **** **** * **** **** * * * ****\n");
printf("\n");
printf("\n");
printf("Press Enter key to continue...");
while(getchar() != '\n');
//fgetc(stdin);
//system("pause");
}
return 0;
}