Advertisement
FoxTuGa

School ORG {Linux}

Sep 17th, 2011
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.53 KB | None | 0 0
  1. /*
  2.  * File:   main.c
  3.  * Author: leandro
  4.  *
  5.  * Created on 16 de Setembro de 2011, 20:17
  6.  */
  7.  
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <string.h>
  11.  
  12. #define TRUE 1
  13.  
  14. struct tagNOME {
  15.    char Primeiro[16];
  16.    char Ultimo[16];
  17. };
  18.  
  19. struct tagDATAS {
  20.     int Dia, Mes, Ano;
  21. };
  22.  
  23. struct tagMORADAS {
  24.     char Rua[20];
  25.     int Andar;
  26.     char Lado;
  27. };
  28.  
  29. struct tagAlunos {
  30.     struct tagNOME nome;
  31.     struct tagDATAS Data_nasc;
  32.     int Numero;
  33.     int Num_Tele;
  34.     struct tagMORADAS Morada;
  35. };
  36.  
  37. void Mostrar(struct tagAlunos Alunos);
  38. void MenuP(void);
  39. void OpenMenu(void) { system("clear"); MenuP(); }
  40. void MostrarAluno(int Num_Alunos, struct tagAlunos Alunos[]);
  41. void Procurar(struct tagAlunos Aluno);
  42. void AddAluno(struct tagAlunos Aluno) {
  43.     system("clear");
  44.     printf("\n\t\tAdicionar Aluno\n\n");
  45.     printf("Primeiro Nome: ");
  46.     scanf("%s", Aluno.nome.Primeiro);
  47.     printf("\nSegundo Nome: ");
  48.     scanf("%s", Aluno.nome.Ultimo);
  49.     printf("\nData de Nascimento <dd/mm/aa>: ");
  50.     scanf("%d/%d/%d", &Aluno.Data_nasc.Dia, &Aluno.Data_nasc.Mes, &Aluno.Data_nasc.Ano);
  51.     printf("\nMorada <Rua, Andar-Lado>: ");
  52.     //scanf("%s", Aluno.Morada.Rua);
  53.     scanf("%d-%c", &Aluno.Morada.Andar, &Aluno.Morada.Lado);
  54.     printf("\nTelemovel: ");
  55.     scanf("%d", &Aluno.Num_Tele);
  56.     system("clear");
  57. }
  58.  
  59. int main(int argc, char** argv) {
  60.     int Num_Aluno;
  61.     char Ask;
  62.     struct tagAlunos Alunos[1000];
  63.     Num_Aluno = 0;
  64.     Ask = NULL;
  65.  
  66.     while(TRUE) {
  67.         OpenMenu();
  68.         printf("\nOpcao: ");
  69.         fflush(stdin);
  70.         Ask = getchar();
  71.         OpenMenu();
  72.  
  73.         if( Ask == 'a' || Ask == 'b' || Ask =='c' ) {
  74.             if( Ask == 'a' ) {
  75.                 AddAluno(Alunos[Num_Aluno]);
  76.                 Alunos[Num_Aluno].Numero = Num_Aluno;
  77.                 Num_Aluno++;
  78.             }
  79.             else    if( Ask == 'c' ) {
  80.                 MostrarAluno(Num_Aluno, Alunos);
  81.             }
  82.         }
  83.     }
  84.  
  85.     return (EXIT_SUCCESS);
  86. }
  87.  
  88. void Mostrar(struct tagAlunos Alunos) {
  89.     printf("\nNome\n");
  90.     printf("  primeiro: %s\n", Alunos.nome.Primeiro);
  91.     printf("  segundo: %s\n", Alunos.nome.Ultimo);
  92.     printf("\nData de Nascimento <DD/MM/AA>: ");
  93.     printf("%d/%d/%d \n", Alunos.Data_nasc.Dia, Alunos.Data_nasc.Mes, Alunos.Data_nasc.Ano);
  94.     printf("\nNumero escolar: %d\n", Alunos.Numero);
  95.     printf("Telemovel: %d\n\n", Alunos.Num_Tele);
  96. }
  97.  
  98. void MenuP(void) {
  99.     printf("\n\t\tMenu Principal\n\n");
  100.     printf("\ta - Adicionar Alunos\n");
  101.     printf("\tb - Remover Alunos\n");
  102.     printf("\tc - Ver Alunos\n");
  103. }
  104.  
  105. void MostrarAluno(int Num_Alunos, struct tagAlunos Alunos[]) {
  106.     int aux, find;
  107.     aux = find = 0;
  108.     system("clear");
  109.     printf("\t\tMostrar Alunos\n\n");
  110.     while(Num_Alunos >= 0){
  111.         if(aux % 2 == 0)
  112.             printf("\n");
  113.         printf("\tAluno: %d", Alunos[Num_Alunos].Numero);
  114.         Num_Alunos--;
  115.         aux++;
  116.     }
  117.     printf("\n\nDigite o numero do aluno que quer procurar: ");
  118.     scanf("%d", &find);
  119.     if(find < 0 || find > Num_Alunos)
  120.         printf("\n\nNão encontrado!\n\n");
  121.     else
  122.         Procurar(Alunos[find]);
  123. }
  124.  
  125. void Procurar(struct tagAlunos Aluno) {
  126.     system("clear");
  127.     printf("\tNome\n");
  128.     printf("Primeiro: %s \n", Aluno.nome.Primeiro);
  129.     printf("Ultimo: %s \n", Aluno.nome.Ultimo);
  130.     printf("Data de Nascimento <dd/mm/aa>: %d/%d/%d\n", Aluno.Data_nasc.Dia, Aluno.Data_nasc.Mes, Aluno.Data_nasc.Ano);
  131.     printf("Telemovel: %d\n\n\n", Aluno.Num_Tele);
  132.     system("pause");
  133. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement