Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #define MAXWORD 50
- #define AGENDASIZE 20
- typedef struct Agenda {
- char AppName[MAXWORD],month[4],DayFlag[3];
- int day,year,hours,minutes;
- }Appointment;
- void MenuGen(); //Gera menu de opções.
- void ShowAgenda(); //Imprime em tela todos os compromissos.
- void ShowAlteredAgenda(); //Imprime em tela todos os compromissos com horários no formato de 24h.
- void ShowAgendaByDate(); //Exibe os compromissos de uma dara inserida pelo usuário.
- void ShowAgendaQuant(); //Exige a quantidade de apontamentos de um mês.
- int ConvertHour(); //Converte horas AM/PM para formato 24h.
- void AgendaInsert(); //Insere novo compromisso.
- int main() {
- int currentSize = 0,option;
- struct Agenda Appointments[AGENDASIZE];
- while (1) {
- system("cls");
- MenuGen();
- scanf("%d",&option);
- switch (option) {
- case 1:
- ShowAgenda(Appointments, currentSize); break;
- case 2:
- ShowAlteredAgenda(Appointments, currentSize); break;
- case 3:
- ShowAgendaByDate(Appointments, currentSize); break;
- case 4:
- ShowAgendaQuant(Appointments, currentSize); break;
- case 5:
- AgendaInsert(Appointments, currentSize); currentSize++; break;
- case 6:
- return;
- default :
- printf("Entrada invalida!\n\n");
- }
- }
- return 0;
- }
- void MenuGen() {
- printf("1 - Listar todos os compromissos:\n");
- printf("2 - Listar todos os compromissos em formato de hora 24h:\n");
- printf("3 - Exibir os compromissos de uma determinada data:\n");
- printf("4 - Exibir a quantidade de compromissos de um determinado mes:\n");
- printf("5 - Inserir novo compromisso :\n");
- printf("6 - Sair :\n");
- return;
- }
- void ShowAgenda (Appointment Appointments[], int currentSize) {
- int i;
- system("cls");
- for (i = 0; i < currentSize; i++)
- {
- printf("Descricao : %s\n",Appointments[i].AppName);
- printf("Data : %d-%s-%d, %d:%d %s\n\n",Appointments[i].day,Appointments[i].month,Appointments[i].year,Appointments[i].hours,Appointments[i].minutes,Appointments[i].DayFlag);
- }
- getch();
- return;
- }
- void ShowAlteredAgenda (Appointment Appointments[], int currentSize) {
- int i,token;
- system("cls");
- for (i = 0; i < currentSize; i++)
- {
- printf("Descricao : %s\n",Appointments[i].AppName);
- token = ConvertHour(Appointments[i].hours, Appointments[i].DayFlag);
- printf("Data : %d-%s-%d, %d:%d\n\n",Appointments[i].day,Appointments[i].month,Appointments[i].year,token,Appointments[i].minutes);
- }
- getch();
- return;
- }
- int ConvertHour (int hour, char flag[3]) {
- if (strcmp(flag,"AM") == 0)
- return hour;
- else if (hour < 12)
- return hour+12;
- else
- return 0;
- }
- void ShowAgendaByDate (Appointment Appointments[], int currentSize) {
- int i,flag = 0,day,year;
- char month[4];
- system("cls");
- printf("Entre com a data do compromisso : (Formato : dd/mmm/aaaa)\n");
- scanf("%d %s %d",&day,&month,&year);
- for (i = 0; i < currentSize; i++) {
- if (Appointments[i].day == day && Appointments[i].year == year && strcmp(month,Appointments[i].month) == 0) {
- printf("Apontamento : %s\n",Appointments[i].AppName);
- flag = 1;
- }
- }
- if (flag == 0)
- printf("Sem apontamentos para a data!\n");
- getch();
- return;
- }
- void ShowAgendaQuant (Appointment Appointments[], int currentSize) {
- int i, counter = 0;
- char month[4];
- system("cls");
- printf("Entre com a sigla do mes desejado :\n");
- fflush(stdin);
- gets(month);
- for (i = 0; i < currentSize; i++)
- if (strcmp(month,Appointments[i].month) == 0)
- counter++;
- printf("Existem %d compromissos para o mes inserido.\n",counter);
- getch();
- return;
- }
- void AgendaInsert (Appointment Appointments[], int currentSize) {
- system("cls");
- printf("Entre com o nome do apontamento :\n");
- fflush(stdin);
- gets(Appointments[currentSize].AppName);
- printf("Entre com o dia, mes (sigla de tres letras) e ano :\n");
- scanf("%d %s %d",&Appointments[currentSize].day,&Appointments[currentSize].month,&Appointments[currentSize].year);
- printf("Entre com a hora (formato 12 horas), minutos e o indicativo de horario (AM/PM)\n");
- scanf("%d %d %s",&Appointments[currentSize].hours,&Appointments[currentSize].minutes,&Appointments[currentSize].DayFlag);
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment