-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathzod.cpp
318 lines (283 loc) · 6.94 KB
/
zod.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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
#include <ncurses.h>
#include "zodiac.h"
#include "desc.h"
#include <cstring>
// source https://stackoverflow.com/questions/22399406/drawing-boxes-using-ncurses/22399551 FOR THE FRAME
ZODIAC A;
PEOPLE B;
void menu(char* filename);
void currentUser(class ZODIAC& A);
void input(char* filename);
void PrintFile(char* filename) {
string line;
ifstream file(filename);
for(int i=0;getline(file, line);i++) mvprintw(i, 0, "%s", line.c_str());
}
void ShowDescWest(string sign) {
if(sign == "Aries") Aries();
else if(sign == "Taurus") Taurus();
else if(sign == "Gemini") Gemini();
else if(sign == "Cancer") Cancer();
else if(sign == "Leo") Leo();
else if(sign == "Virgo") Virgo();
else if(sign == "Libra") Libra();
else if(sign == "Scorpio") Scorpio();
else if(sign == "Sagittarius") Sagittarius();
else if(sign == "Capricorn") Capricorn();
else if(sign == "Aquarius") Aquarius();
else if(sign == "Pisces") Pisces();
}
void ShowDescChinese(string sign) {
if(sign == "Rat") Rat();
else if(sign == "Ox") Ox();
else if(sign == "Tiger") Tiger();
else if(sign == "Rabbit") Rabbit();
else if(sign == "Dragon") Dragon();
else if(sign == "Snake") Snake();
else if(sign == "Horse") Horse();
else if(sign == "Goat") Goat();
else if(sign == "Monkey") Monkey();
else if(sign == "Rooster") Rooster();
else if(sign == "Dog") Dog();
else if(sign == "Pig") Pig();
}
void ShowDescNum(int num) {
if(num == 1) One();
else if(num == 2) Two();
else if(num == 3) Three();
else if(num == 4) Four();
else if(num == 5) Five();
else if(num == 6) Six();
else if(num == 7) Seven();
else if(num == 8) Eight();
else if(num == 9) Nine();
}
void removeLine(char* filename) {
string target = A.GetCurrent();
string line;
ifstream myfile;
myfile.open(filename);
ofstream temp;
temp.open("temp.txt");
while(getline(myfile,line)) {
if(line == target) continue;
else temp << line << endl;
}
temp.close();
myfile.close();
remove(filename);
rename("temp.txt",filename);
}
void FRAME(int y1, int x1, int y2, int x2)
{
mvhline(y1, x1, 0, x2-x1);
mvhline(y2, x1, 0, x2-x1);
mvvline(y1, x1, 0, y2-y1);
mvvline(y1, x2, 0, y2-y1);
mvaddch(y1, x1, ACS_ULCORNER);
mvaddch(y2, x1, ACS_LLCORNER);
mvaddch(y1, x2, ACS_URCORNER);
mvaddch(y2, x2, ACS_LRCORNER);
}
void skeleton() {
FRAME(5, 20, 30, 120);
FRAME(4, 18, 31, 122);
mvprintw(2, 62, "WELCOME TO ZODIAC!");
}
void choice1(char* filename) {
clear();
skeleton();
currentUser(A);
char sign[15];
strcpy(sign, A.GetSunSign(A.GetBirthdate()).c_str());
mvprintw(8, 22, "You are a %s! :)", sign);
string str(sign);
ShowDescWest(sign);
noecho();
curs_set(0);
mvprintw(21, 22, "Press any key to go back to menu...");
getch();
menu(filename);
}
void choice2(char* filename) {
clear();
skeleton();
currentUser(A);
char sign[15];
strcpy(sign, A.GetChineseSign(A.GetBirthdate()).c_str());
mvprintw(8, 22, "You are a %s! :)", sign);
string str(sign);
ShowDescChinese(sign);
noecho();
curs_set(0);
mvprintw(21, 22, "Press any key to go back to menu...");
getch();
menu(filename);
}
void choice3(char* filename) {
clear();
skeleton();
currentUser(A);
int num;
num = A.GetLifePathNumber(A.GetBirthdate());
mvprintw(8, 22, "Your Life Path Number is %d! :)", num);
ShowDescNum(num);
noecho();
curs_set(0);
mvprintw(25, 22, "Press any key to go back to menu...");
getch();
menu(filename);
}
void choice4(char* filename) {
clear();
noecho();
curs_set(0);
PrintFile(filename);
printw("\n\nPress any key to go to menu...");
getch();
menu(filename);
}
void choice5(char* filename) {
clear();
skeleton();
currentUser(A);
A.BlankFile(filename);
noecho();
curs_set(0);
mvprintw(8, 22, "User Data has been REMOVED");
mvprintw(10, 22, "Press Any Key to go back to menu...");
getch();
input(filename);
}
void choice6(char* filename) {
clear();
skeleton();
currentUser(A);
removeLine(filename);
noecho();
curs_set(0);
mvprintw(8, 22, "User: %s %s %s is REMOVED from database", A.GetName().c_str(), A.GetSurname().c_str(), A.GetBirthdate().c_str());
mvprintw(10, 22, "Press Any Key to go back to menu...");
getch();
input(filename);
}
void choice7(char* filename) {
clear();
skeleton();
currentUser(A);
input(filename);
menu(filename);
}
void choice8() {
delwin(stdscr);
endwin();
refresh();
}
void choice(char* filename) {
echo();
curs_set(1);
move(35, 1);
int ch;
ch = getch();
getch();
switch(ch) {
case '1':
choice1(filename);
break;
case '2':
choice2(filename);
break;
case '3':
choice3(filename);
break;
case '4':
choice4(filename);
break;
case '5':
choice5(filename);
break;
case '6':
choice6(filename);
break;
case '7':
choice7(filename);
break;
case '8':
choice8();
break;
}
}
void menu(char* filename) {
clear();
skeleton();
currentUser(A);
mvprintw(7.5, 22, "Choose and type the corresponding digit :)");
mvprintw(8, 22, "1. Your Sun Sign");
mvprintw(9, 22, "2. Your Chinese Sign");
mvprintw(10, 22, "3. Your Life Path Number");
mvprintw(11, 22, "4. See User Data");
mvprintw(12, 22, "5. Delete User Data");
mvprintw(13, 22, "6. Delete Current Data");
mvprintw(14, 22, "7. Enter New Data");
mvprintw(15, 22, "8. Exit");
choice(filename);
}
void Check(char* filename, char* name, char* surname, char* birthdate) {
bool flag = true;
if(A.CheckNameSurname(name)) A.SetName(name);
else {mvprintw(13, 16, "Invalid Name!"); flag=false;}
if(A.CheckNameSurname(surname)) A.SetSurname(surname);
else {mvprintw(14, 16, "Invalid Surname!"); flag=false;}
if(A.CheckDate(birthdate)) A.SetBirthdate(birthdate);
else {mvprintw(15, 16, "Invalid Birthdate!"); flag=false;}
if(!flag) {mvprintw(20, 55, "Enter any key to input data again..."); getch(); input(filename);}
}
void input(char* filename) {
clear();
skeleton();
char name[20];
char surname[30];
char birthdate[12];
mvprintw(6, 22, "Please, enter your name, surname and a date of birth in order to continue. Your data will be saved");
mvprintw(7,22, "to the file you indicated above.");
echo();
curs_set(1);
mvprintw(13, 55, "NAME: ");
getstr(name);
mvprintw(14, 55, "SURNAME: ");
getstr(surname);
mvprintw(15, 55, "BIRTHDATE (dd/mm/yyyy): ");
mvprintw(16, 60, "(ex: 28/07/2000)");
move(15, 79);
getstr(birthdate);
Check(filename, name, surname, birthdate);
A.PrintToFile(filename);
//sorting starts
B.SetSize(filename);
B.FileToList(filename);
B.Sort();
B.PrintToFile(filename);
//sorting ends
menu(filename);
}
void currentUser(class ZODIAC& A) {
mvprintw(6, 22, "NAME: %s\t\tSURNAME: %s\t\tBIRTHDATE: %s", A.GetName().c_str(), A.GetSurname().c_str(), A.GetBirthdate().c_str());
}
int main()
{
initscr(); /* Start curses mode */
char name[20];
char surname[30];
char birthdate[12];
char filename[50];
skeleton();
mvprintw(6, 22, "Please enter a name for the database file: ");
getstr(filename);
char txt[5] = ".txt";
strcat(filename, txt);
A.BlankFile(filename);
input(filename);
menu(filename);
endwin(); /* End curses mode */
return 0;
}