Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <algorithm>
- #include <iostream>
- //#include "utilities.h"
- enum { NO = 0,
- YES = 1,
- RIFIUTATO = 0,
- ACCETTATO = 1 };
- using namespace std;
- class Studente {
- private:
- int unsigned matricola;
- string nome;
- string cognome;
- int unsigned eta;
- public:
- Studente() {}
- ~Studente() {}
- /////////////////////////////////////
- void set_matricola(int matricola);
- int get_matricola();
- void set_nome(string nome);
- string get_nome();
- void set_cognome(string cognome);
- string get_cognome();
- void set_eta(int eta);
- int get_eta();
- };
- /////////////////////////////////////////
- void Studente::set_matricola(int matricola) {
- this->matricola = matricola;
- }
- int Studente::get_matricola() {
- return this->matricola;
- }
- void Studente::set_nome(string nome) {
- this->nome = nome;
- }
- string Studente::get_nome() {
- return this->nome;
- }
- void Studente::set_cognome(string cognome) {
- this->cognome = cognome;
- }
- string Studente::get_cognome() {
- return this->cognome;
- }
- void Studente::set_eta(int eta) {
- this->eta = eta;
- }
- int Studente::get_eta() {
- return this->eta;
- }
- //////////////////////////////
- bool inserisce_matricola(Studente &s1, int matr) {
- if (matr >= 255312 && matr <= 499999) {
- s1.set_matricola(matr);
- return ACCETTATO;
- } else {
- return RIFIUTATO;
- }
- }
- bool inserisce_nome(Studente &s1, string nom) {
- if (nom.length() <= 30) {
- s1.set_nome(nom);
- return ACCETTATO;
- } else {
- return RIFIUTATO;
- }
- }
- bool inserisce_cognome(Studente &s1, string cogn) {
- if (cogn.length() <= 30) {
- s1.set_cognome(cogn);
- return ACCETTATO;
- } else {
- return RIFIUTATO;
- }
- }
- bool inserisce_eta(Studente &s1, int et) {
- if (et >= 12 && et <= 105) {
- s1.set_matricola(et);
- return ACCETTATO;
- } else {
- return RIFIUTATO;
- }
- }
- void stampa_dati(Studente &s1) {
- cout << "il nome e " << s1.get_nome() << endl;
- cout << "il cognome e " << s1.get_cognome() << endl;
- cout << "la eta e " << s1.get_eta() << endl;
- cout << "la matricola e " << s1.get_matricola() << endl;
- }
- int main() {
- cout << "laboratorio 2" << endl;
- Studente s1;
- int matr, et;
- string nom, cogn;
- do {
- cout << "inserire una matricola valida ";
- cin >> matr;
- } while (inserisce_matricola(s1, matr) != ACCETTATO);
- do {
- cout << "inserire un nome di max 30 caratteri ";
- cin >> nom;
- } while (inserisce_nome(s1, nom) != ACCETTATO);
- do {
- cout << "inserire un cognome di max 30 caratteri ";
- cin >> nom;
- } while (inserisce_cognome(s1, cogn) != ACCETTATO);
- do {
- cout << "inserire una eta tra 12 e 105 ";
- cin >> et;
- } while (inserisce_eta(s1, et) != ACCETTATO);
- stampa_dati(s1);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement