/** * @title: prj2.cpp * @date: 2004.11.16 - 18:02 * @author: vinnie * @source for prj2.exe */ #include #include #include #include #include #include #include "Result.h" int main( ) { // vars const int rumor[64] = { 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0 }; int iLen = 0; char userInput[33]; /////////////////////////////////////////////////////////////////////////// // code system("color 1f"); // menu' label MYMENU: // begin // reset vars memset( userInput, 0, 33); iLen = 0; // print intro & menu system("cls"); printf("\t\t SLCC - CS 2310-01 - Fall 2004 - Project 2\n"); printf("\n Given a string, some random rumor is added."); printf("\n Then the string is retrieved.\n For the sake of brevity "); printf("the input string is limited to 32 chars.\n"); printf("\n Please input your string: "); gets( userInput); /////////////////////////////////////////////////////////////////////////// // how long the string is iLen = strlen( userInput); // toupper the string for ( int i = 0; i < iLen; i++) if ( isalpha( userInput[i]) ) userInput[i] = toupper( userInput[i]); // start the math // gimme as many objects as the chars in the string CResult *res = new CResult [iLen]; // init the randomizer srand( clock() ); // scan the userInput string // set a noise // calc the char + noise for ( int i = 0; i < iLen; i++) { // take a char at time res[i].SetOrigChar( *( userInput + i ) ); // find 3 random noises int noRep[3]; int k; k = rand() % 8; noRep[0] = k; res[i].SetNoiseChar( rumor+8*k, 0); BACK0: k = rand() % 8; if ( k == noRep[0] ) goto BACK0; noRep[1] = k; res[i].SetNoiseChar( rumor+8*k, 1); BACK1: k = rand() % 8; if ( k == noRep[0] || k == noRep[1] ) goto BACK1; noRep[2] = k; res[i].SetNoiseChar( rumor+8*k, 2); // add 3 noises to char res[i].AddNoiseToChar( ); } //////////////////////////////////////////////////////////// // build result and retrieve string for ( int i = 0; i < iLen; i++) { res[i].BuildResult( ); res[i].SetResChar( ); } //////////////////////////////////////////////////////////// // print results printf("\n"); printf("C A OrigChar 1stNoise 2ndNoise 3rdNoise 1st-Res 2nd-Res \ 3rd-Res Final C\n"); printf("\n"); for ( int i = 0; i < iLen; i++) { printf( "%c %d ", userInput[i], userInput[i] ); res[i].GetOrigChar( ); res[i].GetNoise( ); res[i].GetDirtyChar( ); res[i].GetResChar( ); res[i].GetFinal( ); printf("\n"); } /////////////////////////////////////////////////////////////////////////// delete [] res; // ask for an other trip printf("\n Another one [Y/y/N/n]? "); while ( !kbhit() ); char c = getchar( ); if ( c == 'Y' || c == 'y' ) goto MYMENU; /////////////////////////////////////////////////////////////////////////// printf("\n Thanks for using Prj2\n"); printf(" Vincenzo Maggio Code - released under GPL\n"); system("color 0f"); return 0; } // niam