Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <ctype.h>
- #include <string.h>
- #include <stdlib.h>
- char name [20]; // onoma
- char lastname [20]; //epwnumo
- int age; //hlikia
- int grade1; //c
- int grade2; // c++
- int grade3; // java
- float average; // mesos oros kai twn 3 mathimatwn
- int regi(void); // sunarthsh gia register
- int login(void); // sunarthsh gia login
- int modify(void); // sunarthsh gia modify
- int view(void); // sunarthsh gia view
- int search(void); // sunarthsh gia search
- int sort (void); // sunarthsh gia to sort
- static char users [100][7][32]; // 100 grammes diaforetikous xrhstes 7 sthles xarakthristika 32 to periexomeno keliou (xarakthres)
- static int count= 0; // metraei posous xrhstes uparxoun sto susthma ekeinh thn stigmh!
- static int id;
- int main (void)
- {
- char user_input[32];
- printf("\t \t \t \t \t WELCOME TO MF Scholarships!\n \n");
- while (1)
- {
- printf ("\t \t * Please insert: \n \t \t - REGISTER \n \t \t - LOG IN \n \n "); // epilogh gia eisodo ki eggrafh
- scanf("\t %s", user_input);
- if (strcmp(user_input,"REGISTER")==0)
- {
- regi();
- }
- else if (strcmp(user_input,"LOGIN")==0)
- {
- id = login();
- if (id == -1)
- {
- break;
- }
- while (1)
- {
- char user_input2[32];
- 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");
- scanf("%s", user_input2);
- if (strcmp(user_input2,"Modify")==0)
- {
- int n = modify();
- }
- if (strcmp(user_input2,"View")==0)
- {
- int p = view();
- }
- if (strcmp(user_input2,"Search")==0)
- {
- int k = search();
- }
- if (strcmp(user_input2,"Sort")==0)
- {
- int l = sort();
- }
- if (strcmp(user_input2, "Exit")==0)
- {
- break;
- }
- }
- }
- }
- return 0;
- }
- int regi(void)
- { int i;
- //metablhtes eggrafhs
- printf("\t \t *Type a user record (name lastname age grade in c grade in java grade in c++)\n");
- scanf("%s %s %d %d %d %d", name, lastname, &age,&grade1, &grade2, &grade3);
- printf("\t -You typed : %s %s %d %d %d %d\n", name, lastname, age, grade1, grade2, grade3);
- average = (grade1 + grade2 + grade3) / 3;
- printf ("\t *Your average is : %1.f\n\n", average);
- for (i=0; i<100; i++)
- {
- if (strcmp(lastname,users[i][1])==0)
- {
- printf("\t The last-name already exists!\n");
- return 1;
- }
- }
- // antigrafei to string pou einai to last name sto users count
- strcpy(users [count] [0],name); // antigrafei to string pou brisketai sto name sto users
- strcpy(users [count] [1],lastname);
- sprintf(users[count] [2], "%d", age); // metatrepei ena int se string
- sprintf(users[count] [3], "%d", grade1);
- sprintf(users[count] [4], "%d", grade2);
- sprintf(users[count] [5], "%d", grade3);
- sprintf(users[count] [6], "%f", average);
- count++;
- return 1;
- }
- int login(void)
- {
- char username[32];
- char password [32];
- char *lastname2; // metablhtes gia log in
- printf("\t \t*Give me you username:\n");
- scanf("%s",username);
- printf("\t \t*Give me your password:\n");
- scanf("%s",password);
- int j;
- int exists = -1;
- for (j=0; j<100; j++)
- {
- if (strcmp(username,users[j][1])==0) // ELEGXOS AN UPARXEI XRHSTHS STO SUSTHMA!
- {
- exists = j;
- }
- }
- int i=0;
- if (exists == -1)
- {
- return -1;
- }
- lastname2 = strdup (username); //strdup mas kanei ena neo antigrafo
- while(lastname2 [i])
- {
- if (i%2 == 0)
- {
- lastname2 [i] = toupper (lastname2 [i]);
- }
- else
- {
- lastname2 [i] = tolower (lastname2 [i]);
- }
- i++;
- }
- if (strcmp(lastname2 , password) == 0)
- {
- printf("\t \t -Success login!\n\n");
- return exists;
- }
- else
- {
- printf("\t \t -Please try again!\n\n");
- return -1;
- }
- }
- int modify (void)
- {
- int change; //allagh stoixeiou
- char last2[32];
- char nam[32];
- int ag;
- int c;
- int java;
- int cpp;
- float av;//metablhtes allaghs
- char input [10];
- 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",
- users[id][1], users[id][0], users[id][2], users[id][3], users[id][4], users[id][5], users[id][6]);
- printf("\t *Do you want to change anything? \n \t Type Yes or NO \n");
- scanf("%s",input);
- if (strcmp(input , "Yes") == 0)
- {
- printf("\t \t *Please insert the number that you want to change:\n");
- scanf("%d",&change);
- if (change == 1)
- {
- printf("\t \t *You want to change your LAST-NAME. Please type:\n\n");
- scanf("%s",last2);
- strcpy(users [id] [1],last2);
- }
- else if(change == 2)
- {
- printf("\t \t *You want to change your NAME. Please type:\n\n");
- scanf("%s",nam);
- strcpy(users [id] [0],nam);
- }
- else if(change == 3)
- {
- printf("\t \t*You want to change your AGE. Please type:\n\n");
- scanf("%d",&ag);
- sprintf(users[id] [2], "%d", ag);
- }
- else if(change == 4)
- {
- printf("\t \t*You want to change your grade in C. Please type:\n\n");
- scanf("%d",&c);
- sprintf(users[id] [3], "%d", c);
- }
- else if(change == 5)
- {
- printf("\t \t*You want to change your grade in JAVA. Please type:\n\n");
- scanf("%d",&java);
- sprintf(users[id] [4], "%d", java);
- }
- else if(change == 6)
- {
- printf("\t \t*You want to change your grade in C++. Please type:\n\n");
- scanf("%d",&cpp);
- sprintf(users[id] [5], "%d", cpp);
- }
- if(change == 4 || change == 5 || change == 6)
- {
- av = (atoi(users[id][3]) + atoi(users[id][4]) + atoi(users[id][5]))/3;
- printf("\t -Your new average is:%1.f\n\n ",av);
- sprintf(users[id] [6], "%f", av);
- }
- 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",
- users[id][1], users[id][0], users[id][2], users[id][3], users[id][4], users[id][5], users[id][6]);
- }
- if (strcmp (input,"No")==0)
- {
- printf("\t -Thank you!\n");
- }
- return 1;
- }
- int view(void)
- {
- int i;
- for (i=0; i<count; i++)
- {
- printf(" -Students are: \n 1.Last-name:%s\n 2.Name: %s \n 3.Age:%s 4. Average: %s\n\n",
- users[i][1], users[i][0], users[i][2],users[i][6]);
- }
- printf(" -Number of students: %d\n\n",count);
- return 1;
- }
- int search(void)
- { int i;
- char search[32];
- int element;
- printf("\t \t*Enter the element to search:\n ");
- scanf("%s", search);
- element = 0;
- for(i=0; i<count; i++)
- {
- if(users[i][1][0] == search[0])
- {
- element = 1;
- printf("\t \t-Students are: \n 1.Last-name:%s\n 2.Name: %s \n 3.Age:%s \n 4. Average: %s\n\n",
- users[id][1], users[id][0], users[id][2],users[id][6]);
- break;
- }
- }
- if(element==0)
- {
- printf("\t -No results.\n");
- }
- }
- int sort(void)
- {
- int i , j ;
- static char temp [7][32];
- int memsize = sizeof(temp); //metraei tn mhnmh pou katanalwnei to temp
- for (i=0; i<count; i++)
- {
- for (j=0; j<count-i; j++)
- {
- if (atof(users[j][6]) < atof(users[j+1][6]))// metatroph string se float
- {
- memcpy(temp,users [j+1], memsize); // memcpy antigrafei oti brisketai stn mhn j+1 sto temp parametro gia na kserw thn mnhmh
- memcpy(users[j+1], users[j], memsize);
- memcpy(users[j],temp, memsize);
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment