Puntoinfinito

Vector Calculator v0.1

Jan 17th, 2013
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 6.29 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4. #include <time.h>
  5. #include <math.h>
  6.  
  7. // Vector calculator by Puntoinfinito started 16.01.2013
  8. // v0.1 ADD sumas, restas y multiplicaciónes
  9.  
  10. using namespace std;
  11.  
  12. int crearvectores();
  13. int opciones();
  14. int sumarvectores();
  15. int restarvectores();
  16. int multvectores();
  17. int divivectores();
  18.  
  19. int tipo;
  20. int numescalar = 0;
  21.  
  22. struct vector {
  23.    
  24.     int posicion1;
  25.     int posicion2;
  26.     int total;
  27.    
  28.     int modulo;
  29.     int direccion;
  30.     int sentido;
  31. } uno, dos, tres, cuatro, cinco;
  32.  
  33. vector uno1, uno2;
  34. vector dos1, dos2;
  35. vector tres1, tres2;
  36. vector cuatro1, cuatro2;
  37. vector cinco1, cinco2;
  38.  
  39. int main() {
  40.     int option = 0;
  41.     cout << "Creacion de vectores... (press 1 and enter) ... ";
  42.     cin >> option;
  43.     switch(option) {
  44.         case 1 : crearvectores();
  45.     }
  46.     return 0;
  47. }
  48.    
  49. int opciones() {
  50.     int option = 0;
  51.     cout << "\n\n1. Sumar\t2. Calcular un vector desde dos puntos \n3. Multiplicar\t4. Dividir por segmentos (proximamente)>>> ";
  52.     cin >> option;
  53.     switch(option) {
  54.         case 1 : sumarvectores();
  55.         case 2 : restarvectores();
  56.         case 3 : multvectores();
  57.     }
  58.     return 0;
  59. }
  60.  
  61. int crearvectores() {
  62.     int maximo;
  63.     cout << "Vectores a crear? (max 5) >> ";
  64.     cin >> maximo;
  65.    
  66.     /* switch(maximo) {
  67.         case 1 : { vector uno; }
  68.         case 2 : { vector uno; vector dos; }
  69.         case 3 : { vector uno; vector dos; vector tres; }
  70.         case 4 : { vector uno; vector dos; vector tres; vector cuatro; }
  71.         case 5 : { vector uno; vector dos; vector tres; vector cuatro; vector cinco; }
  72.     } ERROR */
  73.    
  74.     if (maximo >= 1) {
  75.         tipo = 1;
  76.         cout << "X de vector1 >> ";
  77.         cin >> uno.posicion1;
  78.         cout << "Y de vector1 >> ";
  79.         cin >> dos.posicion2;
  80.         }
  81.     if (maximo >= 2 ) {
  82.         tipo = 2;
  83.         cout << "X de vector2 >> ";
  84.         cin >> dos.posicion1;
  85.         cout << "Y de vector2 >> ";
  86.         cin >> dos.posicion2;
  87.         }
  88.     if (maximo >=3 )  {
  89.         tipo = 3;
  90.         cout << "X de vector3 >> ";
  91.         cin >> tres.posicion1;
  92.         cout << "Y de vector3 >> ";
  93.         cin >> tres.posicion2;
  94.     }
  95.     if (maximo >= 4 ) {
  96.         tipo = 4;
  97.         cout << "X de vector4 >> ";
  98.         cin >> cuatro.posicion1;
  99.         cout << "Y de vector4 >> ";
  100.         cin >> cuatro.posicion2;
  101.     }
  102.    
  103.     if (maximo == 5) {
  104.         tipo = 5;
  105.         cout << "X de vector5 >> ";
  106.         cin >> cinco.posicion1;
  107.         cout << "Y de vector5 >> ";
  108.         cin >> cinco.posicion2;
  109.     }
  110.     return opciones();
  111. }
  112.  
  113. // Funciones de operaciones
  114.  
  115. int sumarvectores() {
  116.    
  117.     switch(tipo) {
  118.         case 1 : {
  119.             uno1.total = uno.posicion1;
  120.             uno2.total = uno.posicion2;
  121.         }
  122.         case 2 : {
  123.             uno1.total = uno.posicion1 + dos.posicion1;
  124.             uno2.total = uno.posicion2 + dos.posicion2;
  125.         }
  126.         case 3 : {
  127.             uno1.total = uno.posicion1 + dos.posicion1 + tres.posicion1;
  128.             uno2.total = uno.posicion2 + dos.posicion2 + tres.posicion2;
  129.         }
  130.         case 4 : {
  131.             uno1.total = uno.posicion1 + dos.posicion1 + tres.posicion1 + cuatro.posicion1;
  132.             uno2.total = uno.posicion2 + dos.posicion2 + tres.posicion2 + cuatro.posicion2;
  133.         }
  134.         case 5 : {
  135.             uno1.total = uno.posicion1 + dos.posicion1 + tres.posicion1 + cuatro.posicion1 + cinco.posicion1;
  136.             uno2.total = uno.posicion2 + dos.posicion2 + tres.posicion2 + cuatro.posicion2 + cinco.posicion2;
  137.         }
  138.     }
  139.     cout << "\n- Vector resultante = primero(" << uno1.total << "," << uno2.total << ")";
  140.     return opciones();
  141. }
  142.  
  143. int restarvectores() {
  144.     int vector1;
  145.     int vector2;
  146.    
  147.     cout << "Debes seleccionar los dos vectores de la lista que quieres restar :";
  148.    
  149.     if (tipo >= 1)
  150.     cout << "\n1. Vector1(" << uno.posicion1 << "," << uno.posicion2 << ")";
  151.     if (tipo >= 2)
  152.     cout << "\n2. Vector2(" << dos.posicion1 << "," << dos.posicion2 << ")";
  153.     if (tipo >= 3)
  154.     cout << "\n3. Vector3(" << tres.posicion1 << "," << tres.posicion2 << ")";
  155.     if (tipo >= 4)
  156.     cout << "\n4. Vector4(" << cuatro.posicion1 << "," << cuatro.posicion2 << ")";
  157.     if (tipo >= 5)
  158.     cout << "\n5. Vector5(" << cinco.posicion1 << "," << cinco.posicion2 << ")";
  159.    
  160.     cout << endl << "Vector primero? >> ";
  161.     cin >> vector1;
  162.     cout << "Vector segundo? >> ";
  163.     cin >> vector2;
  164.    
  165.     if (vector1 == 1) {
  166.         uno1.total = uno.posicion1;
  167.         uno2.total = uno.posicion2;
  168.     }
  169.     if (vector1 == 2) {
  170.         uno1.total = dos.posicion1;
  171.         uno2.total = dos.posicion2;
  172.     }
  173.     if (vector1 == 3) {
  174.         uno1.total = tres.posicion1;
  175.         uno2.total = tres.posicion2;
  176.     }
  177.     if (vector1 == 4) {
  178.         uno1.total = cuatro.posicion1;
  179.         uno2.total = cuatro.posicion2;
  180.     }
  181.     if (vector1 == 5) {
  182.         uno1.total = cinco.posicion1;
  183.         uno2.total = cinco.posicion2;
  184.     }
  185.    
  186.     if (vector2 == 1) {
  187.         dos1.total = uno.posicion1;
  188.         dos2.total = uno.posicion2;
  189.     }
  190.     if (vector2 == 2) {
  191.         dos1.total = dos.posicion1;
  192.         dos2.total = dos.posicion2;
  193.     }
  194.     if (vector2 == 3) {
  195.         dos1.total = tres.posicion1;
  196.         dos2.total = tres.posicion2;
  197.     }
  198.     if (vector2 == 4) {
  199.         dos1.total = cuatro.posicion1;
  200.         dos2.total = cuatro.posicion2;
  201.     }
  202.     if (vector2 == 5) {
  203.         dos1.total = cinco.posicion1;
  204.         dos2.total = cinco.posicion2;
  205.     }
  206.    
  207.     dos1.total = dos1.total * -1;
  208.     dos2.total = dos2.total * -1;
  209.    
  210.     uno1.total = dos1.total + uno1.total;
  211.     uno2.total = dos2.total + uno2.total;
  212.  
  213.     cout << "\n- Vector resultante = primero(" << uno1.total << "," << uno2.total << ")";
  214.     return opciones();
  215. }
  216.  
  217. int multvectores() {
  218.    
  219.     cout << "Numero escalar >> ";
  220.     cin >> numescalar;
  221.    
  222.     if (tipo >= 1) {
  223.         uno1.total = numescalar * uno.posicion1;
  224.         uno2.total = numescalar * uno.posicion2;
  225.     }
  226.     if (tipo >= 2) {
  227.         dos1.total = numescalar * dos.posicion1;
  228.         dos2.total = numescalar * dos.posicion2;
  229.     }
  230.     if (tipo >= 3) {
  231.         tres1.total = numescalar * tres.posicion1;
  232.         tres2.total = numescalar * tres.posicion2;
  233.     }
  234.     if (tipo >= 4) {
  235.         cuatro1.total = numescalar * cuatro.posicion1;
  236.         cuatro2.total = numescalar * cuatro.posicion2;
  237.     }
  238.     if (tipo == 5) {
  239.         cinco1.total = numescalar * cinco.posicion1;
  240.         cinco2.total = numescalar * cinco.posicion2;
  241.     }
  242.  
  243.     if (tipo >= 1)
  244.     cout << "\n- Resultado = primero(" << uno1.total << "," << uno2.total << ")";
  245.     if (tipo >= 2)
  246.     cout << "\n- Resultado = segundo(" << dos1.total << "," << dos2.total << ")";
  247.     if (tipo >= 3)
  248.     cout << "\n- Resultado = tercero(" << tres1.total << "," << tres2.total << ")";
  249.     if (tipo >= 4)
  250.     cout << "\n- Resultado = cuarto(" << cuatro1.total << "," << cuatro2.total << ")";
  251.     if (tipo == 5)
  252.     cout << "\n- Resultado = quinto(" << cinco1.total << "," << cinco2.total << ")";
  253.    
  254.     return opciones();
  255. }
  256.  
  257. int divivectores() {
  258.     //Making... YE
  259.     return 0;
  260. }
Advertisement
Add Comment
Please, Sign In to add comment