Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #define Cuser 30
- typedef struct UserData{
- char sex;
- float weight;
- float height;
- float BMI;
- }UserData;
- typedef struct User {
- long int userId;
- char firstname[100];
- char lastname[100];
- short int status;
- UserData data;
- }User;
- typedef struct Logger {
- char time;
- short int type;
- char message;
- UserData data;
- }Logger;
- float checkBMI( float h, float w){
- return w/h*h;
- }
- UserData addUserData(){
- UserData v;
- do{
- printf("Podaj plec: ");
- fflush(stdin);
- scanf("%c",&v.sex);
- }while(!(v.sex == 'M' || v.sex == 'K') );
- printf("Podaj wage: ");
- fflush(stdin);
- scanf("%f",&v.weight);
- printf("Podaj wysokosc: ");
- fflush(stdin);
- scanf("%c",&v.height);
- v.BMI = checkBMI(v.height,v.weight);
- return v;
- }
- User addUser(){
- User v;
- printf("Podaj id: ");
- fflush(stdin);
- scanf("%ld",&v.userId);
- printf("Podaj Imie: ");
- fflush(stdin);
- scanf("%[^\n]s",&v.firstname);
- printf("Podaj Nazwisko: ");
- fflush(stdin);
- scanf("%[^\n]s",&v.lastname);
- v.status = 1;
- v.data = addUserData();
- return v;
- }
- User archiveUser(User v){
- if(v.status == 1)
- {
- v.status = 0;
- printf("Operacja wykonana pomyslnie\n");
- }
- else
- printf("Uzytkownik nie jest aktywny\n ");
- return v;
- }
- User delUser(User v){
- if(v.status == 0)
- {
- v.status = -1;
- printf("Operacja wykonana pomyslnie\n");
- }
- else
- printf("Uzytkownik nie jest archiwalny\n ");
- return v;
- }
- int main(void)
- {
- User Users[Cuser];
- User v;
- do{
- int choose = 10;
- long int x;
- int i=0;
- printf("1.Dodaj Uzytkownika\n");
- printf("2.Archiwizuj Uzytkownika\n");
- printf("3.Usun Uzytkownika\n");
- printf("4.Pokaz Wszystkich\n");
- fflush(stdin);
- scanf("%d",&choose);
- switch( choose )
- {
- case 1:
- v = addUser();
- Users[v.userId] = v;
- printf("Stworzono:\n");
- break;
- case 2:
- printf("Podaj id;");
- fflush(stdin);
- scanf("%ld",&x);
- v = archiveUser(Users[x]);
- break;
- case 3:
- printf("Podaj id;");
- fflush(stdin);
- scanf("%ld",&x);
- v = archiveUser(Users[x]);
- break;
- case 4:
- for(i=0; i < Cuser; i++)
- {
- printf("Userid: %ld\n", Users[i].userId);
- printf("Imie: %s\n", Users[i].firstname);
- printf("Nazwisko: %s\n", Users[i].lastname);
- printf("Status: %d\n", Users[i].status);
- printf("\n");
- }
- break;
- default:
- printf("Wprowadziles nie poprawna opcje\n");
- break;
- }
- }while(1);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement