nikolas_serafini

Lista 7 - Exercício 11

Aug 10th, 2013
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.19 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #define MAXWORD 50
  4. #define AGENDASIZE 20
  5.  
  6. typedef struct Agenda {
  7.     char AppName[MAXWORD],month[4],DayFlag[3];
  8.     int day,year,hours,minutes;
  9. }Appointment;
  10.  
  11.  
  12. void MenuGen();                 //Gera menu de opções.
  13. void ShowAgenda();              //Imprime em tela todos os compromissos.
  14. void ShowAlteredAgenda();       //Imprime em tela todos os compromissos com horários no formato de 24h.
  15. void ShowAgendaByDate();        //Exibe os compromissos de uma dara inserida pelo usuário.
  16. void ShowAgendaQuant();         //Exige a quantidade de apontamentos de um mês.
  17. int ConvertHour();              //Converte horas AM/PM para formato 24h.
  18. void AgendaInsert();            //Insere novo compromisso.
  19.  
  20. int main() {
  21.  
  22.     int currentSize = 0,option;
  23.     struct Agenda Appointments[AGENDASIZE];
  24.  
  25.     while (1) {
  26.         system("cls");
  27.         MenuGen();
  28.         scanf("%d",&option);
  29.  
  30.         switch (option) {
  31.             case 1:
  32.                 ShowAgenda(Appointments, currentSize); break;
  33.             case 2:
  34.                 ShowAlteredAgenda(Appointments, currentSize); break;
  35.             case 3:
  36.                 ShowAgendaByDate(Appointments, currentSize); break;
  37.             case 4:
  38.                 ShowAgendaQuant(Appointments, currentSize); break;
  39.             case 5:
  40.                 AgendaInsert(Appointments, currentSize); currentSize++; break;
  41.             case 6:
  42.                 return;
  43.             default :
  44.                 printf("Entrada invalida!\n\n");
  45.         }
  46.     }
  47.     return 0;
  48. }
  49.  
  50.  
  51. void MenuGen() {
  52.     printf("1 - Listar todos os compromissos:\n");
  53.     printf("2 - Listar todos os compromissos em formato de hora 24h:\n");
  54.     printf("3 - Exibir os compromissos de uma determinada data:\n");
  55.     printf("4 - Exibir a quantidade de compromissos de um determinado mes:\n");
  56.     printf("5 - Inserir novo compromisso :\n");
  57.     printf("6 - Sair :\n");
  58.     return;
  59. }
  60.  
  61. void ShowAgenda (Appointment Appointments[], int currentSize) {
  62.     int i;
  63.  
  64.     system("cls");
  65.     for (i = 0; i < currentSize; i++)
  66.     {
  67.         printf("Descricao : %s\n",Appointments[i].AppName);
  68.         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);
  69.     }
  70.     getch();
  71.     return;
  72. }
  73.  
  74. void ShowAlteredAgenda (Appointment Appointments[], int currentSize) {
  75.     int i,token;
  76.  
  77.     system("cls");
  78.     for (i = 0; i < currentSize; i++)
  79.     {
  80.         printf("Descricao : %s\n",Appointments[i].AppName);
  81.         token = ConvertHour(Appointments[i].hours, Appointments[i].DayFlag);
  82.         printf("Data : %d-%s-%d, %d:%d\n\n",Appointments[i].day,Appointments[i].month,Appointments[i].year,token,Appointments[i].minutes);
  83.     }
  84.     getch();
  85.     return;
  86. }
  87.  
  88. int ConvertHour (int hour, char flag[3]) {
  89.     if (strcmp(flag,"AM") == 0)
  90.         return hour;
  91.     else if (hour < 12)
  92.         return hour+12;
  93.     else
  94.         return 0;
  95. }
  96.  
  97. void ShowAgendaByDate (Appointment Appointments[], int currentSize) {
  98.  
  99.     int i,flag = 0,day,year;
  100.     char month[4];
  101.  
  102.     system("cls");
  103.     printf("Entre com a data do compromisso : (Formato : dd/mmm/aaaa)\n");
  104.     scanf("%d %s %d",&day,&month,&year);
  105.  
  106.     for (i = 0; i < currentSize; i++) {
  107.         if (Appointments[i].day == day && Appointments[i].year == year && strcmp(month,Appointments[i].month) == 0) {
  108.             printf("Apontamento : %s\n",Appointments[i].AppName);
  109.             flag = 1;
  110.         }
  111.     }
  112.  
  113.     if (flag == 0)
  114.         printf("Sem apontamentos para a data!\n");
  115.  
  116.     getch();
  117.     return;
  118. }
  119.  
  120. void ShowAgendaQuant (Appointment Appointments[], int currentSize) {
  121.  
  122.     int i, counter = 0;
  123.     char month[4];
  124.  
  125.     system("cls");
  126.     printf("Entre com a sigla do mes desejado :\n");
  127.     fflush(stdin);
  128.     gets(month);
  129.  
  130.     for (i = 0; i < currentSize; i++)
  131.         if (strcmp(month,Appointments[i].month) == 0)
  132.             counter++;
  133.  
  134.     printf("Existem %d compromissos para o mes inserido.\n",counter);
  135.     getch();
  136.     return;
  137. }
  138.  
  139. void AgendaInsert (Appointment Appointments[], int currentSize) {
  140.  
  141.     system("cls");
  142.     printf("Entre com o nome do apontamento :\n");
  143.     fflush(stdin);
  144.     gets(Appointments[currentSize].AppName);
  145.     printf("Entre com o dia, mes (sigla de tres letras) e ano :\n");
  146.     scanf("%d %s %d",&Appointments[currentSize].day,&Appointments[currentSize].month,&Appointments[currentSize].year);
  147.     printf("Entre com a hora (formato 12 horas), minutos e o indicativo de horario (AM/PM)\n");
  148.     scanf("%d %d %s",&Appointments[currentSize].hours,&Appointments[currentSize].minutes,&Appointments[currentSize].DayFlag);
  149.     return;
  150.  
  151. }
Advertisement
Add Comment
Please, Sign In to add comment