Red de conocimientos turísticos - Información de alquiler - Utilice VS2008 para programar vc++

Utilice VS2008 para programar vc++

//?xx.cpp?:?Define el punto de entrada para la aplicación de consola.

//

#include?"stdafx.h"

#include?

#include?< time.h>

clase?CMyArray

{

público:

CMyArray(int?*pArray,int?count)

{

if(count?>?0)

{

m_pArray?=?new?int[m_nCount?=?count ];

memcpy(m_pArray,pArray,count*sizeof(int));

}

else

{

m_pArray?=?NULL;

m_nCount?=?0;

}

}

~CMyArray()

{

if(m_pArray)

¿eliminar?[]m_pArray;

}

¿void?Mostrar ()

{

for(int?i=0;i

printf("%d\t",m_pArray[i ]);

printf("\r\n");

}

void?ShowMax()

{

p>

if(m_nCount?>?0)

{

int?max?=?m_pArray[0];

for(int? i=1;i

{

if(m_pArray[i]?>?max)

max?=?m_pArray [i];

}

printf("%d\r\n",max);

}

}

void?ShowMinus(const?CMyArray&?dest)

{

printf("%d\r\n",this-> operador-(dest) );

}

int?operator?-(const?CMyArray&?dest)

{

si (m_nCount?!= ?dest.m_nCount)

return?0;

int?result?=?0;

for(int?i=0 ;i

{

resultado?+=?m_pArray[i]-dest.m_pArray[i];

}

return?resultado;

}

privado:

int?*m_pArray;

int?m_nCount;

};

int?_tmain(int?argc,?_TCHAR*?argv[])

{

int?x [10];

srand((unsigned?int)time(NULL));

<

p> for(int?i=0;i<10;++i)

x[i]?=?rand();

CMyArray?array(x,10 );

printf("Array 1:\r\n");

array.Show();

printf("Valor máximo del array 1 : ");

array.ShowMax();

for(int?i=0;i<10;++i)

++x [ i];

CMyArray?array2(x,10);

printf("array2:\r\n");

array2.Show( );

printf("Valor máximo de la matriz 2:");

array2.ShowMax();

printf("array2-array1=" ) ;

array2.ShowMinus(array);

system("pausa");

return?0;

}< / p>