Advertisement
Guest User

Untitled

a guest
Oct 31st, 2014
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  * Exemplo em C++
  3.  */
  4.  
  5. ...
  6.  
  7. class Aluno {
  8. private: /* os atributos de aluno agora são privativos graças à OO */
  9.     std::string nome;
  10.     float notas[3];
  11.     float media;
  12. public:
  13.     Aluno (std::string nome, float nota1, float nota2, float nota3) { /* construtor da classe aluno */
  14.         this->nome = nome;
  15.         this->notas[0] = nota1;
  16.         this->notas[1] = nota2;
  17.         this->notas[2] = nota3;
  18.         this->media = (this->notas[0] + this->notas[1] + this->notas[2])/3;
  19.     }
  20.    
  21.     /* para acessar os campos do aluno, de uma olhada em como fazer getters para classes de C++ */
  22. };
  23.  
  24. int main (int argc, char **argv) {
  25.     Aluno aluno = Aluno("João Pedro", 9.3, 9.3, 9.3); /* criando um novo objeto de Aluno */
  26.    
  27. ...
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement