Advertisement
Caio_25

Exceções

May 17th, 2019
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.96 KB | None | 0 0
  1. #include<iostream>
  2. #include<vector>
  3. #include<string>
  4. #include<iterator>
  5. #include<algorithm>
  6.  
  7. using namespace std;
  8.  
  9. class Aluno{
  10.  
  11.   private:
  12.     string nome;
  13.     int codigo;
  14.  
  15.   public:
  16.     Aluno(string nome, int codigo)
  17.     {
  18.       this->nome = nome;
  19.  
  20.       if(codigo < 0)
  21.       {
  22.         throw "valor invalido";
  23.       }
  24.       this->codigo = codigo;
  25.     }
  26.  
  27.     Aluno()
  28.     {
  29.  
  30.     }
  31.  
  32.     string getNome()
  33.     {
  34.       return(nome);
  35.     }
  36.  
  37.     void setNome(string nome)
  38.     {
  39.       this->nome = nome;
  40.     }
  41.  
  42.     int getCodigo()
  43.     {
  44.       return(codigo);
  45.     }
  46.  
  47.     void setCodigo(int codigo)
  48.     {
  49.       this->codigo = codigo;
  50.     }
  51.  
  52.  
  53. };
  54.  
  55.  
  56.  
  57. int main()
  58. {
  59.   int nota;
  60.   cin >> nota;
  61.   try
  62.   {
  63.       Aluno a("maria", nota);
  64.       cout << a.getCodigo() << endl;
  65.  
  66.       if(nota - nota == 0)
  67.       {
  68.         throw "divisao por zero";
  69.       }
  70.   }
  71.  
  72.   catch(const char* msg)
  73.   {
  74.     cout <<  msg << endl;
  75.   }
  76.  
  77.  
  78.  
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement