Advertisement
Guest User

Untitled

a guest
Oct 17th, 2019
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.97 KB | None | 0 0
  1. #include <iostream>
  2. #include <ctype.h>//toupper, tolower
  3. #include <conio.h>//kbhit: keyboard hit, getch: get character
  4. using namespace std;
  5. using namespace System;//Console::SetCursorPosition(x,y);
  6.  
  7. #define ARRIBA 'W'
  8. #define IZQUIERDA 'A'
  9. #define ABAJO 'S'
  10. #define DERECHA 'D'
  11.  
  12. void jugar() {
  13. short x=10, y=10;
  14. bool continuar = true;
  15. short pasos = 0;
  16. while (continuar) {
  17. if (kbhit()) {
  18. char direccion = getch();
  19.  
  20. switch (toupper(direccion)) {
  21. case ARRIBA : y--; pasos++; break;
  22. case ABAJO : y++; pasos++; break;
  23. case IZQUIERDA: x--; pasos++; break;
  24. case DERECHA : x++; pasos++; break;
  25. }
  26. Console::SetCursorPosition(x, y);
  27. cout << "*";
  28. }
  29. if (pasos == 20)
  30. continuar = false;
  31. }
  32. }
  33.  
  34. int main() {
  35. jugar();
  36. return 0;
  37. }
  38.  
  39. #include <iostream>
  40. #include <string>
  41. using namespace std;
  42.  
  43. typedef struct Complejo {
  44. int real;
  45. int imaginario;
  46. string mostrar() {
  47. return "(" + to_string(real) + " + " + to_string(imaginario) + "i)";
  48. }
  49. void ingresarNumero() {
  50. cout << "Ingrese el numero complejo: " << endl;
  51. cout << "Parte Real : "; cin >> real;
  52. cout << "Parte Imaginaria: "; cin >> imaginario;
  53. }
  54. };
  55. typedef struct Operacion {
  56. Complejo operando1, operando2, resultado;
  57. char operador;
  58. void operar() {
  59. if (operador == '+') sumar();
  60. else if (operador == '-') restar();
  61. }
  62. void restar() {
  63. resultado.real = operando1.real - operando2.real;
  64. resultado.imaginario = operando1.imaginario - operando2.imaginario;
  65. }
  66. void sumar() {
  67. resultado.real = operando1.real + operando2.real;
  68. resultado.imaginario = operando1.imaginario + operando2.imaginario;
  69. }
  70. string mostrarOperacion() {
  71. operar();
  72. return operando1.mostrar() + operador + operando2.mostrar() + "=" + resultado.mostrar();
  73. }
  74. };
  75.  
  76. int main() {
  77. Operacion op1;
  78. op1.operando1.ingresarNumero();
  79. op1.operando2.ingresarNumero();
  80. op1.operador = '+';
  81. cout << op1.mostrarOperacion();
  82. system("pause>0");
  83. return 0;
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement