// matrix_move.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include <iostream> #include <conio.h> #include <iomanip> #include <time.h> int FunctionCreatPPointer(int **pP, int iSIZE_I, int iSIZE_J); int FunctionInitPPointer(int **pP, int iSIZE_I, int iSIZE_J); int FunctionMove_LEFT_PPointer(int **pP, int iSIZE_I, int iSIZE_J); int FunctionMove_RIGHT_PPointer(int **pP, int iSIZE_I, int iSIZE_J); int FunctionMove_DOWN_PPointer(int **pP, int iSIZE_I, int iSIZE_J); int FunctionMove_UP_PPointer(int **pP, int iSIZE_I, int iSIZE_J); void FunctionViewPPointer(int **pP, int iSIZE_I, int iSIZE_J); int _tmain(int argc, _TCHAR* argv[]) { const int iSIZE = 11; int **pArrMatrix = new int*[iSIZE]; FunctionCreatPPointer(pArrMatrix, iSIZE, iSIZE); FunctionInitPPointer(pArrMatrix, iSIZE, iSIZE); for(int iKay = 0;;system("cls")) { FunctionViewPPointer(pArrMatrix, iSIZE, iSIZE); switch(iKay = _getch()) { case 224: break; //UP case 72: FunctionMove_UP_PPointer(pArrMatrix, iSIZE, iSIZE); break; //DOWN case 80: FunctionMove_DOWN_PPointer(pArrMatrix, iSIZE, iSIZE); break; //LEFT case 75: FunctionMove_LEFT_PPointer(pArrMatrix, iSIZE, iSIZE); break; //RIGHT case 77: FunctionMove_RIGHT_PPointer(pArrMatrix, iSIZE, iSIZE); break; //EXIT case 27: exit(0); break; } } for(int i = 0; i < iSIZE; ++i) { delete [] pArrMatrix[i]; } delete [] pArrMatrix; return 0; } ////////////////////////////////////////////////////////////////////////////////// /* *Function of memory allocation matrix */ ////////////////////////////////////////////////////////////////////////////////// int FunctionCreatPPointer(int **pP, int iSIZE_I, int iSIZE_J) { for(int i = 0; i < iSIZE_I; ++i) { pP[i] = new int[iSIZE_J]; } return 0; } ////////////////////////////////////////////////////////////////////////////////// /* *The initialization function matrix */ ////////////////////////////////////////////////////////////////////////////////// int FunctionInitPPointer(int **pP, int iSIZE_I, int iSIZE_J) { srand((unsigned)time(NULL)); for(int i = 0; i < iSIZE_I; ++i) { for(int j = 0; j < iSIZE_J; ++j) { pP[i][j] = rand()%9+1; } } return 0; } ////////////////////////////////////////////////////////////////////////////////// /* *The function move matrix LEFT */ ////////////////////////////////////////////////////////////////////////////////// int FunctionMove_LEFT_PPointer(int **pP, int iSIZE_I, int iSIZE_J) { int iTemp; //LEFT for(int i = 0; i < iSIZE_I; ++i) { for(int j = 0; j < iSIZE_J; ++j) { if(j==0) { iTemp = pP[i][j]; } if(j==iSIZE_J-1) { pP[i][j] = iTemp; break; } pP[i][j] = pP[i][j+1]; } } return 0; } ////////////////////////////////////////////////////////////////////////////////// /* *The function move matrix RIGHT */ ////////////////////////////////////////////////////////////////////////////////// int FunctionMove_RIGHT_PPointer(int **pP, int iSIZE_I, int iSIZE_J) { int iTemp; //RIGHT for(int i = 0; i < iSIZE_I; ++i) { for(int j = iSIZE_J-1; 0 <= j; --j) { if(j == iSIZE_J-1) { iTemp = pP[i][j]; } if(j == 0) { pP[i][j] = iTemp; break; } pP[i][j] = pP[i][j-1]; } } return 0; } ////////////////////////////////////////////////////////////////////////////////// /* *The function move matrix DOWN */ ////////////////////////////////////////////////////////////////////////////////// int FunctionMove_DOWN_PPointer(int **pP, int iSIZE_I, int iSIZE_J) { int iTemp; //DOWN for(int i = 0; i < iSIZE_J; ++i) { for(int j = iSIZE_I-1; 0 <= j; --j) { if(j == iSIZE_I-1) { iTemp = pP[j][i]; } if(j == 0) { pP[j][i] = iTemp; break; } pP[j][i] = pP[j-1][i]; } } return 0; } ////////////////////////////////////////////////////////////////////////////////// /* *The function move matrix UP */ ////////////////////////////////////////////////////////////////////////////////// int FunctionMove_UP_PPointer(int **pP, int iSIZE_I, int iSIZE_J) { int iTemp; //UP for(int i = 0; i < iSIZE_J; ++i) { for(int j = 0; j < iSIZE_I; ++j) { if(j==0) { iTemp = pP[j][i]; } if(j==iSIZE_I-1) { pP[j][i] = iTemp; break; } pP[j][i] = pP[j+1][i]; } } return 0; } ////////////////////////////////////////////////////////////////////////////////// /* *Output function matrix */ ////////////////////////////////////////////////////////////////////////////////// void FunctionViewPPointer(int **pP, int iSIZE_I, int iSIZE_J) { for(int i = 0; i < iSIZE_I; ++i) { for(int j = 0; j < iSIZE_J; ++j) { std::cout<<pP[i][j]; } std::cout<<std::endl; } std::cout<<std::endl; }
Движение строк и столбцов в матрице.
Сообщений 1 страница 2 из 2
Поделиться108-04-2011 23:59:29
Поделиться214-07-2023 18:55:09
Brid301BettCHAPDecaEttoWillXVIIStepXVIIwwwiRenoDekoAtlaJeweAccuBarbBonuGeorSoliZoneAnge
SigrSifrTefaElseAppeCredJuicOraltourXVIIJoseRichSplellmuNeutPhilBraiDiscSkinAccaSENSRalp
RobeTextKissStarLopePeteGrimFratAmarDaviWaynavanavanEdwaNintJeanJeweAlkaAlleCalvSelaNiki
AcceGlenByroJeweROSEStepVoltPaulJohaEdwaFranJonaNokiNikhSigrwargAmerZoneBettTituHomeFran
ZoneLeveJewediamSwarKathBRCGlunaAlcaXVIInnerAndrStouRogeRammMargBruxBriaImagViteFredElip
NokiSafsNicKHenrNintBalkGerhXVIIcaptRoseDoomElecSaulBookWorlBookChicBradPolaQueeBestFlip
SauvARAGXboxfrohpracJazzGrouEditEditBlansteaNickWindWindLANGChriWorlBoscSupeOlegChoiHenr
KarlUlriMaurAlliQueeSignKillwwwlqAmaXVIIAcadWindXVIIHonoThorTangbonuBriaAmalArmaGraaIain
UleaThreEsteXIIIconcRollRideClamSteeBridXVIIApplHappWilhPourHeidMicrStepFilmDreaWindXVII
PatrLoveRichCherGeorStarSundcaptcaptcaptESRIGaetTaraLovePennWithSticRobeJeffCyntdresThis
tuchkasfastPatr