Advertisement
Guest User

Untitled

a guest
Dec 11th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.46 KB | None | 0 0
  1. #include <iostream>
  2. #include <conio.h>
  3. #include <time.h>
  4. struct User {
  5. long userId;
  6. char firstName[50];
  7. char lastName[50];
  8. short status;
  9. UserData data;
  10. };
  11. struct UserData {
  12. char sex;
  13. float weight;
  14. float height;
  15. float BMI;
  16. };
  17. struct Logger {
  18. char * time;
  19. short type;
  20. char * message;
  21. };
  22. User addUser() {
  23. User u;
  24. printf("Podaj id uzytkownika:\n");
  25. scanf("%s", &u.userId);
  26. fflush(stdin);
  27. printf("Podaj imie uzytkownika:\n");
  28. scanf("%s", &u.firstName);
  29. fflush(stdin);
  30. printf("Podaj nazwisko uzytkownika:\n");
  31. scanf("%s", &u.lastName);
  32. fflush(stdin);
  33. printf("Podaj status uzytkownika:\n");
  34. scanf("%d", &u.status);
  35. fflush(stdin);
  36. u.data = addUserData();
  37. return u;
  38. }
  39. UserData addUserData() {
  40. UserData d;
  41. printf("Podaj plec uzytkownika:\n");
  42. scanf("%c", &d.sex);
  43. fflush(stdin);
  44. printf("Podaj wage uzytkownika:\n");
  45. scanf("%f", &d.weight);
  46. fflush(stdin);
  47. printf("Podaj wysokosc uzytkownika:\n");
  48. scanf("%f", &d.height);
  49. fflush(stdin);
  50. d.BMI = calculateBMI(d.weight, d.height);
  51. return d;
  52. }
  53. float calculateBMI(float weight, float height) {
  54. return weight / (height*height);
  55. }
  56. void archiveUser(User * user, Logger * log,int id) {
  57. if (user[id].status == 1) {
  58. user[id].status = 0;
  59. }
  60. else {
  61. Logger l;
  62. char m[50] = "nie zarchiwizowano";
  63. l.message = m;
  64. l.time = (char*)ctime;
  65. l.type = 1;
  66. *log = l;
  67. log++;
  68. }
  69. }
  70. void deleteUser(User * user, Logger * log,int id) {
  71. if (user[id].status == 0) {
  72. user[id].status = -1;
  73. }
  74. else {
  75. Logger l;
  76. char m[50] = "nie usnieto";
  77. l.message = m;
  78. l.time = (char*)ctime;
  79. l.type = 1;
  80. *log = l;
  81. log++;
  82. }
  83. }
  84. int main()
  85. {
  86. User user[10];
  87. Logger logger[100];
  88. Logger * p;
  89. User * u;
  90. u = &user[0];
  91. p = &logger[0];
  92. int i = 0;
  93. int j = 0;
  94. int wybor = 0;
  95. bool wykonaj = false;
  96. while(wykonaj) {
  97. printf("Wybierz operacje\n");
  98. printf("1. Dodaj użytkownika\n");
  99. printf("2. Archiwuzuj użytkownika\n");
  100. printf("3. Usuń użytkownika\n");
  101. printf("4. Interpretuj wynik BMI\n");
  102. scanf("%d", &wybor);
  103. fflush(stdin);
  104. system("cls");
  105. int x = 0;
  106. switch (wybor)
  107. {
  108. case 1:
  109. addUser();
  110. case 2:
  111. printf("Podaj id uzytkownika:\n");
  112. scanf("%d", &wybor);
  113. fflush(stdin);
  114. archiveUser(u,p,wybor);
  115. case 3:
  116. printf("Podaj id uzytkownika:\n");
  117. scanf("%d", &wybor);
  118. fflush(stdin);
  119. deleteUser(user,p,wybor);
  120. case 4:
  121.  
  122. default:
  123. break;
  124. }
  125. };
  126. printf("Po while");
  127. return 0;
  128. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement