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:
#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)
{
}
}
}
#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));
}
#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;
}