Advertisement
Guest User

Untitled

a guest
Sep 20th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.43 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4. /*
  5. Siamo forniti i nomi e i voti riportati da una serie di studenti in un compito in classe.
  6. Un voto fittizio pari a 0 significa che lo studente era assente. Scrivere un programma che presi in input i nomi e i voti, stampi:
  7. 1) la media dei voti non prendendo in considerazione le assenze
  8. 2) il nome dello studente che ha riportato il voto massimo
  9. 3) l'elenco degli studenti insufficienti  (voto <6)
  10. 4) la percentuale di studenti assenti
  11. */
  12.  
  13. struct Studente {
  14. string nome;
  15. string cognome;
  16. float voto;
  17. };
  18. Studente Classe[40];
  19. void riempimento(int nStud);
  20. float media(int nStud);
  21. string stud_max(int nStud);
  22. void stud_insuff(int nStud);
  23. float stud_ass(int nStud);
  24. int main() {
  25.  
  26. int nStud = 0;
  27. cout << "Inserisci il numero di studenti presenti in classe: ";
  28. cin >> nStud;
  29.  
  30. cout << "\n---------- riempimento ----------\n";
  31. riempimento(nStud);
  32. system("cls");
  33. cout << "\n---------- media ----------\n";
  34. cout << endl << media(nStud);
  35. cout << "\n---------- studente col voto maggiore ----------\n";
  36. cout << endl << stud_max(nStud);
  37. cout << "\n---------- studenti insufficenti ----------\n";
  38. stud_insuff(nStud);
  39. cout << "\n---------- % studenti assenti ----------\n";
  40. cout << stud_ass(nStud) << "%";
  41. }
  42.  
  43. void riempimento(int nStud) {
  44.  
  45. for (int i = 0; i < nStud;i ++)
  46. {
  47. cout << "Inserisci il nome ed il congome dello studente: ";
  48. cin >> Classe[i].nome >> Classe[i].cognome;
  49. cout << "\nInserisci il voto dello studente " << Classe[i].cognome << ": ";
  50. cin >> Classe[i].voto;
  51. }
  52. }
  53.  
  54. float media(int nStud) {
  55. float sum = 0;
  56. int j = 0;
  57. for (int i = 0; i < nStud;i++) {
  58. if(Classe[i].voto != 0)
  59. sum += Classe[i].voto;
  60. else
  61. j++;
  62. }
  63. return (sum / (nStud - j));
  64. }
  65.  
  66. string stud_max(int nStud) {
  67. float max = Classe[0].voto;
  68. int stud = 0;
  69. for (int i = 0; i < nStud; i++) {
  70. if(Classe[i].voto > max) {
  71. max = Classe[i].voto;
  72. stud = i;
  73. }
  74. }
  75. return Classe[stud].cognome;
  76. }
  77.  
  78. void stud_insuff(int nStud) {
  79. string insuff[nStud];
  80. int j = 0;
  81. for(int i = 0; i < nStud; i++) {
  82. if(Classe[i].voto < 6 and Classe[i].voto != 0) {
  83. insuff[j] = Classe[i].cognome;
  84. j++;
  85. }
  86. }
  87. for(int i = 0; i < j;i++)
  88. cout << i + 1 << ") " << insuff[i] << endl;
  89. }
  90.  
  91. float stud_ass(int nStud) {
  92. int ass = 0;
  93. for(int i = 0; i < nStud;i++) {
  94. if (Classe[i].voto == 0)
  95. ass += 1;
  96. }
  97. return ((ass * 100) / nStud);
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement