Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <time.h>
- #include <math.h>
- // Vector calculator by Puntoinfinito started 16.01.2013
- // v0.1 ADD sumas, restas y multiplicaciónes
- using namespace std;
- int crearvectores();
- int opciones();
- int sumarvectores();
- int restarvectores();
- int multvectores();
- int divivectores();
- int tipo;
- int numescalar = 0;
- struct vector {
- int posicion1;
- int posicion2;
- int total;
- int modulo;
- int direccion;
- int sentido;
- } uno, dos, tres, cuatro, cinco;
- vector uno1, uno2;
- vector dos1, dos2;
- vector tres1, tres2;
- vector cuatro1, cuatro2;
- vector cinco1, cinco2;
- int main() {
- int option = 0;
- cout << "Creacion de vectores... (press 1 and enter) ... ";
- cin >> option;
- switch(option) {
- case 1 : crearvectores();
- }
- return 0;
- }
- int opciones() {
- int option = 0;
- cout << "\n\n1. Sumar\t2. Calcular un vector desde dos puntos \n3. Multiplicar\t4. Dividir por segmentos (proximamente)>>> ";
- cin >> option;
- switch(option) {
- case 1 : sumarvectores();
- case 2 : restarvectores();
- case 3 : multvectores();
- }
- return 0;
- }
- int crearvectores() {
- int maximo;
- cout << "Vectores a crear? (max 5) >> ";
- cin >> maximo;
- /* switch(maximo) {
- case 1 : { vector uno; }
- case 2 : { vector uno; vector dos; }
- case 3 : { vector uno; vector dos; vector tres; }
- case 4 : { vector uno; vector dos; vector tres; vector cuatro; }
- case 5 : { vector uno; vector dos; vector tres; vector cuatro; vector cinco; }
- } ERROR */
- if (maximo >= 1) {
- tipo = 1;
- cout << "X de vector1 >> ";
- cin >> uno.posicion1;
- cout << "Y de vector1 >> ";
- cin >> dos.posicion2;
- }
- if (maximo >= 2 ) {
- tipo = 2;
- cout << "X de vector2 >> ";
- cin >> dos.posicion1;
- cout << "Y de vector2 >> ";
- cin >> dos.posicion2;
- }
- if (maximo >=3 ) {
- tipo = 3;
- cout << "X de vector3 >> ";
- cin >> tres.posicion1;
- cout << "Y de vector3 >> ";
- cin >> tres.posicion2;
- }
- if (maximo >= 4 ) {
- tipo = 4;
- cout << "X de vector4 >> ";
- cin >> cuatro.posicion1;
- cout << "Y de vector4 >> ";
- cin >> cuatro.posicion2;
- }
- if (maximo == 5) {
- tipo = 5;
- cout << "X de vector5 >> ";
- cin >> cinco.posicion1;
- cout << "Y de vector5 >> ";
- cin >> cinco.posicion2;
- }
- return opciones();
- }
- // Funciones de operaciones
- int sumarvectores() {
- switch(tipo) {
- case 1 : {
- uno1.total = uno.posicion1;
- uno2.total = uno.posicion2;
- }
- case 2 : {
- uno1.total = uno.posicion1 + dos.posicion1;
- uno2.total = uno.posicion2 + dos.posicion2;
- }
- case 3 : {
- uno1.total = uno.posicion1 + dos.posicion1 + tres.posicion1;
- uno2.total = uno.posicion2 + dos.posicion2 + tres.posicion2;
- }
- case 4 : {
- uno1.total = uno.posicion1 + dos.posicion1 + tres.posicion1 + cuatro.posicion1;
- uno2.total = uno.posicion2 + dos.posicion2 + tres.posicion2 + cuatro.posicion2;
- }
- case 5 : {
- uno1.total = uno.posicion1 + dos.posicion1 + tres.posicion1 + cuatro.posicion1 + cinco.posicion1;
- uno2.total = uno.posicion2 + dos.posicion2 + tres.posicion2 + cuatro.posicion2 + cinco.posicion2;
- }
- }
- cout << "\n- Vector resultante = primero(" << uno1.total << "," << uno2.total << ")";
- return opciones();
- }
- int restarvectores() {
- int vector1;
- int vector2;
- cout << "Debes seleccionar los dos vectores de la lista que quieres restar :";
- if (tipo >= 1)
- cout << "\n1. Vector1(" << uno.posicion1 << "," << uno.posicion2 << ")";
- if (tipo >= 2)
- cout << "\n2. Vector2(" << dos.posicion1 << "," << dos.posicion2 << ")";
- if (tipo >= 3)
- cout << "\n3. Vector3(" << tres.posicion1 << "," << tres.posicion2 << ")";
- if (tipo >= 4)
- cout << "\n4. Vector4(" << cuatro.posicion1 << "," << cuatro.posicion2 << ")";
- if (tipo >= 5)
- cout << "\n5. Vector5(" << cinco.posicion1 << "," << cinco.posicion2 << ")";
- cout << endl << "Vector primero? >> ";
- cin >> vector1;
- cout << "Vector segundo? >> ";
- cin >> vector2;
- if (vector1 == 1) {
- uno1.total = uno.posicion1;
- uno2.total = uno.posicion2;
- }
- if (vector1 == 2) {
- uno1.total = dos.posicion1;
- uno2.total = dos.posicion2;
- }
- if (vector1 == 3) {
- uno1.total = tres.posicion1;
- uno2.total = tres.posicion2;
- }
- if (vector1 == 4) {
- uno1.total = cuatro.posicion1;
- uno2.total = cuatro.posicion2;
- }
- if (vector1 == 5) {
- uno1.total = cinco.posicion1;
- uno2.total = cinco.posicion2;
- }
- if (vector2 == 1) {
- dos1.total = uno.posicion1;
- dos2.total = uno.posicion2;
- }
- if (vector2 == 2) {
- dos1.total = dos.posicion1;
- dos2.total = dos.posicion2;
- }
- if (vector2 == 3) {
- dos1.total = tres.posicion1;
- dos2.total = tres.posicion2;
- }
- if (vector2 == 4) {
- dos1.total = cuatro.posicion1;
- dos2.total = cuatro.posicion2;
- }
- if (vector2 == 5) {
- dos1.total = cinco.posicion1;
- dos2.total = cinco.posicion2;
- }
- dos1.total = dos1.total * -1;
- dos2.total = dos2.total * -1;
- uno1.total = dos1.total + uno1.total;
- uno2.total = dos2.total + uno2.total;
- cout << "\n- Vector resultante = primero(" << uno1.total << "," << uno2.total << ")";
- return opciones();
- }
- int multvectores() {
- cout << "Numero escalar >> ";
- cin >> numescalar;
- if (tipo >= 1) {
- uno1.total = numescalar * uno.posicion1;
- uno2.total = numescalar * uno.posicion2;
- }
- if (tipo >= 2) {
- dos1.total = numescalar * dos.posicion1;
- dos2.total = numescalar * dos.posicion2;
- }
- if (tipo >= 3) {
- tres1.total = numescalar * tres.posicion1;
- tres2.total = numescalar * tres.posicion2;
- }
- if (tipo >= 4) {
- cuatro1.total = numescalar * cuatro.posicion1;
- cuatro2.total = numescalar * cuatro.posicion2;
- }
- if (tipo == 5) {
- cinco1.total = numescalar * cinco.posicion1;
- cinco2.total = numescalar * cinco.posicion2;
- }
- if (tipo >= 1)
- cout << "\n- Resultado = primero(" << uno1.total << "," << uno2.total << ")";
- if (tipo >= 2)
- cout << "\n- Resultado = segundo(" << dos1.total << "," << dos2.total << ")";
- if (tipo >= 3)
- cout << "\n- Resultado = tercero(" << tres1.total << "," << tres2.total << ")";
- if (tipo >= 4)
- cout << "\n- Resultado = cuarto(" << cuatro1.total << "," << cuatro2.total << ")";
- if (tipo == 5)
- cout << "\n- Resultado = quinto(" << cinco1.total << "," << cinco2.total << ")";
- return opciones();
- }
- int divivectores() {
- //Making... YE
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment