// This program writes the letters to be used as input in Project9.cp #include using namespace std; //introduces namespace std #include #include #include int m ; char inp ; double percent ; int let[10][10][6] ; class Letter { private: struct storage { int pattern1[10]; int pattern2[10]; int updown; }; public: void a(); void h(); void i(); void o(); void x(); void Construction( storage out ); void alphabet(); void output(); }; void Letter::alphabet( ) { Letter call; switch( inp ) { case 'a': case 'A': call.a(); break; case 'h': case 'H': call.h(); break; case 'i': case 'I': call.i(); break; case 'o': case 'O': call.o(); break; case 'x': case 'X': call.x(); break; } } void Letter::a() { storage a1 = { {4, 3, 2, 1, 1, 5, 3, 2, 2, 2}, {1, 2, 2, 2, 4, 0, 2, 3, 3, 3}, 1 }; Construction( a1 ); } void Letter::h() { storage h1 = { {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {2, 2, 2, 2, 5, 0, 0, 0, 0, 0}, 0 }; Construction( h1 ); } void Letter::i() { storage i1 = { {3, 3, 4, 4, 4, 0, 0, 0, 0, 0}, {2, 2, 1, 1, 1, 0, 0, 0, 0, 0}, 0 }; Construction( i1 ); } void Letter::o() { storage o1 = { {2, 1, 0, 0, 0, 0, 0, 0, 0, 0 }, {3, 4, 3, 2, 2, 0, 0, 0, 0, 0 }, 0 }; Construction( o1 ); } void Letter::x() { storage x1 = { {0, 1, 2, 3, 4, 0, 0, 0, 0, 0 }, {2, 2, 2, 2, 1, 0, 0, 0, 0, 0 }, 0 }; Construction( x1 ); } void Letter::Construction( storage out ) { int i, j, symmetry = 5 ; int up, down ; if( out.updown != 0 ) symmetry = 10 ; for(i = 0; i < symmetry; i++) { for( j = 0; j < 5; j++) { if( i < 5 || out.updown == 0 ) { up = 1; down = -1; } else if( out.updown == 1 ) { up = -1; down = 1; } if( j < out.pattern1[i] ) let[i][j][m] = down ; else { if( j < out.pattern1[i] + out.pattern2[i] ) let[i][j][m] = up ; else let[i][j][m] = down ; } if( out.updown != 1 ) { let[9-i][j][m] = let[i][j][m] ; let[9-i][9-j][m] = let[9-i][j][m] ; } let[i][9-j][m] = let[i][j][m] ; } } } void Letter::output() { ofstream fout1("J.dat"); ofstream fout2("sigma.dat"); double x ; int i, j ; cout << "\nOutput:\n"; for( m = 0; m < 6; m++ ) for( i = 0; i < 10; i++ ) { for( j = 0; j < 10; j++ ) { if( m < 5 ) { if( let[i][j][m] == 1 ) fout1 << "+\n" ; else fout1 << "-\n" ; } else { x = drand48(); if( x > percent ) { if( let[i][j][m] == 1 ) { fout2 << "+\n" ; cout << "+ " ; } else { fout2 << "-\n" ; cout << "- " ; } } else { if( let[i][j][m] == 1 ) { fout2 << "-\n" ; cout << "- " ; } else { fout2 << "+\n" ; cout << "+ " ; } } if( j == 9 ) cout << "\n" ; } } } fout1.close() ; fout2.close() ; } main() { Letter step; int iseed = 25969 ; int flag=0; srand48(iseed) ; m = 0 ; step.a(); m = 1 ; step.h(); m = 2 ; step.i(); m = 3 ; step.o(); m = 4 ; step.x(); m = 5; do{ cout << "Enter the letter you wish to have identified and randomized ( a, h, i, o, x). \n" ; cin >> inp ; if( inp != 'a' && inp != 'h' && inp != 'i' && inp != 'o' && inp != 'x' ) if( inp != 'A' && inp != 'H' && inp != 'I' && inp != 'O' && inp != 'X' ) flag = 1; else flag = 0; else flag = 0; } while( flag == 1 ); step.alphabet(); flag = 1; do{ cout << "Enter the percentage of the spins you wish subject to randomization. \n" ; cin >> percent ; } while( percent > 100 || percent < 0 ); percent /= 100.0 ; m = 0; step.output( ); }