elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Únete al Grupo Steam elhacker.NET


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación C/C++ (Moderadores: Eternal Idol, Littlehorse, K-YreX)
| | |-+  C++ y P.OO
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: C++ y P.OO  (Leído 1,322 veces)
V_Dan

Desconectado Desconectado

Mensajes: 8


Ver Perfil
C++ y P.OO
« en: 22 Julio 2012, 04:37 am »

Tengo este código, pero no me deja declarar los métodos donde están y la verdad no creo que este bien :S
Les Agradecería mucho la ayuda y una explicación de P.o.o
#include <iostream>
using namespace std;



class IntroCompGraf {
private:
int x[100][3];
public:

void leerDatos();
float alturaMedia();
float pesoMedia();
int numMujeres();
int numHombres();
};// Fin ICG



float am1,am2;

int A[3][3]={170,80,0,160,1,165,70,0};
int C[2][3]={170,60,0,165,65,1};


void IntroCompGraf::leerDatos(int B [][3]);
{
for(i=0;i<n;i++)
{
for(j=0;j<3;j++)
{
x[j]=B[j];
}
};
return ;
};//LeerD

float IntroCompGraf::alturaMedia(int n)
{
int suma=0, media;
for(i=0;i<n;i++)
{

suma=x
  • +suma;

};
media=suma/n;
return media;
};//finaM

float IntroCompGraf::pesoMedia(int n)
{
int suma=0, media;
for(i=0;i<n;i++)
{

suma=x[1]+suma;

};
media=suma/n;
return media;
};//finpM


float IntroCompGraf::numHombres(int n)
{
int aux;
for(i=0;i<n;i++)
{
if(x[3]=1)
{
aux=++
};
};

return aux;
};//finnH

float IntroCompGraf::numMujeres(int n)
{
int aux;
for(i=0;i<n;i++)
{
if(x[4]=1)
{
aux=++
};
};

return aux;
};//finnM


int main ()
{

IntroCompGraf g1,g2;
g1.leerDatos(A,3);
am1=g1.alturaMedia();
g2.leerDatos(C,2);
am2=g2.alturaMedia();


}//Fin Main

Muchas Gracias!


En línea

bemone

Desconectado Desconectado

Mensajes: 74



Ver Perfil
Re: C++ y P.OO
« Respuesta #1 en: 22 Julio 2012, 05:24 am »

Se declara la clase arriba del main y abajo del main el codigo con los objetos y cuando se cierra la funcion no se pone punto y coma.
Ej:

Código
  1. #include <iostream>
  2. using namespace std;
  3.  
  4.  
  5.  
  6. class IntroCompGraf {
  7. private:
  8. int x[100][3];
  9. public:
  10.  
  11. void leerDatos();
  12. float alturaMedia();
  13. float pesoMedia();
  14. int numMujeres();
  15. int numHombres();
  16. };// Fin ICG
  17.  
  18.  
  19.  
  20. float am1,am2;
  21.  
  22. int A[3][3]={170,80,0,160,1,165,70,0};
  23. int C[2][3]={170,60,0,165,65,1};
  24.  
  25. int main ()
  26. {
  27.  
  28. IntroCompGraf g1,g2;
  29. g1.leerDatos(A,3);
  30. am1=g1.alturaMedia();
  31. g2.leerDatos(C,2);
  32. am2=g2.alturaMedia();
  33. }//Fin Main
  34.  
  35. void IntroCompGraf::leerDatos(int B [][3]);
  36. {
  37. for(i=0;i<n;i++)
  38. {
  39. for(j=0;j<3;j++)
  40. {
  41. x[j]=B[j];
  42. }
  43. }
  44. return ;
  45. }//LeerD
  46.  
  47. float IntroCompGraf::alturaMedia(int n)
  48. {
  49. int suma=0, media;
  50. for(i=0;i<n;i++)
  51. {
  52.  
  53. suma=x
  54. +suma;
  55.  
  56. }
  57. media=suma/n;
  58. return media;
  59. }//finaM
  60.  
  61. float IntroCompGraf::pesoMedia(int n)
  62. {
  63. int suma=0, media;
  64. for(i=0;i<n;i++)
  65. {
  66.  
  67. suma=x[1]+suma;
  68.  
  69. }
  70. media=suma/n;
  71. return media;
  72. }//finpM
  73.  
  74.  
  75. float IntroCompGraf::numHombres(int n)
  76. {
  77. int aux;
  78. for(i=0;i<n;i++)
  79. {
  80. if(x[3]=1)
  81. {
  82. aux=++
  83. }
  84. }
  85.  
  86. return aux;
  87. };//finnH
  88.  
  89. float IntroCompGraf::numMujeres(int n)
  90. {
  91. int aux;
  92. for(i=0;i<n;i++)
  93. {
  94. if(x[4]=1)
  95. {
  96. aux=++
  97. }
  98. }
  99.  
  100. return aux;
  101. }//finnM
  102.  


« Última modificación: 22 Julio 2012, 05:27 am por bemone » En línea

Odio los tipos de variable de Windows.
Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines