NoT3yAres

Verifica Recupero

Apr 3rd, 2023
424
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.92 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. class Studente {
  6. public:
  7.   string nome, cognome;
  8.   float voti[2];
  9.  
  10.   Studente(string n, string c, float v) {
  11.     nome = n;
  12.     cognome = c;
  13.     voti[2] = v;
  14.   }
  15.  
  16.   void carica() {
  17.     cout << "Inserisci il nome dell'alunno: ";
  18.     cin >> nome;
  19.     cout << endl;
  20.     for (int i = 0; i < 3; i++) {
  21.       cout << "inserisci il voto " << i << " :";
  22.       cin >> voti[i];
  23.     }
  24.     cout << endl;
  25.   }
  26.  
  27.   void stampa() {
  28.     cout << "L'alunno " << nome << " ha i seguenti voti" << endl;
  29.     for (int i = 0; i < 3; i++) {
  30.       cout << voti[i] << endl;
  31.     }
  32.   }
  33. };
  34.  
  35. int main() {
  36.   Studente alunno1("", "", 0);
  37.   Studente alunno2("", "", 0);
  38.  
  39.   int scelta;
  40.   int scelta_alunno;
  41.  
  42.   do {
  43.     cout << "Che alunno sei?" << endl;
  44.     cout << "(1) Alunno 1" << endl;
  45.     cout << "(2) Alunno 2" << endl;
  46.     cout << "(0) Chiusura programma" << endl;
  47.     cin >> scelta_alunno;
  48.     do {
  49.       cout << "Cosa vuoi fare?" << endl;
  50.       cout << "(1) Carica" << endl;
  51.       cout << "(2) Stampa" << endl;
  52.       cout << "(0) Selezione alunno" << endl;
  53.       cin >> scelta;
  54.       switch (scelta) {
  55.       case 1: {
  56.         if (scelta_alunno == 1) {
  57.           alunno1.carica();
  58.         } else if (scelta_alunno == 2) {
  59.           alunno2.carica();
  60.         } else {
  61.           cout << "**************Errore**************" << endl;
  62.           cout << "Tornare alla selezione dell'alunno" << endl;
  63.         }
  64.         break;
  65.       }
  66.       case 2: {
  67.         if (scelta_alunno == 1) {
  68.           alunno1.stampa();
  69.         } else if (scelta_alunno == 2) {
  70.           alunno2.stampa();
  71.         } else {
  72.           cout << "**************Errore**************" << endl;
  73.           cout << "Tornare alla selezione dell'alunno" << endl;
  74.         }
  75.         break;
  76.       }
  77.       }
  78.       }
  79.       while (scelta != 0);
  80.       }
  81.       while (scelta_alunno != 0);
  82.       return 0;
  83.     }
Advertisement
Add Comment
Please, Sign In to add comment