Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
3.4 kB
7
Indexable
Never
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "linkedlist.h"

int main() {

    int opt = 0, cuantos = 0, i = 0, delete = 0, update = 0;
    char basura;

    LinkedList list = LINKEDLIST_create();
    Element e, dos;

    do {

        printf("\n>> QUIRON HOSPITAL SYSTEM <<\n");
        printf("1. Insert patient | 2. Show list | 3. Delete patient | 4. Update data | 5. Exit\nInput: ");
        scanf("%d", &opt);

        switch (opt) {
            case 1:
                printf("\nHow many patients do you want to add? ");
                scanf("%d", &cuantos);

                for(i = 0; i < cuantos; i++) {
                    printf("\n--- Patient No.%d ---\n", i+1);
                    printf("\tHC numer: ");
                    scanf("%d", &e.HC);
                    scanf("%c", &basura);
                    printf("\tName: ");
                    scanf("%s", e.name);
                    scanf("%c", &basura);
                    printf("\tAge: ");
                    scanf("%d", &e.edad);
                    scanf("%c", &basura);
                    printf("\tGender (m/f): ");
                    scanf("%c", &e.genero);
                    scanf("%c", &basura);

                    LINKEDLIST_add(list, e);
                }

                break;
            case 2:
                printf("\n>> Patients list <<\n");

                LINKEDLIST_goToHead(list);

                for(i = 0; !LINKEDLIST_isAtEnd(list); i++) {

                    e = LINKEDLIST_get(list);

                    printf("\n--- Patient No.%d ---\n", i+1);
                    printf("\tNumber HC: %d\n", e.HC);
                    printf("\tName: %s\n", e.name);
                    printf("\tAge: %d\n", e.edad);
                    printf("\tGenre: %c\n", e.genero);

                    LINKEDLIST_next(list);

                }

                break;
            case 3:

                printf(">>Num HC to delete: ");
                scanf("%d", &delete);

                LINKEDLIST_goToHead(list);

                while(!LINKEDLIST_isAtEnd(list)) {

                    e = LINKEDLIST_get(list);

                    if(e.HC == delete) {

                        LINKEDLIST_remove(list);
                        
                    }

                    LINKEDLIST_next(list);

                }


                break;
            case 4:

                printf(">>Num HC to update: ");
                scanf("%d", &update);

                LINKEDLIST_goToHead(list);

                while(!LINKEDLIST_isAtEnd(list)) {

                    e = LINKEDLIST_get(list);

                    if(e.HC == update) {

                        printf("New name: ");
                        scanf("%s", dos.name);
                        printf("New age: ");
                        scanf("%d", &dos.edad);

                        dos.genero = e.genero;
                        dos.HC = e.HC;

                        LINKEDLIST_remove(list);
                        LINKEDLIST_add(list, dos);

                    }

                    LINKEDLIST_next(list);
                }

                break;
            case 5:
                printf("\nBye bye :)\n");
                LINKEDLIST_destroy(&list);
                break;
            default:
                printf("\nInvalid option :(\n\n");
                break;
        }




    }while(opt != 5);



    return 0;
}