Advertisement
argentinapb

Untitled

Jul 10th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.72 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. struct data{
  5. int dia, mes, ano;
  6. };
  7.  
  8. struct aluno{
  9. struct data nascimento;
  10. int id;
  11. char nome[256];
  12. double notas[5][2], media[5];
  13. };
  14.  
  15. void inserir(struct aluno c[], int *n);
  16. void remover(struct aluno c[], int *n);
  17. void alterar(struct aluno c[], int *n);
  18. void buscar(struct aluno c[], int *n);
  19. void mostrar_tudo(struct aluno c[], int n);
  20. void mostrar_data(struct aluno c[], int n);
  21. void mostrar_aprovados(struct aluno c[], int n);
  22. void mostrar_reprovados(struct aluno c[], int n);
  23. int main(){
  24. int opc;
  25. struct aluno c[10];
  26. int n = 0;
  27. do{
  28. printf("1. Inserir\n");
  29. printf("2. Remover\n");
  30. printf("3. Buscar\n");
  31. printf("4. Alterar\n");
  32. printf("5. Mostrar tudo\n");
  33. printf("6. Mostar por ano\n");
  34. printf("7. Mostrar alunos aprovados\n");
  35. printf("8. Mostrar alunos reprovados\n");
  36. printf("0. Sair\n");
  37. scanf("%d", &opc);
  38. switch(opc){
  39. case 1:
  40. inserir(c, &n);
  41. break;
  42. case 2:
  43. remover(c, &n);
  44. break;
  45. case 3:
  46. buscar(c, &n);
  47. break;
  48. case 4:
  49. alterar(c, &n);
  50. break;
  51. case 5:
  52. mostrar_tudo(c, n);
  53. break;
  54. case 6:
  55. mostrar_data(c, n);
  56. break;
  57. case 7:
  58. mostrar_aprovados(c, n);
  59. break;
  60. case 8:
  61. mostrar_reprovados(c, n);
  62. case 0:
  63. return 0;
  64. }
  65. }while(opc != 0);
  66. return 0;
  67. }
  68.  
  69. void inserir(struct aluno c[], int *n){
  70. int i, j, id;
  71. printf("Insira os dados do aluno.\n");
  72. printf("Codigo: ");
  73. scanf("%d", &id);
  74. for(i = 0; i < *n; i++){
  75. if(id == c[i].id){
  76. printf("Codigo ja cadastrado.\n");
  77. return;
  78. }
  79. }
  80. c[*n].id = id;
  81. printf("Nome: ");
  82. getchar();
  83. gets(c[*n].nome);
  84. getchar();
  85. printf("Data de nascimento (dd/mm/aaaa): ");
  86. scanf("%d/%d/%d", c[*n].nascimento.dia, c[*n].nascimento.mes, c[*n].nascimento.ano);
  87. for(i = 0; i < 5; i++){
  88. printf("Notas da disciplina %d:\n", i+1);
  89. for(j = 0; j < 2; j++){
  90. printf("Nota %d: ", j+1);
  91. scanf("%lf", c[*n].notas[i][j]);
  92. }
  93. }
  94. *n = *n + 1;
  95.  
  96. for(i = 0; i < 5; i++){
  97. c[*n].media[i] = (c[*n].notas[i][0] + c[*n].notas[i][1])/2;
  98. }
  99. printf("Inserido com sucesso.\n");
  100. return;
  101. }
  102.  
  103. void buscar(struct aluno c[], int *n){
  104. int id, achou = 0, i, j, k;
  105. printf("Insira o codigo para busca: ");
  106. scanf("%d", &id);
  107. for(i = 0; i < *n; i++){
  108. if(id == c[i].id){
  109. achou = 1;
  110. printf("Nome: %s\n", c[i].nome);
  111. printf("Data de nascimento: %d/%d/%d\n", c[i].nascimento.dia, c[i].nascimento.mes, c[i].nascimento.ano);
  112. printf("Notas:\n");
  113. for(j = 0; j < 5; j++){
  114. printf("Notas da disciplina %d:", j+1);
  115. for(k = 0; k < 2; k++){
  116. printf(" %.1lf", c[i].notas[j][k]);
  117. }
  118. printf("\n");
  119. }
  120. }
  121. }
  122. if(achou == 0){
  123. printf("Nao encontrado.\n");
  124. }
  125. return;
  126. }
  127.  
  128. void alterar(struct aluno c[], int *n){
  129. int id, i, j, k, achou = 0,cod;
  130. printf("Insira o codigo do aluno:");
  131. scanf("%d", &cod);
  132. for(i = 0; i < *n; i++){
  133. if(id == c[i].id){
  134. achou = 1;
  135. printf("Insira o novo nome: ");
  136. getchar();
  137. gets(c[i].nome);
  138. getchar();
  139. printf("Insira a nova data de nascimento (dd/mm/aaaa):");
  140. scanf("%d/%d/%d", c[i].nascimento.dia, c[i].nascimento.mes, c[i].nascimento.ano);
  141. printf("Insira as novas notas:");
  142. for(j = 0; j < 5; j++){
  143. printf("Notas da disciplina %d:\n", j+1);
  144. for(k = 0; k < 2; k++){
  145. printf("Nota %d: ", k+1);
  146. scanf("%lf", c[i].notas[i][j]);
  147. }
  148. }
  149. }
  150. }
  151. if(achou == 0){
  152. printf("Nao encontrado.");
  153. }
  154. return;
  155. }
  156.  
  157. void remover(struct aluno c[], int *n){
  158. int id, i, j, achou = 0;
  159. printf("Insira o codigo:");
  160. scanf("%d", &id);
  161. for(int i = 0; i < *n; i++){
  162. if(id == c[i].id){
  163. achou = 1;
  164. for(j = i+1; j < *n; j++){
  165. c[j-1] = c[j];
  166. }
  167. printf("Excluido com sucesso.\n");
  168. *n = *n - 1;
  169. }
  170. }
  171. if(achou == 0){
  172. printf("Nao encontrado.\n");
  173. }
  174. return;
  175. }
  176.  
  177. void mostrar_tudo(struct aluno c[], int n){
  178. int i, j, k;
  179. for(i = 0; i < n; i++){
  180. printf("Codigo: %d\n", c[i].id);
  181. printf("Nome: %s\n", c[i].nome);
  182. printf("Data de nascimento: %d/%d/%d\n", c[i].nascimento.dia, c[i].nascimento.mes, c[i].nascimento.ano);
  183. printf("Notas:");
  184. for(j = 0; j < 5; j++){
  185. printf("Notas da disciplina %d:", j+1);
  186. for(k = 0; k < 2; k++){
  187. printf(" %lf", c[i].notas[j][k]);
  188. }
  189. printf("\n");
  190. printf("Media da disciplina %d: %.1lf",j+1,c[i].media[j]);
  191. printf("\n");
  192. }
  193. }
  194. return;
  195. }
  196. void mostrar_data(struct aluno c[], int n){
  197. int i,j,ano,k;
  198. printf("Ano: %d\n",&ano);
  199. for(i = 0; i < n; i++){
  200. if(ano == c[i].nascimento.ano){
  201. printf("Codigo: %d\n", c[i].id);
  202. printf("Nome: %s\n", c[i].nome);
  203. printf("Data de nascimento: %d/%d/%d\n", c[i].nascimento.dia, c[i].nascimento.mes, c[i].nascimento.ano);
  204. printf("Notas:");
  205. for(j = 0; j < 5; j++){
  206. printf("Notas da disciplina %d:", j+1);
  207. for(k = 0; k < 2; k++){
  208. printf(" %.1lf", c[i].notas[j][k]);
  209. }
  210. printf("\n");
  211. printf("Media da disciplina %d: %.1lf",j+1,c[i].media[j]);
  212. printf("\n");
  213. }
  214. }
  215. }
  216. }
  217. void mostrar_aprovados(struct aluno c[], int n){
  218. int i,j,k,cont = 0;
  219. for(i = 0; i < n; i++){
  220. for(j = 0; j < 5; j++){
  221. if(c[i].media[j] < 6,0){
  222. cont++;
  223. }
  224. }
  225. if(cont == 0){
  226. printf("Codigo: %d\n", c[i].id);
  227. printf("Nome: %s\n", c[i].nome);
  228. printf("Data de nascimento: %d/%d/%d\n", c[i].nascimento.dia, c[i].nascimento.mes, c[i].nascimento.ano);
  229. printf("Notas:");
  230. for(j = 0; j < 5; j++){
  231. printf("Notas da disciplina %d:", j+1);
  232. for(k = 0; k < 2; k++){
  233. printf(" %.1lf", c[i].notas[j][k]);
  234. }
  235. printf("\n");
  236. printf("Media da disciplina %d: %.1lf",j+1,c[i].media[j]);
  237. printf("\n");
  238. }
  239.  
  240. }
  241. }
  242. }
  243. void mostrar_reprovados(struct aluno c[], int n){
  244. int i,j,k,cont = 0;
  245. for(i = 0; i < n; i++){
  246. for(j = 0; j < 5; j++){
  247. if(c[i].media[j] < 6,0){
  248. cont++;
  249. }
  250. }
  251. if(cont > 0){
  252. printf("Codigo: %d\n", c[i].id);
  253. printf("Nome: %s\n", c[i].nome);
  254. printf("Data de nascimento: %d/%d/%d\n", c[i].nascimento.dia, c[i].nascimento.mes, c[i].nascimento.ano);
  255. printf("Notas:");
  256. for(j = 0; j < 5; j++){
  257. printf("Notas da disciplina %d:", j+1);
  258. for(k = 0; k < 2; k++){
  259. printf(" %.1lf", c[i].notas[j][k]);
  260. }
  261. printf("\n");
  262. printf("Media da disciplina %d: %.1lf",j+1,c[i].media[j]);
  263. printf("\n");
  264. }
  265.  
  266. }
  267. }
  268. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement