Click here to Skip to main content
15,903,856 members
Please Sign up or sign in to vote.
1.00/5 (4 votes)
See more:
Hi guys, could someone help me with this exam?
I really need these 2 parts and i don't know how to do them.
Please, help me, please.
1)In a modularized C project, take from a file done by the student records of medical prescriptions made in this way:
#prescriptioncode#doctorsurname#exemption#issueday#issuehour
(int, char[], char[], int, int)
2)verify that there aren't more than 3 prescriptions with the same surname in the same the day, if there are this prescriptions need to be moved to another day and saved in the file "prescrizioni.txt"
3)sort the prescriptions by the relaction's order <issuedate, issuehour,="" surname="">.
The increasing or decreasing parameter is choosen by from input. Save the sorted prescriptions in the output file "Ordinamento.txt".
I'll send the full project

What I have tried:

C
#include "funzioni.h"

void cleanconsole()
{
    system("pause");
    system("cls");
}

void menu()
{
    printf("Benvenuto nel sistema di gestione prenotazioni\nInserisci 1 per visualizzare\nInserisci 2 per controllare\nInserisci 3 per ordinare\nScelta:  ");
    int scelta = 0;
    controllo_scelta(&scelta);
    while(scelta > 0 && scelta < 4)
    {
        switch(scelta)
        {
        case 1:
            acquisizione()
            cleanconsole();
            break;
        case 2:
            controllare();
            cleanconsole();
            break;
        case 3:
            ordinare()
            cleanconsole();
        }
        printf("Benvenuto nel sistema di gestione prenotazioni\nInserisci 1 per visualizzare\nInserisci 2 per controllare\nInserisci 3 per ordinare\nScelta:  ");
        controllo_scelta(&scelta);
    }
    puts("Arrivederci!");
}

void stampaRecord(int i)
{
    printf("%d#%s#%s#%d#%.2f\n",getCodiceByI(i), getCognomeByI(i), getEsenzioneByI(i), getGiornoByI(i), getOrarioByI(i))
}

void visualizza()
{
    puts("=====PRESCRIZIONI=====");
    for(unsigned int i = 0; i < getNprescrizioni(); i++)
    {
        stampaRecord(i);
        puts("");
    }
}

void controllo_acquisizione()
{
    if(getFlagAcq() == 0)
    {
        puts("Bisogna acquisire i dati da file: ");
        acquisizione();
        printf("%d\n", getFlagAcq());
        cleanconsole();
        return;
    }
}

void inizializza(int i)
{
    setCodiceByI(i, 0);
    setCognomeByI(i, "");
    setEsenzioneByI(i, "");
    setGiornoByI(i, 0);
    setOrarioByI(i, 0);
}

void inizializzaAll()
{
    for(unsigned int i = 0; i < getNprescrizioni(); i++)
    {
        inizializza(i);
    }
}

void acquisisci()
{
    puts("Inserisci il nome del file da acquisire:");
    char nome_file[SIZE];
    scanf("%s", nome_file);
    if(apri_file(nome_file, "r") == 0)
    {
        puts("Impossibile aprire il file\n");
        return;
    }
    else
    {
        puts("Acquisizione in corso...");
        inizializzaAll();
        leggi_file();
        if(getNprescrizioni() != 0)
        {
            visualizza();
            setFlagPos();
        }
        else
        {
            puts("File Vuoto\nAcquisire nuovamente");
            acquisizione();
        }
    }
    chiudi_file();
    puts("Acquisizione terminata");
}

void controlla()
{
    puts("Sto controllando il tuo archivio...");
    if(apri_file("Prescrizioni.txt", "w") == 0)
    {
        puts("Impossibile aprire il file!");
        return;
    }
    else
    {
        unsigned int counter = 1;
        for(unsigned int i = 0; i < getNprescrizioni(); i++)
        {
            for(unsigned int j = i+1; j < getNprescrizioni(); j++)
            {
                if(getGiornoByI(i) == getGiornoByI(j) && strcmp(getCognomeByI(i), getCognomeByI(j)) == 0)
                {
                    counter++;
                }
            }
        }
        if(counter >= 3)
        {

        }
    }
}


C
#include "file.h"

FILE *p;
int apri_file(char* file_name, char* modo)
{
    p = fopen(file_name, modo);
    if(p == NULL)
    {
        perror("Impossibile aprire il file\n");
        return 0;
    }
    else
    {
        return 1;
    }
}

void chiudi_file()
{
    fclose(p);
}

void leggi_file()
{
    char verify[BIG_SIZE];
    unsigned int counter;
    int j = 0;
    if(getNprescrizioni() != 0)
    {
        counter = getNprescrizioni();
    }
    else{counter = 0};
    while(!feof(p))
    {
        if(counter < 0 || counter > SIZE)
        {
            puts("Errore");
            return;
        }
        verify[j] = fgetc(p);
        if((verify[j] == '\n' || verify[j] == EOF) && strlen(verify) > 2)
        {
            verify[j] = '\0';
        if(CancSuRighe(verify))
        {
            tokenator(verify, &counter);
            strcpy(verify, "");
            counter++;
            j = -1;
        }
        else
        {
            j = -1;
        }
    }
    else if(verify[0] == '\n')
    {
        strcpy(verify, "");
        j = -1;
    }
    j++;
}
puts("Caricamento completato...");
}

void tokenator(char *frase, unsigned int *i)
{
    controllo_indice_tok(*i);
    char* token = NULL;
    int controllo = 0;
    int codice;
    char cognome[SIZE];
    char esenzione[SIZE];
    int giorno;
    float orario;
    token = strtok(frase, "#");
    codice = atoi(token);
    if(controllo_vuota(codice, "Codice"))
    {
        puts("Errore");
        --*i;
        system("pause");
        return;
    }
    token = strtok(NULL, "#");
    strcpy(cognome, token);
    if(controllo_vuota(cognome, "Cognome"))
    {
        puts("Errore");
        --*i;
        system("pause");
        return;
    }
    token = strtok(NULL, "#");
    strcpy(esenzione, token);
    if(controllo_vuota(esenzione, "Esenzione"))
    {
        puts("Errore");
        --*i;
        system("pause");
        return;
    }
    token = strtok(NULL, "#");
    giorno = atoi(token);
    if(controllo_vuota(giorno, "Giorno"))
    {
        puts("Errore");
        --*i;
        system("pause");
        return;
    }
    token = strtok(NULL, "#");
    orario = atof(token);
    if(controllo_vuota(orario,"Orario"))
    {
        puts("Errore");
        --*i;
        system("pause");
        return;
    }
    if(!controllo_atoi(codice) || !controllo_cognome(cognome) || !controllo_atoi(giorno) || !controllo_atof(orario))
    {
        controllo = 1;
    }
    if(!controllo)
    {
        setCodiceByI(*i, codice);
        setCognomeByI(*i, cognome);
        setEsenzioneByI(*i, esenzione);
        setGiornoByI(*i, giorno);
        setOrarioByI(*i, orario);
        IncNPrescrizioni();
    }
}

void scrivi_file(unsigned int i)
{
    fprintf(p, "%d%#%s#%s#%d#%.2f\n", getCodiceByI(i), getCognomeByI(i), getEsenzioneByI(i), getGiornoByI(i), getOrarioByI(i));
}


C
#include "dati.h"

typedef struct
{
    int codice;
    char cognome[SIZE];
    char esenzione[SIZE];
    int giorno;
    float orario;
}medici;

medici med[SIZE];
int nPrescrizioni;
int FlagAcq;

void IncNPrescrizioni()
{
    ++nPrescrizioni;
}

void DecNPrescrizioni()
{
    --nPrescrizioni;
}

unsigned int getNprescrizioni()
{
    return nPrescrizioni;
}

void setFlagPos()
{
    FlagAcq = 1;
}

void setFlagNeg()
{
    FlagAcq = 0;
}

int getFlagAcq()
{
    return FlagAcq;
}

int getCodiceByI(int i)
{
    if(i < 0 || i > SIZE)
    {
        puts("Errore");
        i = 0;
    }
    return med[i].codice;
}

char* getCognomeByI(int i)
{
    if(i < 0 || i > SIZE)
    {
        puts("Errore");
        i = 0;
    }
    return med[i].cognome;
}

char* getEsenzioneByI(int i)
{
    if(i < 0 || i > SIZE)
    {
        puts("Errore");
        i = 0;
    }
    if(strcmp(med[i].esenzione, "si") == 0 || strcmp(med[i].esenzione, "no") == 0)
    {
        return med[i].esenzione;
    }
    else
    {
        puts("Errore");
        return;
    }
}

int getGiornoByI(int i)
{
    if(i < 0 || i > SIZE)
    {
        puts("Errore");
        i = 0;
    }
    return med[i].giorno;
}

float getOrarioByI(int i)
{
    if(i < 0 || i > SIZE)
    {
        puts("Errore");
        i = 0;
    }
    return med[i].orario;
}
Posted
Updated 28-Jan-21 4:32am
v2
Comments
Richard MacCutchan 28-Jan-21 6:45am    
What is the problem?
Chris Miccione 28-Jan-21 6:51am    
i don't know how to do the point number 2 and 3
Richard MacCutchan 28-Jan-21 7:34am    
I cannot figure out where in the code tyou are saving all the prescription data after you read it from the input file. The logical thing would be to create a struct to hold the details of each prescription, and build an array of these as you read the input. You can then count the entries that look the same, sort them into different order etc.

We are more than willing to help those that are stuck: but that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for us to do it all for you.

So we need you to do the work, and we will help you when you get stuck. That doesn't mean we will give you a step by step solution you can hand in!
Start by explaining where you are at the moment, and what the next step in the process is. Then tell us what you have tried to get that next step working, and what happened when you did.

If you are having problems getting started at all, then this may help: How to Write Code to Solve a Problem, A Beginner's Guide[^]
 
Share this answer
 
If I take your exam for you do I also get your diploma if/when you graduate?
 
Share this answer
 
The easiest way is to aquire the needed skills, solver the task in excellent quality and impress your teacher and mates with your knowledge. By the way: girls prefer sucessful man. ;-)

So start with learning to use the debugger with some tutorial.

tip: learn to break down issue to small and solvable task which you can implement as functions and classes. Test every pieces of code to be sure it works fine.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900