Advertisement
Voldemord

koko

Dec 20th, 2018
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.11 KB | None | 0 0
  1. #include <stdio.h>
  2. #define Cuser 30
  3. typedef struct UserData{
  4.     char sex;
  5.     float weight;
  6.     float height;
  7.     float BMI;
  8. }UserData;
  9.  
  10. typedef struct User {
  11.     long int userId;
  12.     char firstname[100];
  13.     char lastname[100];
  14.     short int status;
  15.     UserData data;
  16.  
  17. }User;
  18.  
  19. typedef struct Logger {
  20.     char time;
  21.     short int type;
  22.     char message;
  23.     UserData data;
  24.  
  25. }Logger;
  26.  
  27. float checkBMI( float h, float w){
  28.     return w/h*h;
  29. }
  30.  
  31. UserData addUserData(){
  32.     UserData v;
  33.     do{
  34.         printf("Podaj plec: ");
  35.         fflush(stdin);
  36.         scanf("%c",&v.sex);
  37.     }while(!(v.sex == 'M' || v.sex == 'K') );
  38.     printf("Podaj wage: ");
  39.     fflush(stdin);
  40.     scanf("%f",&v.weight);
  41.     printf("Podaj wysokosc: ");
  42.     fflush(stdin);
  43.     scanf("%c",&v.height);
  44.     v.BMI = checkBMI(v.height,v.weight);
  45.     return v;
  46. }
  47.  
  48. User addUser(){
  49.     User v;
  50.     printf("Podaj id: ");
  51.     fflush(stdin);
  52.     scanf("%ld",&v.userId);
  53.     printf("Podaj Imie: ");
  54.     fflush(stdin);
  55.     scanf("%[^\n]s",&v.firstname);
  56.     printf("Podaj Nazwisko: ");
  57.     fflush(stdin);
  58.     scanf("%[^\n]s",&v.lastname);
  59.     v.status = 1;
  60.     v.data = addUserData();
  61.     return v;
  62. }
  63. User archiveUser(User v){
  64.     if(v.status == 1)
  65.     {
  66.         v.status = 0;
  67.         printf("Operacja wykonana pomyslnie\n");
  68.     }
  69.     else
  70.         printf("Uzytkownik nie jest aktywny\n ");
  71.     return v;
  72. }
  73.  
  74. User delUser(User v){
  75.  
  76.     if(v.status == 0)
  77.     {
  78.         v.status = -1;
  79.         printf("Operacja wykonana pomyslnie\n");
  80.     }
  81.     else
  82.         printf("Uzytkownik nie jest archiwalny\n ");
  83.     return v;
  84. }
  85.  
  86. int main(void)
  87. {
  88.     User Users[Cuser];
  89.     User v;
  90.     do{
  91.         int choose = 10;
  92.         long int x;
  93.         int i=0;
  94.         printf("1.Dodaj Uzytkownika\n");
  95.         printf("2.Archiwizuj Uzytkownika\n");
  96.         printf("3.Usun Uzytkownika\n");
  97.         printf("4.Pokaz Wszystkich\n");
  98.         fflush(stdin);
  99.         scanf("%d",&choose);
  100.         switch( choose )
  101.         {
  102.             case 1:
  103.                 v = addUser();
  104.                 Users[v.userId] = v;
  105.                 printf("Stworzono:\n");
  106.                 break;
  107.  
  108.             case 2:
  109.                 printf("Podaj id;");
  110.                 fflush(stdin);
  111.                 scanf("%ld",&x);
  112.                 v = archiveUser(Users[x]);
  113.                 break;
  114.             case 3:
  115.                 printf("Podaj id;");
  116.                 fflush(stdin);
  117.                 scanf("%ld",&x);
  118.                 v = archiveUser(Users[x]);
  119.                 break;
  120.             case 4:
  121.  
  122.                 for(i=0; i < Cuser; i++)
  123.                 {
  124.                     printf("Userid: %ld\n", Users[i].userId);
  125.                     printf("Imie: %s\n", Users[i].firstname);
  126.                     printf("Nazwisko: %s\n", Users[i].lastname);
  127.                     printf("Status: %d\n", Users[i].status);
  128.                     printf("\n");
  129.  
  130.                 }
  131.  
  132.                 break;
  133.  
  134.             default:
  135.                     printf("Wprowadziles nie poprawna opcje\n");
  136.                     break;
  137.  
  138.  
  139.         }
  140.     }while(1);
  141.     return 0;
  142. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement