Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <ctype.h>//toupper, tolower
- #include <conio.h>//kbhit: keyboard hit, getch: get character
- using namespace std;
- using namespace System;//Console::SetCursorPosition(x,y);
- #define ARRIBA 'W'
- #define IZQUIERDA 'A'
- #define ABAJO 'S'
- #define DERECHA 'D'
- void jugar() {
- short x=10, y=10;
- bool continuar = true;
- short pasos = 0;
- while (continuar) {
- if (kbhit()) {
- char direccion = getch();
- switch (toupper(direccion)) {
- case ARRIBA : y--; pasos++; break;
- case ABAJO : y++; pasos++; break;
- case IZQUIERDA: x--; pasos++; break;
- case DERECHA : x++; pasos++; break;
- }
- Console::SetCursorPosition(x, y);
- cout << "*";
- }
- if (pasos == 20)
- continuar = false;
- }
- }
- int main() {
- jugar();
- return 0;
- }
- #include <iostream>
- #include <string>
- using namespace std;
- typedef struct Complejo {
- int real;
- int imaginario;
- string mostrar() {
- return "(" + to_string(real) + " + " + to_string(imaginario) + "i)";
- }
- void ingresarNumero() {
- cout << "Ingrese el numero complejo: " << endl;
- cout << "Parte Real : "; cin >> real;
- cout << "Parte Imaginaria: "; cin >> imaginario;
- }
- };
- typedef struct Operacion {
- Complejo operando1, operando2, resultado;
- char operador;
- void operar() {
- if (operador == '+') sumar();
- else if (operador == '-') restar();
- }
- void restar() {
- resultado.real = operando1.real - operando2.real;
- resultado.imaginario = operando1.imaginario - operando2.imaginario;
- }
- void sumar() {
- resultado.real = operando1.real + operando2.real;
- resultado.imaginario = operando1.imaginario + operando2.imaginario;
- }
- string mostrarOperacion() {
- operar();
- return operando1.mostrar() + operador + operando2.mostrar() + "=" + resultado.mostrar();
- }
- };
- int main() {
- Operacion op1;
- op1.operando1.ingresarNumero();
- op1.operando2.ingresarNumero();
- op1.operador = '+';
- cout << op1.mostrarOperacion();
- system("pause>0");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement