Advertisement
alfredonthecode

funciones

Jun 21st, 2022
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 7.02 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. class Funciones{
  6.    
  7.     float x1 = 0;
  8.     float x2 = 0;
  9.     float tt1 = 0;
  10.     float tt2 = 0;
  11.     char operacion1;
  12.     char operacion2;   
  13.  
  14.     public:
  15.         Funciones();
  16.         void calcularYa(float x1, float x2, float tt1, float tt2, char operacion1, char operacion2);
  17.         void calcularFinal(float x, float tt);
  18.         void calcularDificil(float cp, char operacion1, float termino_ind, float termino_ind4, float cp2, char operacion2, float termino_ind2, float termino_ind3);
  19.         void calcularDificilYa(float x1, float x2, float tt1, float tt2, char operacion1, char operacion2);
  20.         void calcularDificilFinal(float x, float tt);
  21. };
  22.    
  23. Funciones::Funciones(){
  24.    
  25. }
  26.  
  27.  
  28. void Funciones::calcularDificil(float cp, char operacion1, float termino_ind, float termino_ind4, float cp2, char operacion2, float termino_ind2, float termino_ind3){
  29.    
  30.         //segundo paso
  31.     cout << "Sexto paso" << endl;;
  32.     cout << "(" << cp << "X " << operacion1 << " " << termino_ind << ")" << ". " << termino_ind4 << " = " << "(" << cp2 << "X " << operacion2 << " " << termino_ind2 << ")" << ". " << termino_ind3 << endl;
  33.    
  34.  
  35.     float n_cp = termino_ind4 * cp;
  36.     float n_ti = termino_ind4 * termino_ind;
  37.        
  38.     float n_cp2 = termino_ind3 * cp2;
  39.     float n_ti2 = termino_ind3 * termino_ind2;
  40.        
  41.     cout << endl;
  42.    
  43.     cout << "Septimo paso" << endl;;
  44.        
  45.     if(n_ti < 0 and n_ti2 < 0){
  46.        
  47.         operacion1 = '-';
  48.         operacion2 = '-';
  49.        
  50.         cout << n_cp << "X " << operacion1 << " " << n_ti << " = ";
  51.         cout << n_cp2 << "X " << operacion2 << " " << n_ti2 << endl;
  52.        
  53.         cout << endl;          
  54.        
  55.         cout << "Octavo paso" << endl;
  56.        
  57.         calcularDificilYa(n_cp, n_cp2, n_ti, n_ti2, operacion1, operacion2);
  58.  
  59.     }else if(n_ti < 0){
  60.        
  61.         operacion1 = '-';
  62.        
  63.         cout << n_cp << "X " << operacion1 << " " << n_ti << " = ";
  64.         cout << n_cp2 << "X " << operacion2 << " " << n_ti2 << endl;
  65.    
  66.         cout << endl;
  67.        
  68.         cout << "Octavo paso" << endl;
  69.        
  70.         calcularDificilYa(n_cp, n_cp2, n_ti, n_ti2, operacion1, operacion2);
  71.        
  72.     }else if(n_ti2 < 0){
  73.    
  74.         operacion2 = '-';
  75.        
  76.         cout << n_cp << "X " << operacion1 << " " << n_ti << " = ";
  77.         cout << n_cp2 << "X " << operacion2 << " " << n_ti2 << endl;
  78.    
  79.         cout << endl;              
  80.        
  81.         cout << "Octavo paso" << endl;
  82.        
  83.         calcularDificilYa(n_cp, n_cp2, n_ti, n_ti2, operacion1, operacion2);   
  84.            
  85.     }else{
  86.        
  87.         cout << n_cp << "X " << operacion1 << " " << n_ti << " = " << n_cp2 << "X " << operacion2 << " " << n_ti2 << endl;
  88.        
  89.         cout << endl;
  90.        
  91.         cout << "Octavo paso" << endl;
  92.        
  93.         calcularDificilYa(n_cp, n_cp2, n_ti, n_ti2, operacion1, operacion2);
  94.    
  95.        
  96.     }
  97.  
  98.    
  99.    
  100.    
  101.    
  102.    
  103. }
  104.  
  105.  
  106.  
  107. void Funciones::calcularDificilYa(float x1, float x2, float tt1, float tt2, char operacion1, char operacion2){
  108.    
  109.        if( operacion1 == '-' and operacion2 == '-'){
  110.            
  111.         operacion1= '+';   
  112.         operacion2= '+';
  113.                    
  114.         cout << x1 << "X " << operacion1 <<  " " << x2 << "X = " << tt2  << " " << operacion2 << " " << tt1 << endl;
  115.        
  116.         cout << endl;
  117.        
  118.         float tt = tt2 + tt1;
  119.         float x = x1 + x2;
  120.        
  121.         cout << "Noveno paso" << endl;  
  122.        
  123.         calcularDificilFinal(x, tt);
  124.        
  125.        
  126.        }else if( operacion1 == '+' and operacion2 == '+'){
  127.        
  128.         //no hace falta verificar
  129.        
  130.         operacion1= '-';   
  131.         operacion2= '-';
  132.        
  133.         //en caso que todos sean positivos
  134.         cout << x1 << "X " << operacion1 <<  " " << x2 << "X = " << tt2  << " " << operacion2 << " " << tt1 << endl;
  135.        
  136.         cout << endl;
  137.        
  138.         float tt = tt2 - tt1;
  139.         float x = x1 - x2;
  140.    
  141.         cout << "Noveno paso" << endl;  
  142.    
  143.         calcularDificilFinal(x, tt);   
  144.        
  145.        
  146.        }else if(operacion2 == '-'){
  147.        
  148.         operacion1= '+';
  149.            
  150.         cout << x1 << "X " << operacion1 <<  " " << x2 << "X = " << tt2  << " " << operacion2 << " " << tt1 << endl;
  151.        
  152.         cout << endl;
  153.        
  154.         float tt = tt2 - tt1;
  155.         float x = x1 + x2;
  156.        
  157.         cout << "Noveno paso" << endl;  
  158.        
  159.         calcularDificilFinal(x, tt);
  160.        
  161.        
  162.        }else if(operacion1= '-'){
  163.            
  164.         operacion2= '+';
  165.            
  166.         cout << x1 << "X " << operacion1 <<  " " << x2 << "X = " << tt2  << " " << operacion2 << " " << tt1 << endl;
  167.        
  168.         cout << endl;
  169.        
  170.         float tt = tt2 + tt1;
  171.         float x = x1 - x2;
  172.        
  173.         cout << "Noveno paso" << endl;  
  174.        
  175.         calcularDificilFinal(x, tt);
  176.  
  177.        }else{
  178.        
  179.         cout << "No ha ingresado nada" << endl;
  180.        
  181.        }
  182.        
  183.  
  184.    
  185. }
  186.  
  187.  
  188. void Funciones::calcularDificilFinal(float x, float tt){
  189.    
  190.    
  191.         cout << x << "X " << "= " << tt << endl;
  192.        
  193.         cout << endl;
  194.        
  195.         cout << "Decimo paso" << endl;  
  196.        
  197.         cout << "X = " << tt << " / "<< x << endl;
  198.        
  199.         cout << endl;
  200.        
  201.         cout << "Resultado final" << endl;
  202.        
  203.         cout << "X = " << tt / x << endl;
  204.        
  205.         cout << "  " << endl;    
  206.        
  207.    
  208. }
  209.  
  210.  
  211. //**************************************
  212.  
  213. void Funciones::calcularYa(float x1, float x2, float tt1, float tt2, char operacion1, char operacion2){
  214.    
  215.        if( operacion1 == '-' and operacion2 == '-'){
  216.            
  217.         operacion1= '+';   
  218.         operacion2= '+';
  219.                    
  220.         cout << x1 << "X " << operacion1 <<  " " << x2 << "X = " << tt2  << " " << operacion2 << " " << tt1 << endl;
  221.        
  222.         cout << endl;
  223.        
  224.         float tt = tt2 + tt1;
  225.         float x = x1 + x2;
  226.        
  227.         cout << "Cuarto paso" << endl;  
  228.        
  229.         calcularFinal(x, tt);
  230.        
  231.        
  232.        }else if( operacion1 == '+' and operacion2 == '+'){
  233.        
  234.         //no hace falta verificar
  235.        
  236.         operacion1= '-';   
  237.         operacion2= '-';
  238.        
  239.         //en caso que todos sean positivos
  240.         cout << x1 << "X " << operacion1 <<  " " << x2 << "X = " << tt2  << " " << operacion2 << " " << tt1 << endl;
  241.        
  242.         cout << endl;
  243.        
  244.         float tt = tt2 - tt1;
  245.         float x = x1 - x2;
  246.    
  247.         cout << "Cuarto paso" << endl;  
  248.    
  249.         calcularFinal(x, tt);  
  250.        
  251.        
  252.        }else if(operacion2 == '-'){
  253.        
  254.         operacion1= '+';
  255.            
  256.         cout << x1 << "X " << operacion1 <<  " " << x2 << "X = " << tt2  << " " << operacion2 << " " << tt1 << endl;
  257.        
  258.         cout << endl;
  259.        
  260.         float tt = tt2 - tt1;
  261.         float x = x1 + x2;
  262.        
  263.         cout << "Cuarto paso" << endl;  
  264.        
  265.         calcularFinal(x, tt);
  266.        
  267.        
  268.        }else if(operacion1= '-'){
  269.            
  270.         operacion2= '+';
  271.            
  272.         cout << x1 << "X " << operacion1 <<  " " << x2 << "X = " << tt2  << " " << operacion2 << " " << tt1 << endl;
  273.        
  274.         cout << endl;
  275.        
  276.         float tt = tt2 + tt1;
  277.         float x = x1 - x2;
  278.        
  279.         cout << "Cuarto paso" << endl;  
  280.        
  281.         calcularFinal(x, tt);
  282.  
  283.        }else{
  284.        
  285.         cout << "No ha ingresado nada" << endl;
  286.        
  287.        }
  288.        
  289.  
  290.    
  291. }
  292.  
  293.  
  294. void Funciones::calcularFinal(float x, float tt){
  295.    
  296.    
  297.         cout << x << "X " << "= " << tt << endl;
  298.        
  299.         cout << endl;
  300.        
  301.         cout << "Quinto paso" << endl;  
  302.        
  303.         cout << "X = " << tt << " / "<< x << endl;
  304.        
  305.         cout << endl;
  306.        
  307.         cout << "Resultado final" << endl;
  308.        
  309.         cout << "X = " << tt / x << endl;
  310.        
  311.         cout << "  " << endl;    
  312.        
  313.    
  314. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement