Advertisement
crobots

Untitled

Jul 13th, 2020
869
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.98 KB | None | 0 0
  1. #include <algorithm>
  2. #include <iostream>
  3.  
  4. //#include "utilities.h"
  5. enum { NO = 0,
  6.        YES = 1,
  7.        RIFIUTATO = 0,
  8.        ACCETTATO = 1 };
  9.  
  10. using namespace std;
  11.  
  12. class Studente {
  13.    private:
  14.     int unsigned matricola;
  15.     string nome;
  16.     string cognome;
  17.     int unsigned eta;
  18.  
  19.    public:
  20.     Studente() {}
  21.     ~Studente() {}
  22.     /////////////////////////////////////
  23.  
  24.     void set_matricola(int matricola);
  25.  
  26.     int get_matricola();
  27.  
  28.     void set_nome(string nome);
  29.  
  30.     string get_nome();
  31.  
  32.     void set_cognome(string cognome);
  33.  
  34.     string get_cognome();
  35.  
  36.     void set_eta(int eta);
  37.  
  38.     int get_eta();
  39. };
  40.  
  41. /////////////////////////////////////////
  42.  
  43. void Studente::set_matricola(int matricola) {
  44.     this->matricola = matricola;
  45. }
  46.  
  47. int Studente::get_matricola() {
  48.     return this->matricola;
  49. }
  50.  
  51. void Studente::set_nome(string nome) {
  52.     this->nome = nome;
  53. }
  54.  
  55. string Studente::get_nome() {
  56.     return this->nome;
  57. }
  58.  
  59. void Studente::set_cognome(string cognome) {
  60.     this->cognome = cognome;
  61. }
  62.  
  63. string Studente::get_cognome() {
  64.     return this->cognome;
  65. }
  66.  
  67. void Studente::set_eta(int eta) {
  68.     this->eta = eta;
  69. }
  70.  
  71. int Studente::get_eta() {
  72.     return this->eta;
  73. }
  74.  
  75. //////////////////////////////
  76.  
  77. bool inserisce_matricola(Studente &s1, int matr) {
  78.     if (matr >= 255312 && matr <= 499999) {
  79.         s1.set_matricola(matr);
  80.         return ACCETTATO;
  81.     } else {
  82.         return RIFIUTATO;
  83.     }
  84. }
  85.  
  86. bool inserisce_nome(Studente &s1, string nom) {
  87.     if (nom.length() <= 30) {
  88.         s1.set_nome(nom);
  89.         return ACCETTATO;
  90.     } else {
  91.         return RIFIUTATO;
  92.     }
  93. }
  94.  
  95. bool inserisce_cognome(Studente &s1, string cogn) {
  96.     if (cogn.length() <= 30) {
  97.         s1.set_cognome(cogn);
  98.         return ACCETTATO;
  99.     } else {
  100.         return RIFIUTATO;
  101.     }
  102. }
  103.  
  104. bool inserisce_eta(Studente &s1, int et) {
  105.     if (et >= 12 && et <= 105) {
  106.         s1.set_matricola(et);
  107.         return ACCETTATO;
  108.     } else {
  109.         return RIFIUTATO;
  110.     }
  111. }
  112.  
  113. void stampa_dati(Studente &s1) {
  114.     cout << "il nome e " << s1.get_nome() << endl;
  115.     cout << "il cognome e " << s1.get_cognome() << endl;
  116.     cout << "la eta e " << s1.get_eta() << endl;
  117.     cout << "la matricola e " << s1.get_matricola() << endl;
  118. }
  119.  
  120. int main() {
  121.     cout << "laboratorio 2" << endl;
  122.     Studente s1;
  123.     int matr, et;
  124.     string nom, cogn;
  125.     do {
  126.         cout << "inserire una matricola valida ";
  127.         cin >> matr;
  128.     } while (inserisce_matricola(s1, matr) != ACCETTATO);
  129.  
  130.     do {
  131.         cout << "inserire un nome di max 30 caratteri ";
  132.         cin >> nom;
  133.     } while (inserisce_nome(s1, nom) != ACCETTATO);
  134.  
  135.     do {
  136.         cout << "inserire un cognome di max 30 caratteri ";
  137.         cin >> nom;
  138.     } while (inserisce_cognome(s1, cogn) != ACCETTATO);
  139.  
  140.     do {
  141.         cout << "inserire una eta tra 12 e 105 ";
  142.         cin >> et;
  143.     } while (inserisce_eta(s1, et) != ACCETTATO);
  144.  
  145.     stampa_dati(s1);
  146.  
  147.     return 0;
  148. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement