Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <conio.h>
- #include <time.h>
- struct User {
- long userId;
- char firstName[50];
- char lastName[50];
- short status;
- UserData data;
- };
- struct UserData {
- char sex;
- float weight;
- float height;
- float BMI;
- };
- struct Logger {
- char * time;
- short type;
- char * message;
- };
- User addUser() {
- User u;
- printf("Podaj id uzytkownika:\n");
- scanf("%s", &u.userId);
- fflush(stdin);
- printf("Podaj imie uzytkownika:\n");
- scanf("%s", &u.firstName);
- fflush(stdin);
- printf("Podaj nazwisko uzytkownika:\n");
- scanf("%s", &u.lastName);
- fflush(stdin);
- printf("Podaj status uzytkownika:\n");
- scanf("%d", &u.status);
- fflush(stdin);
- u.data = addUserData();
- return u;
- }
- UserData addUserData() {
- UserData d;
- printf("Podaj plec uzytkownika:\n");
- scanf("%c", &d.sex);
- fflush(stdin);
- printf("Podaj wage uzytkownika:\n");
- scanf("%f", &d.weight);
- fflush(stdin);
- printf("Podaj wysokosc uzytkownika:\n");
- scanf("%f", &d.height);
- fflush(stdin);
- d.BMI = calculateBMI(d.weight, d.height);
- return d;
- }
- float calculateBMI(float weight, float height) {
- return weight / (height*height);
- }
- void archiveUser(User * user, Logger * log,int id) {
- if (user[id].status == 1) {
- user[id].status = 0;
- }
- else {
- Logger l;
- char m[50] = "nie zarchiwizowano";
- l.message = m;
- l.time = (char*)ctime;
- l.type = 1;
- *log = l;
- log++;
- }
- }
- void deleteUser(User * user, Logger * log,int id) {
- if (user[id].status == 0) {
- user[id].status = -1;
- }
- else {
- Logger l;
- char m[50] = "nie usnieto";
- l.message = m;
- l.time = (char*)ctime;
- l.type = 1;
- *log = l;
- log++;
- }
- }
- int main()
- {
- User user[10];
- Logger logger[100];
- Logger * p;
- User * u;
- u = &user[0];
- p = &logger[0];
- int i = 0;
- int j = 0;
- int wybor = 0;
- bool wykonaj = false;
- while(wykonaj) {
- printf("Wybierz operacje\n");
- printf("1. Dodaj użytkownika\n");
- printf("2. Archiwuzuj użytkownika\n");
- printf("3. Usuń użytkownika\n");
- printf("4. Interpretuj wynik BMI\n");
- scanf("%d", &wybor);
- fflush(stdin);
- system("cls");
- int x = 0;
- switch (wybor)
- {
- case 1:
- addUser();
- case 2:
- printf("Podaj id uzytkownika:\n");
- scanf("%d", &wybor);
- fflush(stdin);
- archiveUser(u,p,wybor);
- case 3:
- printf("Podaj id uzytkownika:\n");
- scanf("%d", &wybor);
- fflush(stdin);
- deleteUser(user,p,wybor);
- case 4:
- default:
- break;
- }
- };
- printf("Po while");
- return 0;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement