Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- class Studente {
- public:
- string nome, cognome;
- float voti[2];
- Studente(string n, string c, float v) {
- nome = n;
- cognome = c;
- voti[2] = v;
- }
- void carica() {
- cout << "Inserisci il nome dell'alunno: ";
- cin >> nome;
- cout << endl;
- for (int i = 0; i < 3; i++) {
- cout << "inserisci il voto " << i << " :";
- cin >> voti[i];
- }
- cout << endl;
- }
- void stampa() {
- cout << "L'alunno " << nome << " ha i seguenti voti" << endl;
- for (int i = 0; i < 3; i++) {
- cout << voti[i] << endl;
- }
- }
- };
- int main() {
- Studente alunno1("", "", 0);
- Studente alunno2("", "", 0);
- int scelta;
- int scelta_alunno;
- do {
- cout << "Che alunno sei?" << endl;
- cout << "(1) Alunno 1" << endl;
- cout << "(2) Alunno 2" << endl;
- cout << "(0) Chiusura programma" << endl;
- cin >> scelta_alunno;
- do {
- cout << "Cosa vuoi fare?" << endl;
- cout << "(1) Carica" << endl;
- cout << "(2) Stampa" << endl;
- cout << "(0) Selezione alunno" << endl;
- cin >> scelta;
- switch (scelta) {
- case 1: {
- if (scelta_alunno == 1) {
- alunno1.carica();
- } else if (scelta_alunno == 2) {
- alunno2.carica();
- } else {
- cout << "**************Errore**************" << endl;
- cout << "Tornare alla selezione dell'alunno" << endl;
- }
- break;
- }
- case 2: {
- if (scelta_alunno == 1) {
- alunno1.stampa();
- } else if (scelta_alunno == 2) {
- alunno2.stampa();
- } else {
- cout << "**************Errore**************" << endl;
- cout << "Tornare alla selezione dell'alunno" << endl;
- }
- break;
- }
- }
- }
- while (scelta != 0);
- }
- while (scelta_alunno != 0);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment