Está en la página 1de 9

1.

Escribir un programa con objetos con un menú de 4 opciones, para borrar la pantalla y
según la opción seleccionada mostrar tabla de suma, resta, multiplicación, división.

FUNCION MAIN

#include<cstdlib>

#include<iostream>

#include "solucion.h"

#include "solucion.cpp"

using namespace std;

int main()

int op,n;

cout<<"Ingrese un numero: ";

cin>>n;

cout<<"Que operacion quiere con ese numero?"<<endl;

cout<<"1.- TABLA DE SUMAR"<<endl;

cout<<"2.- TABLA DE RESTA"<<endl;

cout<<"3.- TABLA DE MULTIPLICACION"<<endl;

cout<<"4.- TABLA DE DIVISION"<<endl;

cout<<"5.- SALIR"<<endl;

cout<<"ELIJA OPCION: "<<endl;

cin>>op;

if(op>5)

cout<<"OPCION ERRONEA";

return 0;

solucion o(n);

switch(op)

case 1:

o.suma();
break;

case 2:

o.resta();

break;

case 3:

o.multiplicacion();

break;

case 4:

o.division();

break;

while(op!=5);

FUNCION solución.cpp

#include "solucion.h"
#include<cstdlib>
#include<iostream>
using namespace std;
solucion::solucion(int _n)
{
n=_n;
}
void solucion::suma()
{
int aux=1;
system("cls");
cout<<"TABLA DE SUMAR DE "<<n<<endl;
while(aux!=11)
{
cout<<n<<" + "<<aux<<" = "<<n+aux<<endl;
aux++;
}
}
void solucion::resta()
{
int aux=1;
system("cls");
cout<<"TABLA DE RESTAR DE "<<n<<endl;
while(aux!=11)
{
cout<<n<<" - "<<aux<<" = "<<n-aux<<endl;
aux++;
}
}
void solucion::multiplicacion()
{
int aux=1;
system("cls");
cout<<"TABLA DE MULTIPLICAR DE "<<n<<endl;
while(aux!=11)
{
cout<<n<<" * "<<aux<<" = "<<n*aux<<endl;
aux++;
}
}
void solucion::division()
{
int aux=1;
system("cls");
cout<<"TABLA DE DIVIDIR DE "<<n<<endl;
while(aux!=11)
{
cout<<n<<" / "<<aux<<" = "<<n/aux<<endl;
aux++;
}
}
FUNCION solución.h

#ifndef SOLUCION_H
#define SOLUCION_H
class solucion
{
public:
solucion(int);
void suma();
void resta();
void multiplicacion();
void division();
private:
int n;
};

#endif
CORRIDO DEL PROGRAMA:
2.-Juego de adivinar el numero randomico

FUNCION main

#include <iostream>
#include "solucion.h"

using namespace std;

int main()
{
solucion op(0,0);
op.juego();
return 0;
}

FUNCION solución.cpp

#include "solucion.h"
#include<stdlib.h>
#include<time.h>
#include<iostream>
using namespace std;
solucion::solucion(int _num,int _random)
{
srand(time(NULL));
num=_num;
random=rand()%(101-1);
}
void solucion::leer()
{
cout<<"INGRESE UN NUMERO: ";
cin>>num;
}
void solucion::juego()
{
for(int i=1;i<11;i++)
{
cout<<"-----------------ADIVINE EL NUMERO-----------------------"<<endl;
cout<<"INTENTO "<<i<<endl;
leer();
if(num==random)
{
for(int i=0;i<10;i++)
{
cout<<"GANO EL JUEGO!!!!"<<endl;
}
break;
}
else
system("cls");
cout<<"SIGA INTENTANDO"<<endl;
}
if(num!=random)
{
system("cls");
cout<<"-----------------ADIVINE EL NUMERO-----------------------"<<endl;
cout<<"EL NUMERO ERA "<<random<<endl;
for(int j=1;j<11;j++)
{
cout<<"MEJOR SUERTE LA PROXIMA"<<endl;
}
}
}

FUNCION solución.h

#ifndef SOLUCION_H
#define SOLUCION_H

class solucion
{
public:
solucion(int,int);
void juego();
void leer();
private:
int num;
int random;
};

#endif

CORRIDO DEL PROGRAMA:

También podría gustarte