Advertisement
F_THIAGO

Itens da Prova

May 27th, 2019
386
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.02 KB | None | 0 0
  1. /*
  2. *   Questão 4) Distancia entre dois pontos
  3. */
  4.  
  5. #include <iostream>
  6. #include <cmath>
  7.  
  8. using namespace std;
  9.  
  10. typedef struct
  11. {
  12.     float x;
  13.     float y;
  14. }PONTO;
  15.  
  16. float distPontos( PONTO a, PONTO b )
  17. {
  18.     return sqrt( pow( (b.x-a.x), 2) + pow( (b.y-a.y), 2) );
  19. }
  20.  
  21. int main()
  22. {
  23.     PONTO x1;
  24.     PONTO x2;
  25.    
  26.     float distancia;
  27.  
  28.     // ====================== Entrada ==========================
  29.     cout << " ========== Primeiro ponto =========== " << endl;
  30.     cout << "x: ";
  31.     cin >> x1.x;
  32.     cout << "y: ";
  33.     cin >> x1.y;
  34.  
  35.     cout << endl << " ========== Segundo ponto =========== " << endl;
  36.     cout << "x: ";
  37.     cin >> x2.x;
  38.     cout << "y: ";
  39.     cin >> x2.y;
  40.  
  41.     // ====================== Calc distancia ========================
  42.     distancia = distPontos( x1, x2 );
  43.  
  44.     // ======================== Exibe a distancia ========================
  45.     cout << endl;
  46.     cout << "A distancia eh " << distancia << endl;
  47.  
  48.     system("pause>nul");
  49.     return 0;
  50. }
  51.  
  52. /*
  53. *   Questão 5) Vetor de 4 posições de uma classe com nome e telefone
  54. */
  55.  
  56. #include <iostream>
  57. #include <string>
  58.  
  59. using namespace std;
  60.  
  61. class Agenda
  62. {
  63.     private:
  64.         string nome;
  65.         string telefone;
  66.  
  67.     public:
  68.         void setNome( string Nome )
  69.         {
  70.             nome = Nome;
  71.         }
  72.  
  73.         string getNome()
  74.         {
  75.             return nome;
  76.         }
  77.  
  78.         void setTelefone( string Tel )
  79.         {
  80.             telefone = Tel;
  81.         }
  82.  
  83.         string getTelefone()
  84.         {
  85.             return telefone;
  86.         }
  87. };
  88.  
  89. int main()
  90. {
  91.     Agenda contatos[4];
  92.     int atual;
  93.  
  94.     string nome, telefone;
  95.  
  96.     // Cadastro
  97.     for( atual=0; atual<4; atual++ )
  98.     {
  99.         cout << "======== Contato " << atual+1 << " ==========" << endl;
  100.         cout << "Nome: ";
  101.         getline( cin, nome );
  102.         cout << "Telefone: ";
  103.         getline( cin, telefone );
  104.         cout << endl;
  105.  
  106.         contatos[ atual ].setNome( nome );
  107.         contatos[ atual ].setTelefone( telefone );
  108.     }
  109.  
  110.     // Exibe os dados cadastrados
  111.     for( atual=0; atual<4; atual++ )
  112.     {
  113.         cout << "Nome: " << contatos[atual].getNome() << endl;
  114.         cout << "Telefone: " << contatos[atual].getTelefone() << endl;
  115.         cout << endl;
  116.     }
  117.  
  118.  
  119.     system("pause>nul");
  120.     return 0;
  121. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement