Guest User

Untitled

a guest
Jan 14th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.14 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <ctype.h>
  3. #include <string.h>
  4. #include <stdlib.h>
  5.  
  6. char name [20]; // onoma
  7. char lastname [20]; //epwnumo
  8. int age; //hlikia
  9. int grade1; //c
  10. int grade2; // c++
  11. int grade3; // java
  12. float average; // mesos oros kai twn 3 mathimatwn
  13.  
  14. int regi(void); // sunarthsh gia register
  15. int login(void); // sunarthsh gia login
  16. int modify(void); // sunarthsh gia modify
  17. int view(void); // sunarthsh gia view
  18. int search(void); // sunarthsh gia search
  19. int sort (void); // sunarthsh gia to sort
  20.  
  21. static char users [100][7][32]; // 100 grammes diaforetikous xrhstes 7 sthles xarakthristika 32 to periexomeno keliou (xarakthres)
  22. static int count= 0; // metraei posous xrhstes uparxoun sto susthma ekeinh thn stigmh!
  23. static int id;
  24.  
  25. int main (void)
  26. {
  27. char user_input[32];
  28. printf("\t \t \t \t \t WELCOME TO MF Scholarships!\n \n");
  29. while (1)
  30. {
  31.  
  32. printf ("\t \t * Please insert: \n \t \t - REGISTER \n \t \t - LOG IN \n \n "); // epilogh gia eisodo ki eggrafh
  33. scanf("\t %s", user_input);
  34.  
  35. if (strcmp(user_input,"REGISTER")==0)
  36. {
  37. regi();
  38.  
  39.  
  40. }
  41. else if (strcmp(user_input,"LOGIN")==0)
  42. {
  43. id = login();
  44.  
  45. if (id == -1)
  46. {
  47. break;
  48. }
  49. while (1)
  50. {
  51. char user_input2[32];
  52. printf("\t \t Please insert: \n \t\t - Modify \n \t \t - View \n \t \t -Search \n \t \t -Sort \n \t \t -Exit\n");
  53. scanf("%s", user_input2);
  54.  
  55.  
  56. if (strcmp(user_input2,"Modify")==0)
  57. {
  58. int n = modify();
  59. }
  60.  
  61. if (strcmp(user_input2,"View")==0)
  62. {
  63. int p = view();
  64. }
  65.  
  66. if (strcmp(user_input2,"Search")==0)
  67. {
  68. int k = search();
  69. }
  70.  
  71. if (strcmp(user_input2,"Sort")==0)
  72. {
  73. int l = sort();
  74. }
  75.  
  76. if (strcmp(user_input2, "Exit")==0)
  77. {
  78. break;
  79. }
  80.  
  81. }
  82.  
  83.  
  84. }
  85.  
  86. }
  87. return 0;
  88.  
  89. }
  90.  
  91. int regi(void)
  92. { int i;
  93.  
  94. //metablhtes eggrafhs
  95.  
  96. printf("\t \t *Type a user record (name lastname age grade in c grade in java grade in c++)\n");
  97. scanf("%s %s %d %d %d %d", name, lastname, &age,&grade1, &grade2, &grade3);
  98. printf("\t -You typed : %s %s %d %d %d %d\n", name, lastname, age, grade1, grade2, grade3);
  99. average = (grade1 + grade2 + grade3) / 3;
  100. printf ("\t *Your average is : %1.f\n\n", average);
  101.  
  102. for (i=0; i<100; i++)
  103. {
  104. if (strcmp(lastname,users[i][1])==0)
  105. {
  106. printf("\t The last-name already exists!\n");
  107. return 1;
  108. }
  109.  
  110.  
  111. }
  112.  
  113. // antigrafei to string pou einai to last name sto users count
  114.  
  115. strcpy(users [count] [0],name); // antigrafei to string pou brisketai sto name sto users
  116. strcpy(users [count] [1],lastname);
  117. sprintf(users[count] [2], "%d", age); // metatrepei ena int se string
  118. sprintf(users[count] [3], "%d", grade1);
  119. sprintf(users[count] [4], "%d", grade2);
  120. sprintf(users[count] [5], "%d", grade3);
  121. sprintf(users[count] [6], "%f", average);
  122.  
  123. count++;
  124.  
  125. return 1;
  126.  
  127.  
  128. }
  129.  
  130. int login(void)
  131. {
  132. char username[32];
  133. char password [32];
  134. char *lastname2; // metablhtes gia log in
  135.  
  136. printf("\t \t*Give me you username:\n");
  137. scanf("%s",username);
  138. printf("\t \t*Give me your password:\n");
  139. scanf("%s",password);
  140. int j;
  141. int exists = -1;
  142.  
  143. for (j=0; j<100; j++)
  144. {
  145. if (strcmp(username,users[j][1])==0) // ELEGXOS AN UPARXEI XRHSTHS STO SUSTHMA!
  146. {
  147.  
  148. exists = j;
  149. }
  150.  
  151.  
  152. }
  153. int i=0;
  154. if (exists == -1)
  155. {
  156. return -1;
  157. }
  158.  
  159.  
  160. lastname2 = strdup (username); //strdup mas kanei ena neo antigrafo
  161.  
  162. while(lastname2 [i])
  163. {
  164. if (i%2 == 0)
  165. {
  166. lastname2 [i] = toupper (lastname2 [i]);
  167. }
  168. else
  169. {
  170.  
  171. lastname2 [i] = tolower (lastname2 [i]);
  172. }
  173. i++;
  174. }
  175.  
  176. if (strcmp(lastname2 , password) == 0)
  177. {
  178. printf("\t \t -Success login!\n\n");
  179. return exists;
  180.  
  181. }
  182. else
  183. {
  184. printf("\t \t -Please try again!\n\n");
  185. return -1;
  186. }
  187.  
  188. }
  189.  
  190. int modify (void)
  191. {
  192. int change; //allagh stoixeiou
  193. char last2[32];
  194. char nam[32];
  195. int ag;
  196. int c;
  197. int java;
  198. int cpp;
  199. float av;//metablhtes allaghs
  200.  
  201. char input [10];
  202. printf ("\t \t*You have entered the following personal data:\n 1.Last-name:%s\n 2.Name: %s \n 3.Age:%s \n 4Grade in C:%s \n 5.Grade in Java: %s \n 6.Grade in C++: %s\n 7. Average: %s\n\n",
  203. users[id][1], users[id][0], users[id][2], users[id][3], users[id][4], users[id][5], users[id][6]);
  204. printf("\t *Do you want to change anything? \n \t Type Yes or NO \n");
  205. scanf("%s",input);
  206.  
  207. if (strcmp(input , "Yes") == 0)
  208. {
  209. printf("\t \t *Please insert the number that you want to change:\n");
  210. scanf("%d",&change);
  211. if (change == 1)
  212. {
  213. printf("\t \t *You want to change your LAST-NAME. Please type:\n\n");
  214. scanf("%s",last2);
  215. strcpy(users [id] [1],last2);
  216. }
  217.  
  218. else if(change == 2)
  219. {
  220. printf("\t \t *You want to change your NAME. Please type:\n\n");
  221. scanf("%s",nam);
  222. strcpy(users [id] [0],nam);
  223. }
  224.  
  225. else if(change == 3)
  226. {
  227. printf("\t \t*You want to change your AGE. Please type:\n\n");
  228. scanf("%d",&ag);
  229. sprintf(users[id] [2], "%d", ag);
  230. }
  231. else if(change == 4)
  232. {
  233. printf("\t \t*You want to change your grade in C. Please type:\n\n");
  234. scanf("%d",&c);
  235. sprintf(users[id] [3], "%d", c);
  236. }
  237. else if(change == 5)
  238. {
  239. printf("\t \t*You want to change your grade in JAVA. Please type:\n\n");
  240. scanf("%d",&java);
  241. sprintf(users[id] [4], "%d", java);
  242. }
  243. else if(change == 6)
  244. {
  245. printf("\t \t*You want to change your grade in C++. Please type:\n\n");
  246. scanf("%d",&cpp);
  247. sprintf(users[id] [5], "%d", cpp);
  248. }
  249.  
  250. if(change == 4 || change == 5 || change == 6)
  251. {
  252. av = (atoi(users[id][3]) + atoi(users[id][4]) + atoi(users[id][5]))/3;
  253. printf("\t -Your new average is:%1.f\n\n ",av);
  254. sprintf(users[id] [6], "%f", av);
  255. }
  256.  
  257. printf ("\t \t*Your new entered the following personal data:\n 1.Last-name:%s\n 2.Name: %s \n 3.Age:%s \n 4Grade in C:%s \n 5.Grade in Java: %s \n 6.Grade in C++: %s\n 7. Average: %s\n\n",
  258. users[id][1], users[id][0], users[id][2], users[id][3], users[id][4], users[id][5], users[id][6]);
  259. }
  260.  
  261. if (strcmp (input,"No")==0)
  262. {
  263. printf("\t -Thank you!\n");
  264. }
  265. return 1;
  266. }
  267.  
  268. int view(void)
  269. {
  270. int i;
  271. for (i=0; i<count; i++)
  272. {
  273. printf(" -Students are: \n 1.Last-name:%s\n 2.Name: %s \n 3.Age:%s 4. Average: %s\n\n",
  274. users[i][1], users[i][0], users[i][2],users[i][6]);
  275. }
  276. printf(" -Number of students: %d\n\n",count);
  277. return 1;
  278. }
  279.  
  280. int search(void)
  281. { int i;
  282. char search[32];
  283. int element;
  284. printf("\t \t*Enter the element to search:\n ");
  285. scanf("%s", search);
  286.  
  287. element = 0;
  288. for(i=0; i<count; i++)
  289. {
  290.  
  291. if(users[i][1][0] == search[0])
  292. {
  293. element = 1;
  294. printf("\t \t-Students are: \n 1.Last-name:%s\n 2.Name: %s \n 3.Age:%s \n 4. Average: %s\n\n",
  295. users[id][1], users[id][0], users[id][2],users[id][6]);
  296. break;
  297. }
  298. }
  299. if(element==0)
  300. {
  301. printf("\t -No results.\n");
  302. }
  303.  
  304. }
  305.  
  306. int sort(void)
  307. {
  308. int i , j ;
  309. static char temp [7][32];
  310. int memsize = sizeof(temp); //metraei tn mhnmh pou katanalwnei to temp
  311. for (i=0; i<count; i++)
  312. {
  313. for (j=0; j<count-i; j++)
  314. {
  315.  
  316. if (atof(users[j][6]) < atof(users[j+1][6]))// metatroph string se float
  317. {
  318.  
  319. memcpy(temp,users [j+1], memsize); // memcpy antigrafei oti brisketai stn mhn j+1 sto temp parametro gia na kserw thn mnhmh
  320. memcpy(users[j+1], users[j], memsize);
  321. memcpy(users[j],temp, memsize);
  322.  
  323. }
  324. }
  325. }
  326. }
Add Comment
Please, Sign In to add comment