Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- typedef struct _Vetor {
- float x;
- float y;
- float z;
- } Vetor;
- void soma ( const Vetor *v1, const Vetor *v2, Vetor **res );
- Vetor soma2 ( const Vetor *v1, const Vetor *v2 );
- int main ()
- {
- Vetor v1,v2;
- cout << "Digite os valores para V1:" << endl;
- cout << "X:";
- cin >> v1.x;
- cout << "Y:";
- cin >> v1.y;
- cout << "Z:";
- cin >> v1.z;
- cout << "Digite os valores para V2:" << endl;
- cout << "X:";
- cin >> v2.x;
- cout << "Y:";
- cin >> v2.y;
- cout << "Z:";
- cin >> v2.z;
- Vetor resultado = soma2 (&v1,&v2);
- cout << "\nResultado da soma 2:" << endl;
- cout << "X =" << resultado.x << endl;
- cout << "Y =" << resultado.y<< endl;
- cout << "Z =" << resultado.z<< endl;
- Vetor * resposta = NULL;
- soma(&v1,&v2,&resposta);
- cout << "\nResultado da soma 1:" << endl;
- cout << "X =" << resposta->x << endl;
- cout << "Y =" << resposta->y << endl;
- cout << "Z =" << resposta->z<< endl;
- delete resposta;
- return 0;
- }
- void soma ( const Vetor *v1, const Vetor *v2, Vetor **res )
- {
- Vetor *aux = new Vetor;
- aux->x = (v1 -> x + v2 -> x);
- aux->y = (v1 -> y + v2 -> y);
- aux->z = (v1 -> z + v2 -> z);
- (*res) = aux;
- }
- Vetor soma2 ( const Vetor *v1, const Vetor *v2 )
- {
- Vetor v = {v1 -> x + v2 -> x, v1 -> y + v2 -> y, v1 -> z + v2 -> z};
- cout << "ok\n";
- return v;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement