xSiRON

Classe Studente

Dec 27th, 2015
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.34 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <ctime>
  4. using namespace std;
  5.  
  6. class Studente{
  7. public:
  8.     Studente();
  9.     ~Studente();
  10.     int getMatricola();
  11.     void getVoti();
  12.     int getMedia();
  13.     void setVoti();
  14.     char* getNome();
  15.  
  16. private:
  17.     int* voti;
  18.     char nome[20];
  19.     int matricola;
  20. };
  21.  
  22. Studente::Studente(){
  23.     int m;
  24.     cout << "Inserisci la tua matricola: ";
  25.     cin >> m;
  26.     matricola = m;
  27.     voti = new int[10];
  28.     for(int i = 0; i < 10; i++){
  29.         voti[i] = rand()%13+18;
  30.     }
  31.     cout << "Inserisci il tuo nome: ";
  32.     cin >> nome;
  33. }
  34.  
  35. int Studente::getMatricola(){
  36.     return matricola;
  37. }
  38.  
  39. void Studente::getVoti(){
  40.     cout << "Voti dell'alunno " << getNome() << ": ";
  41.     for(int i = 0; i < 10; i++)
  42.         cout << voti[i] << " ";
  43. }
  44.  
  45. char* Studente::getNome(){
  46.     return nome;
  47. }
  48.  
  49. void Studente::setVoti(){
  50.     for(int i = 0; i < 10; i++){
  51.         cout << "Imposta voto " << i+1 << ": ";
  52.         cin >> voti[i];
  53.     }
  54. }
  55.  
  56. Studente::~Studente(){
  57.     delete [] voti;
  58.     voti = NULL;
  59. }
  60.  
  61. void truccaVoti(Studente*);
  62.  
  63. int main(){
  64.     srand(time(NULL));
  65.     Studente s;
  66.     Studente* ptr = &s;
  67.  
  68.     ptr->getVoti();
  69.     cout << "\nNome dell'alunno: " << ptr->getNome() << endl;
  70.     cout << "Numero di matricola: " << ptr->getMatricola() << endl;
  71.  
  72.     truccaVoti(ptr);
  73.     ptr->getVoti();
  74.  
  75.     return 0;
  76. }
  77.  
  78. void truccaVoti(Studente* stPtr){
  79.     stPtr->setVoti();
  80. }
Add Comment
Please, Sign In to add comment