Foro de elhacker.net

Programación => Programación C/C++ => Mensaje iniciado por: eduardo17445 en 22 Noviembre 2012, 05:51 am



Título: me gustaria q m dijeran como va este programa
Publicado por: eduardo17445 en 22 Noviembre 2012, 05:51 am

//debe hacer las operaciones de la calculadora

#include <iostream>
using namespace std;
class calculadora
{
private:
   int n,k,b,c,d,f,e,w;
   int i,j,g,a;
   float h;
public:
void leer_datos();
void restar_sumar_multiplicar_dividir();
void introducir_operaciones();
};
    void calculadora::leer_datos()
{
     cout<<"introducir numero";
    cin>>n;
    cout<<"introduzca numeros";
    cin>>a;
  }
    void calculadora::restar_sumar_multiplicar_dividir()
    {
        int i=0;
       i=e+w;
       i=i;
       int k=0;   
        h=n-a;
        k=k;
        int j=0;
       j=n*d;
       j=j;
       
      float h=0.0;
          h=n/g;
        h=h;
        }
        void calculadora::introducir_operaciones()
        {
             
             
        }
    int main()
    {
       calculadora x;
       x.leer_datos();
      x.restar_sumar_multiplicar_dividir();
      x.introducir_operaciones();
        system("pause");
        return 0;
    }
         
     


Título: Re: me gustaria q m dijeran como va este programa
Publicado por: Sputnik_ en 22 Noviembre 2012, 16:23 pm
A primera vista parece bien, aunque esta un poco entreverado y todo junto se mescla más, y tmb sin la etiqueta del codigo aun más  :xD, tirándote una idea, le pondría para que se puedan sumar más valores, yo hace un tiempo hice una calculadora con muchas funciones en C, en la parte de las operaciones básicas, hice que se puedan sumar varios valores

Te paso ese fragmento por si lo queres usar.

Código
  1. void operacion(void)
  2. {
  3.    int op,cantidad,i; //OP = OPERACION, SE LLAMO OP YA QUE OPERACION ES EL NOMBRE DE LA FUNCION
  4.    float suma1=0,suma2=0,resta1=0,resta2=0,mult1=1,mult2=1,div1=1,div2=1;
  5.  
  6.    puts("OPERACIONES SIMPLES:");
  7.    printf("1 - SUMA\n2 - RESTA\n3 - MULTIPLICACION\n4 - DIVISION\n\nRESPUESTA: ");
  8.    scanf("%d",&op);
  9.    switch(op){
  10.    case 1: {
  11.  
  12.        printf("\n\nCANTIDAD DE VALORES A SUMAR: ");
  13.        scanf("%d",&cantidad); //ESTO PERMITE SUMAR MAS DE UN ELEMENTO
  14.  
  15.        for(i=1;i<cantidad+1;i++)
  16.    {
  17.            printf("\n%d º VALOR: ",i);
  18.            scanf("%f",&suma1);
  19.            suma2+=suma1;
  20.    }
  21.        printf("\nLA SUMA DE DICHOS VALORES ES: %f",suma2);
  22.        break;
  23.    }
  24.  
  25.    case 2: {
  26.        printf("\n\nCANTIDAD DE VALORES A RESTAR: ");
  27.        scanf("%d",&cantidad);
  28.        printf("\n1 º VALOR: ");
  29.            scanf("%f",&resta1);
  30.            resta2=resta1;
  31.  
  32.        for(i=2;i<cantidad+1;i++)
  33.        {
  34.            printf("\n%d º VALOR: ",i);
  35.            scanf("%f",&resta1);
  36.            resta2-=resta1;
  37.        }
  38.        printf("\nLA RESTA DE DICHOS VALORES ES: %f",resta2);
  39.        break;
  40.    }
  41.  
  42.    case 3: {
  43.        printf("\n\nCANTIDAD DE VALORES A MULTIPLICAR: ");
  44.        scanf("%d",&cantidad);
  45.        for (i=1;i<cantidad+1;i++)
  46.        {
  47.            printf("\n%d º VALOR: ",i);
  48.            scanf("%f",&mult1);
  49.            mult2*=mult1;
  50.        }
  51.        printf("\nEL PRODUCTO DE DICHOS VALORES ES: %f",mult2);
  52.        break;
  53.    }
  54.  
  55.    case 4: {
  56.        printf("\n\nCANTIDAD DE VALORES A DIVIDIR: ");
  57.        scanf("%d",&cantidad);
  58.        printf("\n1 º VALOR: ");
  59.        scanf("%f",&div1);
  60.        div2=div1;
  61.        for(i=2;i<cantidad+1;i++)
  62.        {
  63.            printf("\n%d º VALOR: ",i);
  64.            scanf("%f",&div1);
  65.            div2/=div1;
  66.        }
  67.        printf("\nEL RESULTADO DE DIVIDIR DICHOS VALORES ES: %f",div2);
  68.        break;
  69.        }
  70.    }

Saludos  ;-)


Título: Re: me gustaria q m dijeran como va este programa
Publicado por: eduardo17445 en 22 Noviembre 2012, 22:28 pm
ah ok pero lo debo hacer con clase