Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Questão 4) Distancia entre dois pontos
- */
- #include <iostream>
- #include <cmath>
- using namespace std;
- typedef struct
- {
- float x;
- float y;
- }PONTO;
- float distPontos( PONTO a, PONTO b )
- {
- return sqrt( pow( (b.x-a.x), 2) + pow( (b.y-a.y), 2) );
- }
- int main()
- {
- PONTO x1;
- PONTO x2;
- float distancia;
- // ====================== Entrada ==========================
- cout << " ========== Primeiro ponto =========== " << endl;
- cout << "x: ";
- cin >> x1.x;
- cout << "y: ";
- cin >> x1.y;
- cout << endl << " ========== Segundo ponto =========== " << endl;
- cout << "x: ";
- cin >> x2.x;
- cout << "y: ";
- cin >> x2.y;
- // ====================== Calc distancia ========================
- distancia = distPontos( x1, x2 );
- // ======================== Exibe a distancia ========================
- cout << endl;
- cout << "A distancia eh " << distancia << endl;
- system("pause>nul");
- return 0;
- }
- /*
- * Questão 5) Vetor de 4 posições de uma classe com nome e telefone
- */
- #include <iostream>
- #include <string>
- using namespace std;
- class Agenda
- {
- private:
- string nome;
- string telefone;
- public:
- void setNome( string Nome )
- {
- nome = Nome;
- }
- string getNome()
- {
- return nome;
- }
- void setTelefone( string Tel )
- {
- telefone = Tel;
- }
- string getTelefone()
- {
- return telefone;
- }
- };
- int main()
- {
- Agenda contatos[4];
- int atual;
- string nome, telefone;
- // Cadastro
- for( atual=0; atual<4; atual++ )
- {
- cout << "======== Contato " << atual+1 << " ==========" << endl;
- cout << "Nome: ";
- getline( cin, nome );
- cout << "Telefone: ";
- getline( cin, telefone );
- cout << endl;
- contatos[ atual ].setNome( nome );
- contatos[ atual ].setTelefone( telefone );
- }
- // Exibe os dados cadastrados
- for( atual=0; atual<4; atual++ )
- {
- cout << "Nome: " << contatos[atual].getNome() << endl;
- cout << "Telefone: " << contatos[atual].getTelefone() << endl;
- cout << endl;
- }
- system("pause>nul");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement