Advertisement
Guest User

ejercicios 24 de mayo

a guest
May 24th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 7.62 KB | None | 0 0
  1.  
  2.  
  3.  
  4. //  ejercicio 5.2
  5.  
  6. #include "pch.h"
  7. #include <iostream>
  8. #include <sstream>
  9.  
  10. using namespace std;
  11.  
  12. const int cantidadMaxima = 500;
  13. const int mayoresQue = 100;
  14. const int menoresQue = -10;
  15.  
  16. enum formato {
  17.     Y = 1,
  18.     D = 2,
  19.     M = 3
  20. };
  21.  
  22. int yyyymmdd(int bb, int aa);
  23.  
  24. int main()
  25. {
  26.     /*
  27.     string meses[]
  28.     {
  29.         enero
  30.         febrero
  31.         marzo
  32.         abril
  33.         mayo
  34.         junio
  35.         julio
  36.         agosto
  37.         septiembre
  38.         octubre
  39.         noviembre
  40.         diciembre
  41.     }
  42.         */
  43.     int numeritoMagico = 0;
  44.  
  45.     cout << "ingrese una fecha en formato YYYYMMDD: " << endl;
  46.     cin >> numeritoMagico;
  47.  
  48.  
  49.     cout << yyyymmdd(numeritoMagico, Y) << " ";
  50.  
  51.     if (yyyymmdd(numeritoMagico, M) < 10)
  52.     {
  53.         cout << "0";
  54.     }
  55.  
  56.     cout << yyyymmdd(numeritoMagico, M) << " " << yyyymmdd(numeritoMagico, D);
  57.  
  58. }
  59.  
  60. int yyyymmdd(int bb, int aa)
  61. {
  62.     int exportAnio = 0;
  63.     int exportMes = 0;
  64.     int exportDia = 0;
  65.  
  66.     switch (aa)
  67.     {
  68.     case Y:
  69.     {
  70.         exportAnio = bb / 10000;
  71.         return exportAnio;
  72.     }; break;
  73.     case M:
  74.     {
  75.         exportMes = (bb - ((bb / 10000) * 10000)) / 100;
  76.  
  77.         return exportMes;
  78.     }; break;
  79.     case D:
  80.     {
  81.         exportDia = bb - ((bb / 10000) * 10000) - ((bb - ((bb / 10000) * 10000)) / 100) * 100;
  82.         return exportDia;
  83.     }; break;
  84.  
  85.     default:
  86.         break;
  87.     }
  88. }
  89.  
  90.  
  91. /*
  92.  
  93. //  ejercicio 5.1
  94.  
  95. #include "pch.h"
  96. #include <iostream>
  97. #include <sstream>
  98.  
  99. using namespace std;
  100.  
  101. const int cantidadMaxima = 500;
  102. const int mayoresQue = 100;
  103. const int menoresQue = -10;
  104.  
  105. enum formato {
  106.     Y = 1,
  107.     D = 2,
  108.     M = 3
  109. };
  110.  
  111. int yyyymmdd(int bb, int aa);
  112.  
  113. int main()
  114. {
  115.  
  116.     int numeritoMagico = 0;
  117.  
  118.     cout << "ingrese una fecha en formato YYYYMMDD: " << endl;
  119.     cin >> numeritoMagico;
  120.  
  121.  
  122.     cout << yyyymmdd(numeritoMagico, Y) << " ";
  123.  
  124.     if (yyyymmdd(numeritoMagico, M) < 10)
  125.     {
  126.         cout << "0";
  127.     }
  128.  
  129.     cout << yyyymmdd(numeritoMagico, M) << " " << yyyymmdd(numeritoMagico, D);
  130.  
  131. }
  132.  
  133. int yyyymmdd(int bb, int aa)
  134. {
  135.     int exportAnio = 0;
  136.     int exportMes = 0;
  137.     int exportDia = 0;
  138.  
  139.     switch (aa)
  140.     {
  141.     case Y:
  142.         {
  143.             exportAnio = bb / 10000;
  144.             return exportAnio;
  145.         }; break;
  146.     case M:
  147.         {
  148.             exportMes = (bb - ((bb / 10000) * 10000)) / 100;
  149.            
  150.             return exportMes;
  151.         }; break;
  152.     case D:
  153.         {
  154.             exportDia = bb - ((bb / 10000) * 10000) - ((bb - ((bb / 10000) * 10000)) / 100) * 100;
  155.             return exportDia;
  156.         }; break;
  157.  
  158.         default:
  159.         break;
  160.     }
  161. }
  162.  
  163.  
  164. */
  165.  
  166. /*
  167. // ejercicio 5
  168.  
  169. #include "pch.h"
  170. #include <iostream>
  171. #include <sstream>
  172.  
  173. using namespace std;
  174.  
  175. const int cantidadMaxima = 500;
  176. const int mayoresQue = 100;
  177. const int menoresQue = -10;
  178.  
  179.  
  180. int main()
  181. {
  182.     int recorteAnio = 0;
  183.     int recorteMes = 0;
  184.     int recorteDia = 0;
  185.     float recorteMesFloat = 0;
  186.  
  187.  
  188.     int numeritoMagico = 0;
  189.     int numeroQueEsMultiploDe3 = 0;
  190.     int numeroQueNoEsMultiploDe5ySiDe3 = 0;
  191.     int temp = 0;
  192.     int contador = 0;
  193.  
  194.     cout << "ingrese una fecha en formato YYYYMMDD: " << endl;
  195.     cin >> numeritoMagico;
  196.  
  197.  
  198.     recorteAnio = numeritoMagico / 10000;
  199.     recorteMes = (numeritoMagico - (recorteAnio * 10000))/100;
  200.     recorteDia = numeritoMagico - (recorteAnio * 10000) - recorteMes * 100;
  201.     cout << recorteDia << " " << recorteMes << " " << recorteAnio;
  202.  
  203. }
  204.  
  205. void YYYYMMDD(int bb, int aa)
  206. {
  207.     int exportAnio = 0;
  208.     int exportMes = 0;
  209.     int exportDia = 0;
  210.  
  211.     switch (aa)
  212.     {
  213.         case y
  214.         {
  215.             exportAnio = bb / 10000;
  216.             return exportAnio;
  217.         }
  218.         case m
  219.         {
  220.             exportMes = (bb - ((bb / 10000) * 10000)) / 100;
  221.             return exportMes;
  222.         }
  223.         case d
  224.         {
  225.             exportDia = bb - ((bb / 10000) * 10000) - ((bb - ((bb / 10000) * 10000)) / 100) * 100;
  226.             return exportDia;
  227.         }
  228.  
  229.     default:
  230.         break;
  231.     }
  232.     recorteAnio = numeritoMagico / 10000;
  233.     recorteMes = (numeritoMagico - (recorteAnio * 10000)) / 100;
  234.     recorteDia = numeritoMagico - (recorteAnio * 10000) - recorteMes * 100;
  235. }
  236.  
  237.  
  238. */
  239.  
  240.  
  241.  
  242.  
  243. /*
  244. // ejercicio 4
  245. #include "pch.h"
  246. #include <iostream>
  247. #include <sstream>
  248.  
  249. using namespace std;
  250.  
  251. const int cantidadMaxima = 500;
  252. const int mayoresQue = 100;
  253. const int menoresQue = -10;
  254.  
  255.  
  256. int main()
  257. {
  258.     int numeritoMagico = 0;
  259.     int numeroQueEsMultiploDe3 = 0;
  260.     int numeroQueNoEsMultiploDe5ySiDe3 = 0;
  261.     int temp = 0;
  262.     int contador = 0;
  263.  
  264.     cout << "Decime un numero: " << endl;
  265.     cin >> numeritoMagico;
  266.  
  267.     while(contador < numeritoMagico)
  268.     {
  269.         temp =temp +3;
  270.  
  271.         if ( (temp % 5) != 0)
  272.         {
  273.  
  274.             cout << " "  << temp << " es divisible por 3 y no por 5" << endl;
  275.             contador++;
  276.         }
  277.        
  278.     }
  279.  
  280. }
  281. */
  282.  
  283.  
  284.  
  285.  
  286. /*
  287. //EJERCICIO 3.1
  288.  
  289. #include "pch.h"
  290. #include <iostream>
  291. #include <sstream>
  292.  
  293. using namespace std;
  294.  
  295. const int cantidadMaxima = 500;
  296. const int mayoresQue = 100;
  297. const int menoresQue = -10;
  298.  
  299.  
  300. int main()
  301. {
  302.     int numerosIngresados[cantidadMaxima];
  303.     int index = 0;
  304.     int valorMaximo = 0;
  305.     int valorPuntero = 0;
  306.  
  307.     do
  308.     {
  309.         cout << "Ingresa un numero: ";
  310.         cin >> numerosIngresados[index];
  311.  
  312.         if (numerosIngresados[index] > valorMaximo)
  313.         {
  314.             valorMaximo = numerosIngresados[index];
  315.  
  316.             valorPuntero = index;
  317.         }
  318.  
  319.         index++;
  320.     } while (numerosIngresados[index - 1] > 0);
  321.  
  322.  
  323.  
  324.     cout << "el numero mas grande ingresado fue: " << valorMaximo << endl;
  325.     cout << "y se ubicaba en la posicion: " << valorPuntero + 1;
  326. }
  327.  
  328.  
  329. int valorMayor(int a, int b)
  330. {
  331.     if (a > b)
  332.     {
  333.         b = a;
  334.     }
  335.    
  336.  
  337.     // Retornar  algo
  338.     return a;
  339. }
  340. */
  341.  
  342. /*
  343. //EJERCICIO 3
  344.  
  345. #include "pch.h"
  346. #include <iostream>
  347. #include <sstream>
  348.  
  349. using namespace std;
  350.  
  351. const int cantidadMaxima = 500;
  352. const int mayoresQue = 100;
  353. const int menoresQue = -10;
  354.  
  355.  
  356. int main()
  357. {
  358.     int numerosIngresados[cantidadMaxima];
  359.     int index = 0;
  360.     int valorMaximo = 0;
  361.     int valorPuntero = 0;
  362.  
  363.     do
  364.     {
  365.         cout << "Ingresa un numero: ";
  366.         cin >> numerosIngresados[index];
  367.  
  368.         if (numerosIngresados[index] > valorMaximo)
  369.         {
  370.             valorMaximo = numerosIngresados[index];
  371.  
  372.             valorPuntero = index;
  373.         }
  374.  
  375.     index++;
  376.     }while (numerosIngresados[index-1] > 0);
  377.  
  378.  
  379.  
  380.     cout << "el numero mas grande ingresado fue: " << valorMaximo << endl;
  381.     cout << "y se ubicaba en la posicion: " << valorPuntero+1;
  382. }
  383. */
  384.  
  385. /*
  386.  
  387. // ejercicio 2
  388.  
  389. #include "pch.h"
  390. #include <iostream>
  391. #include <sstream>
  392.  
  393. using namespace std;
  394.  
  395. const int cantidadMaxima = 5;
  396. const int mayoresQue = 100;
  397. const int menoresQue = -10;
  398.  
  399.  
  400. int main()
  401. {
  402.  
  403.     int numerosIngresados[cantidadMaxima];
  404.  
  405.     int promedioNumeros = 0;
  406.     int sumaNumeros = 0;
  407.     int contadorDeNumeros = 0;
  408.     int entrada = 0;
  409.  
  410.     for (int index = 0; index < cantidadMaxima; index++)
  411.     {
  412.         cout << "Ingresa un numero: ";
  413.         cin >> numerosIngresados[index];
  414.         if (numerosIngresados[index] > mayoresQue)
  415.         {
  416.             promedioNumeros = promedioNumeros + numerosIngresados[index];
  417.             contadorDeNumeros++;
  418.  
  419.         }
  420.         else  if (numerosIngresados[index] < menoresQue)
  421.         {
  422.             sumaNumeros = numerosIngresados[index] + sumaNumeros;
  423.         }
  424.     }
  425.  
  426.     cout << "el promedio de los numeros mayores que 100 es: " << (promedioNumeros/contadorDeNumeros) << endl;
  427.     cout << "la suma de los numeros menores que -10 es: " << sumaNumeros;
  428.    
  429. }
  430. */
  431.  
  432.  
  433.  
  434.  
  435.  
  436.  
  437.  
  438.  
  439.  
  440.  
  441.  
  442.  
  443.  
  444.  
  445.  
  446.  
  447.  
  448.  
  449.  
  450.  
  451.  
  452.  
  453.  
  454.  
  455.  
  456.  
  457. /*
  458.  
  459. //ejercicio 1.5
  460. #include "pch.h"
  461. #include <iostream>
  462. #include <sstream>
  463.  
  464. using namespace std;
  465.  
  466.  
  467. int main()
  468. {
  469.     int unaVariable = 9999999999999999;
  470.     int entrada = 0;
  471.  
  472.     for (int index = 0; index < 10; index++)
  473.         {
  474.         cout << "Ingresa un numero: ";
  475.         cin >> entrada;
  476.         if (entrada < unaVariable)
  477.         {
  478.             unaVariable = entrada;
  479.  
  480.         }
  481.         }
  482.    
  483.     std::cout << unaVariable;
  484. }
  485. */
  486.  
  487. /*
  488.  
  489. //ejercicio 1
  490.  
  491. #include "pch.h"
  492. #include <iostream>
  493. #include <sstream>
  494.  
  495. using namespace std;
  496.  
  497.  
  498. int main()
  499. {
  500.     int unaVariable = 0;
  501.     int entrada = 0;
  502.  
  503.     for (int index = 0; index < 10; index++)
  504.         {
  505.         cout << "Ingresa un numero: ";
  506.         cin >> entrada;
  507.         if (entrada > unaVariable)
  508.         {
  509.             unaVariable = entrada;
  510.  
  511.         }
  512.         }
  513.  
  514.     std::cout << unaVariable;
  515. }
  516.  
  517. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement