#include #include #include #include #include #include "utente.h" // ================= SEZIONE ATTRIBUTI E METODI DI CLASSE int utente::ultimaMatricola = 1; int utente::get_ultimaMatricola() { return utente::ultimaMatricola; } // ================= SEZIONE METODI DI OGGETTI // -------- 2 costruttori utente::utente() {nome = ""; cognome = ""; matricola = ultimaMatricola; stipendio = 1000.0; ultimaMatricola++; }; utente::utente(string n, string c, float s) {nome = n; cognome = c; matricola = ultimaMatricola; set_stipendio(s); ultimaMatricola++; }; // -------- 4 funzioni di lettura string utente::get_nome() const { return nome; } string utente::get_cognome() const { return cognome; } int utente::get_matricola() const { return matricola; } float utente::get_stipendio() const { return stipendio; } // -------- 4 funzioni di modifica void utente::set_nome(string n) { nome = n; } void utente::set_cognome(string c) { cognome = c; } void utente::set_stipendio(float s) { stipendio = (s>0) ? s : 1000.0; } // ---------- operatore di lettura da cin void utente::leggi() { string n, c; float s; char buffer[100]; cout << "Inserisci i dati del dipendente" << endl; cout << "Attenzione: al piu' 100 caratteri per campo" << endl << endl; cout << "Nome: "; cin.getline(buffer,100,'\n'); n=buffer; cout << "Cognome: "; cin.getline(buffer,100,'\n'); c=buffer; cout << "Stipendio: "; cin >> s; set_nome(n); set_cognome(c); set_stipendio(s); } // ---------- operatore di stampa su cout void utente::stampa() { cout << "\n-----------------------------------------------------"; cout << "\nDATI UTENTE:"; cout << "\n-----------------------------------------------------\n"; cout << "\t Matricola : " << matricola << endl; cout << "\t Nome : " << nome << endl; cout << "\t Cognome : " << cognome << endl; cout << "\t Stipendio : " << setiosflags( ios::fixed ) << setprecision(2) << stipendio; cout << "\n-----------------------------------------------------\n\n"; }