T.T


SUBMITTED BY: Guest

DATE: Nov. 23, 2013, 4:56 p.m.

FORMAT: Text only

SIZE: 2.4 kB

HITS: 808

  1. http://cur.lv/4x9e0 (Earn Bitcoins)
  2. // HEADER
  3. #ifndef studentimatricolaesame_studente_h
  4. #define studentimatricolaesame_studente_h
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <string.h>
  8. typedef struct elem{
  9. int voto;
  10. struct elem* next;
  11. } esame;
  12. typedef char string[5];
  13. typedef struct elems{
  14. string matricola;
  15. esame* info;
  16. struct elems* next;
  17. } studente;
  18. typedef studente* studenti;
  19. studenti inseriscistudente(studenti);
  20. void aggiungivoto(esame*);
  21. void stampa(studenti);
  22. #endif
  23. // COMPILATO
  24. #include "studente.h"
  25. studenti inseriscistudente(studenti l){
  26. studente* nuovo = malloc(sizeof(studente));
  27. nuovo->next = NULL;
  28. printf("Inserire matricola: ");
  29. string m;
  30. scanf("%s", m);
  31. strcpy(nuovo->matricola, m);
  32. esame* p = malloc(sizeof(esame));
  33. p->next = NULL;
  34. printf("Inserire voto: ");
  35. scanf("%d",&p->voto);
  36. nuovo->info=p;
  37. printf("Continuare? y/n\n");
  38. char risposta='y';
  39. scanf(" %c", &risposta);
  40. while (risposta=='y' || risposta=='Y'){
  41. aggiungivoto(nuovo->info);
  42. printf("Continuare? y/n\n");
  43. scanf(" %c", &risposta);
  44. }
  45. return l;
  46. }
  47. void aggiungivoto(esame* l){
  48. esame* v = malloc(sizeof(esame));
  49. v->next = NULL;
  50. printf("Inserire voto: ");
  51. scanf("%d",&v->voto);
  52. while (l->next!=NULL)
  53. l=l->next;
  54. l->next=v;
  55. }
  56. void stampaesami(esame* l){
  57. while (l!=NULL){
  58. printf("%d ", l->voto);
  59. l=l->next;
  60. }
  61. }
  62. void stampa(studenti l){
  63. while (l!=NULL){
  64. printf("Matricola: %s\n", l->matricola);
  65. printf("Voti dello studente: ");
  66. stampaesami(l->info);
  67. printf("\n");
  68. l=l->next;
  69. }
  70. }
  71. // MAIN
  72. int main(int argc, const char * argv[])
  73. {
  74. studenti scemi = malloc(sizeof(studente));
  75. strcpy(scemi->matricola,"AB123");
  76. esame* esami = malloc(sizeof(esame));
  77. esami->voto = 3;
  78. scemi->info = esami;
  79. stampa(scemi);
  80. printf("\n");
  81. inseriscistudente(scemi);
  82. printf("\n");
  83. stampa(scemi);
  84. return 0;
  85. }

comments powered by Disqus