My program;
So I want you to look at my code and point out any errors or stuff thats not functional or missing.Code:#include <iostream> #include <fstream> #include <cstdlib> // exit() #include <vector> #include <string.h> #include <sstream> #include <windows.h> using namespace std; string up = "up"; string upnD = "up and down"; string down = "down"; string right_ = "right"; string left_ = "left"; string straight = "straight"; string around = "around"; string add = "+"; string subtract = "-"; string addSubtract = "+-"; int count_up = 0; int count_upnD = 0; int count_down = 0; int count_right_ = 0; int count_left_ = 0; int count_straight = 0; int count_around = 0; // I use this in the 12 pattern finding functions, to compare stings. string a = "466.16"; // blue, keAS string b = "415.3"; // cyan, keGS string c = "415.3"; // cyan, keGS string d = "415.3"; // cyan, keGS string e = "415.3"; // cyan, keGS string f = "415.3"; // cyan, keGS string g = "349.23"; // yellow, keF string h = "277.18"; // red, keCS string i = "349.23"; // yellow, keF string j = "440"; // blue, keA string k = "392"; // green, keG string l = "261.63"; // red, keC string m = "261.63"; // red, keC string n = "349.23"; // yellow, keF string o = "493.88"; // violet, keB string p = "261.63"; // red, keC string q = "261.63"; // red, keC string r = "329.63"; // orange, keE string s = "311.13"; // red, keDS string t = "415.3"; // cyan, keGS string u = "293.66"; // red, keD string v = "415.3"; // cyan, keGS string w = "311.13"; // red, keDS string x = "369.99"; // green, keFS string y = "392"; // green, keG string z = "392"; // green, keG string gF1 = "A_gFlat_part_1_AND_green:"; // right string gF2 = "A_gFlat_part_1_AND_red:"; // up string gF3 = "A_gFlat_part_1_AND_cyan:"; // left string gF4 = "A_gFlat_part_1_AND_red:"; // up string gF5 = "A_gFlat_part_2_AND_green:"; // right string gF6 = "A_gFlat_part_2_AND_red:"; // up string gF7 = "A_gFlat_part_3_XOR_red:"; // up string gF8 = "A_gFlat_part_4_OR_cyan:"; // left string gF9 = "A_gFlat_part_4_OR_red:"; // up string dF1 = "B_dFlat_part_1_AND_red:"; // up string dF2 = "B_dFlat_part_1_AND_blue:"; // straight string dF3 = "B_dFlat_part_1_AND_red:"; // up string dF4 = "B_dFlat_part_1_AND_cyan:"; // left string dF5 = "B_dFlat_part_2_AND_red:"; // up string dF6 = "B_dFlat_part_2_AND_cyan:"; // left string dF7 = "B_dFlat_part_3_XOR_blue:"; // straight string dF8 = "B_dFlat_part_4_OR_red:"; // up string dF9 = "B_dFlat_part_4_OR_cyan:"; // left string aF1 = "C_aFlat_part_1_AND_cyan:"; // left string aF2 = "C_aFlat_part_1_AND_yellow:"; // down string aF3 = "C_aFlat_part_1_AND_blue:"; // straight string aF4 = "C_aFlat_part_1_AND_red:"; // up string aF5 = "C_aFlat_part_2_AND_cyan:"; // left string aF6 = "C_aFlat_part_2_AND_red:"; // up string aF7 = "C_aFlat_part_3_XOR_yellow:"; // down string aF8 = "C_aFlat_part_4_OR_blue:"; // straight string aF9 = "C_aFlat_part_4_OR_red:"; // up string eF1 = "D_eFlat_part_1_AND_red:"; // up string eF2 = "D_eFlat_part_1_AND_red:"; // up string eF3 = "D_eFlat_part_1_AND_yellow:"; // down string eF4 = "D_eFlat_part_1_AND_blue:"; // straight string eF5 = "D_eFlat_part_2_AND_red:"; // up string eF6 = "D_eFlat_part_2_AND_blue:"; // straight string eF7 = "D_eFlat_part_3_XOR_red:"; // up string eF8 = "D_eFlat_part_4_OR_yellow:"; // down string eF9 = "D_eFlat_part_4_OR_blue:"; // straight string bF1 = "E_bFlat_part_1_AND_blue:"; // straight string bF2 = "E_bFlat_part_1_AND_green:"; // right string bF3 = "E_bFlat_part_1_AND_red:"; // up string bF4 = "E_bFlat_part_1_AND_yellow:"; // down string bF5 = "E_bFlat_part_2_AND_blue:"; // straight string bF6 = "E_bFlat_part_2_AND_yellow:"; // down string bF7 = "E_bFlat_part_3_XOR_green:"; // right string bF8 = "E_bFlat_part_4_OR_red:"; // up string bF9 = "E_bFlat_part_4_OR_yellow:"; // down string F1 = "F_part_1_AND_yellow:"; // down string F2 = "F_part_1_AND_red:"; // up string F3 = "F_part_1_AND_green:"; // right string F4 = "F_part_1_AND_red:"; // up string F5 = "F_part_2_AND_yellow:"; // down string F6 = "F_part_2_AND_red:"; // up string F7 = "F_part_3_XOR_red:"; // up string F8 = "F_part_4_OR_green:"; // right string F9 = "F_part_4_OR_red:"; // up string C1 = "G_C_part_1_AND_red:"; // up string C2 = "G_C_part_1_AND_blue:"; // straight string C3 = "G_C_part_1_AND_red:"; // up string C4 = "G_C_part_1_AND_green:"; // right string C5 = "G_C_part_2_AND_red:"; // up string C6 = "G_C_part_2_AND_green:"; // right string C7 = "G_C_part_3_XOR_blue:"; // straight string C8 = "G_C_part_4_OR_red:"; // up string C9 = "G_C_part_4_OR_green:"; // right string G1 = "H_G_part_1_AND_green:"; // right string G2 = "H_G_part_1_AND_orange:"; // up and down string G3 = "H_G_part_1_AND_blue:"; // straight string G4 = "H_G_part_1_AND_red:"; // up string G5 = "H_G_part_2_AND_green:"; // right string G6 = "H_G_part_2_AND_red:"; // up string G7 = "H_G_part_3_XOR_orange:"; // up and down string G8 = "H_G_part_4_OR_blue:"; // straight string G9 = "H_G_part_4_OR_red:"; // up string D1 = "I_part_1_AND_red:"; // up string D2 = "I_part_1_AND_violet:"; // around string D3 = "I_part_1_AND_orange:"; // up and down string D4 = "I_part_1_AND_blue:"; // straight string D5 = "I_part_2_AND_red:"; // up string D6 = "I_part_2_AND_blue:"; // straight string D7 = "I_part_3_XOR_violet:"; // around string D8 = "I_part_4_OR_orange:"; // up and down string D9 = "I_part_4_OR_blue:"; // straight string A1 = "J_A_part_1_AND_blue:"; // straight string A2 = "J_A_part_1_AND_green:"; // right string A3 = "J_A_part_1_AND_violet:"; // around string A4 = "J_A_part_1_AND_orange:"; // up and down string A5 = "J_A_part_2_AND_blue:"; // straight string A6 = "J_A_part_2_AND_orange:"; // up and down string A7 = "J_A_part_3_XOR_green:"; // right string A8 = "J_A_part_4_OR_violet:"; // around string A9 = "J_A_part_4_OR_orange:"; // up and down string E1 = "K_E_part_1_AND_orange:"; // up and down string E2 = "K_E_part_1_AND_red:"; // up string E3 = "K_E_part_1_AND_green:"; // right string E4 = "K_E_part_1_AND_violet:"; // around string E5 = "K_E_part_2_AND_orange:"; // up and down string E6 = "K_E_part_2_AND_violet:"; // around string E7 = "K_E_part_3_XOR_red:"; // up string E8 = "K_E_part_4_OR_green:"; // right string E9 = "K_E_part_4_OR_violet:"; // around string B1 = "L_B_part_1_AND_violet:"; // around string B2 = "L_B_part_1_AND_cyan:"; // left string B3 = "L_B_part_1_AND_red:"; // up string B4 = "L_B_part_1_AND_green:"; // right string B5 = "L_B_part_2_AND_violet:"; // around string B6 = "L_B_part_2_AND_green:"; // right string B7 = "L_B_part_3_XOR_cyan:"; // left string B8 = "L_B_part_4_OR_red:"; // up string B9 = "L_B_part_4_OR_green:"; // right // This is used for playing sound enum EFrequency { keRest = 0, keC = 262, keCS = 277, keD = 294, keDS = 311, keE = 330, keF = 349, keFS = 370, keG = 392, keGS = 415, keA = 440, keAS = 466, keB = 494, }; enum EDuration { ke16th = 200, ke8th = (ke16th << 1), keQuart = (ke8th << 1), keHalf = (keQuart << 1), keWhole = (keQuart << 1) }; class CNote { public: CNote(unsigned int uiFrequency, unsigned int uiDuration) : muiFrequency(uiFrequency), muiDuration(uiDuration) {} void Play () { if (muiFrequency > 0) { Beep(muiFrequency, muiDuration); } else { Sleep(muiDuration); } } unsigned int muiFrequency; unsigned int muiDuration; }; class CMelody { public: void AddNote(unsigned int uiFrequency, unsigned int uiDuration) { mqNotes.push_back(CNote(uiFrequency, uiDuration)); } void Play () { std::vector<CNote>::iterator qIter; for (qIter = mqNotes.begin(); qIter != mqNotes.end(); ++qIter) { qIter->Play(); } } std::vector<CNote> mqNotes; }; void findMatch(){ std::ifstream hfin1("holdSentence.txt", fstream::app), fin2("holdDatabase.txt"); if (!hfin1 || !fin2) { std::cerr<<"file error\n"; std::exit(1); } string temp1; string temp2; string temp3; string temp4; string temp5; string temp6; string temp7; string temp8; string dataBaseSentence1; string dataBaseSentence2; string dataBaseSentence3; string dataBaseSentence4; string dataBaseSentence5; string dataBaseSentence6; string dataBaseSentence7; int count1 = 0; int count2 = 0; int count3 = 0; int count4 = 0; int count5 = 0; int count6 = 0; int count7 = 0; int countResult = 0; vector<string> text_file1; vector<string> text_file2; vector<string> text_file3; vector<string> text_file4; vector<string> text_file5; vector<string> text_file6; vector<string> text_file7; while( getline( hfin1, temp1 ) ){ while( getline( fin2, temp2 ) ){ for (unsigned int a=0;a < temp1.length();a++){ if(temp2[a] == '1'){ if ( temp1[a] == temp2[a] ) count1++; if(countResult == 0 && (temp1 != temp2)){ dataBaseSentence1 = temp2; countResult++; } } } text_file1.push_back( temp2 ); } } hfin1.close(); fin2.close(); countResult = 0; std::ifstream hfin2("holdSentence.txt", fstream::app), fin3("holdDatabase.txt"); if (!hfin2 || !fin3) { std::cerr<<"file error\n"; std::exit(1); } while( getline( hfin2, temp1 ) ){ while( getline( fin3, temp3 ) ){ for (unsigned int a=0;a < temp1.length();a++){ if(temp3[a] == '2'){ if ( temp1[a] == temp3[a] ) count2++; if(countResult == 0 && (temp1 != temp3)){ dataBaseSentence2 = temp3; countResult++; } } } text_file2.push_back( temp3 ); } } hfin2.close(); fin3.close(); countResult = 0; std::ifstream hfin3("holdSentence.txt", fstream::app), fin4("holdDatabase.txt"); if (!hfin3 || !fin4) { std::cerr<<"file error\n"; std::exit(1); } while( getline( hfin3, temp1 ) ){ while( getline( fin4, temp4 ) ){ for (unsigned int a=0;a < temp1.length();a++){ if(temp4[a] == '3'){ if ( temp1[a] == temp4[a] ) count3++; if(countResult == 0 && (temp1 != temp4)){ dataBaseSentence3 = temp4; countResult++; } } } text_file3.push_back( temp4 ); } } hfin3.close(); fin4.close(); countResult = 0; std::ifstream hfin4("holdSentence.txt", fstream::app), fin5("holdDatabase.txt"); if (!hfin4 || !fin5) { std::cerr<<"file error\n"; std::exit(1); } while( getline( hfin4, temp1 ) ){ while( getline( fin5, temp5 ) ){ for (unsigned int a=0;a < temp1.length();a++){ if(temp5[a] == '4'){ if ( temp1[a] == temp5[a] ) count4++; if(countResult == 0 && (temp1 != temp5)){ dataBaseSentence4 = temp5; countResult++; } } } text_file4.push_back( temp5 ); } } hfin4.close(); fin5.close(); countResult = 0; std::ifstream hfin5("holdSentence.txt", fstream::app), fin6("holdDatabase.txt"); if (!hfin5 || !fin6) { std::cerr<<"file error\n"; std::exit(1); } while( getline( hfin5, temp1 ) ){ while( getline( fin6, temp6 ) ){ for (unsigned int a=0;a < temp1.length();a++){ if(temp6[a] == '5'){ if ( temp1[a] == temp6[a] ) count5++; if(countResult == 0 && (temp1 != temp6)){ dataBaseSentence5 = temp6; countResult++; } } } text_file5.push_back( temp6 ); } } hfin5.close(); fin6.close(); countResult = 0; std::ifstream hfin6("holdSentence.txt", fstream::app), fin7("holdDatabase.txt"); if (!hfin6 || !fin7) { std::cerr<<"file error\n"; std::exit(1); } while( getline( hfin6, temp1 ) ){ while( getline( fin7, temp7 ) ){ for (unsigned int a=0;a < temp1.length();a++){ if(temp7[a] == '6'){ if ( temp1[a] == temp7[a] ) count6++; if(countResult == 0 && (temp1 != temp7)){ dataBaseSentence6 = temp7; countResult++; } } } text_file6.push_back( temp7 ); } } hfin6.close(); fin7.close(); countResult = 0; std::ifstream hfin7("holdSentence.txt", fstream::app), fin8("holdDatabase.txt"); if (!hfin7 || !fin8) { std::cerr<<"file error\n"; std::exit(1); } while( getline( hfin7, temp1 ) ){ while( getline( fin8, temp8 ) ){ for (unsigned int a=0;a < temp1.length();a++){ if(temp8[a] == '7'){ if ( temp1[a] == temp8[a] ) count7++; if(countResult == 0 && (temp1 != temp8)){ dataBaseSentence7 = temp8; countResult++; } } } text_file7.push_back( temp8 ); } } hfin7.close(); fin8.close(); countResult = 0; if(count1 > count2 && (count1 > count3) && (count1 > count4) && (count1 > count5) && (count1 > count6) && (count1 > count7)) cout << endl << endl << "Program response;" << endl << dataBaseSentence1; else if(count2 > count1 && (count2 > count3) && (count2 > count4) && (count2 > count5) && (count2 > count6) && (count2 > count7)) cout << endl << endl << "Program response;" << endl << dataBaseSentence2; else if(count3 > count2 && (count3 > count1) && (count3 > count4) && (count3 > count5) && (count3 > count6) && (count3 > count7)) cout << endl << endl << "Program response;" << endl << dataBaseSentence3; else if(count4 > count2 && (count4 > count3) && (count4 > count1) && (count4 > count5) && (count4 > count6) && (count4 > count7)) cout << endl << endl << "Program response;" << endl << dataBaseSentence4; else if(count5 > count2 && (count5 > count3) && (count5 > count4) && (count5 > count1) && (count5 > count6) && (count5 > count7)) cout << endl << endl << "Program response;" << endl << dataBaseSentence5; else if(count6 > count2 && (count6 > count3) && (count6 > count4) && (count6 > count5) && (count6 > count1) && (count6 > count7)) cout << endl << endl << "Program response;" << endl << dataBaseSentence6; else if(count7 > count2 && (count7 > count3) && (count7 > count4) && (count7 > count5) && (count7 > count6) && (count7 > count1)) cout << endl << endl << "Program response;" << endl << dataBaseSentence7; } void readSentence(std:: string direction, int amount){ std::ofstream newLine("holdSentence.txt", fstream::app); if (!newLine) { std::cerr<<"file error\n"; std::exit(1); } newLine << " " << direction << endl; newLine.close(); std::ifstream fin1("holdSentence.txt", fstream::app), fin2("holdDatabase.txt", fstream::app); if (!fin1 || !fin2) { std::cerr<<"file error\n"; std::exit(1); } string temp1; string temp2; string temp3; int count = 0; vector<string> text_file1; while( getline( fin1, temp1 ) ){ while( getline( fin2, temp2 ) ){ if(temp1 == temp2 && count == 0){ count++; } else if(temp1 == temp2 && count > 0){ count++; } } } fin1.close(); fin2.close(); std::ifstream fin3("holdSentence.txt", fstream::app); std::ofstream fout("holdDatabase.txt", fstream::app); if (!fin3 || !fout) { std::cerr<<"file error\n"; std::exit(1); } if(count == 0){ getline(fin3, temp3); fout << temp3 << endl; } fin3.close(); fout.close(); } void writeSentence(std::string str){ std::ofstream fout("holdSentence.txt", fstream::app); if (!fout) { std::cerr<<"file error\n"; std::exit(1); } char * writable = new char[str.size() + 1]; std::copy(str.begin(), str.end(), writable); writable[str.size()] = '\0'; // don't forget the terminating 0 if (strncmp(writable, " ", 1) == 0) { cout << writable[1]; fout << writable[1]; } else if (strncmp(writable, " ", 1) != 0 ) { cout << " " << writable; fout << " " << writable; } fout.close(); } // This plays the sound void playSound(std::string note, std::string note2){ CMelody songSound; if(note == gF1 ){ songSound.AddNote(keFS, ke8th); // compare chord x writeSentence(note2); count_right_++; } if(note == gF2){ songSound.AddNote(keDS, ke8th + ke16th); // compare chord s writeSentence(note2); count_up++; } if(note == gF3){ songSound.AddNote(keGS, ke16th); // compare chord b writeSentence(note2); count_left_++; } if(note == gF4){ songSound.AddNote(keCS, ke8th + ke16th); // compare chord h writeSentence(note2); count_up++; } if(note == gF5){ songSound.AddNote(keFS, ke8th); // compare chord x writeSentence(note2); count_right_++; } if(note == gF6){ songSound.AddNote(keCS, ke8th + ke16th); // compare chord h writeSentence(note2); count_up++; } if(note == gF7){ songSound.AddNote(keDS, ke8th + ke16th); // compare chord s writeSentence(note2); count_up++; } if(note == gF8){ songSound.AddNote(keGS, ke16th); // compare chord b writeSentence(note2); count_left_++; } if(note == gF9){ songSound.AddNote(keCS, ke8th + ke16th); // compare chord h writeSentence(note2); count_up++; } ////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////// if(note == dF1){ songSound.AddNote(keCS, ke8th + ke16th); // compare chord h writeSentence(note2); count_up++; } if(note == dF2){ songSound.AddNote(keAS, ke16th); // compare chord a writeSentence(note2); count_straight++; } if(note == dF3){ songSound.AddNote(keDS, ke8th + ke16th); // compare chord s writeSentence(note2); count_up++; } if(note == dF4){ songSound.AddNote(keGS, ke16th); // compare chord b writeSentence(note2); count_left_++; } if(note == dF5){ songSound.AddNote(keCS, ke8th + ke16th); // compare chord h writeSentence(note2); count_up++; } if(note == dF6){ songSound.AddNote(keGS, ke16th); // compare chord b writeSentence(note2); count_left_++; } if(note == dF7){ songSound.AddNote(keAS, ke16th); // compare chord a writeSentence(note2); count_straight++; } if(note == dF8){ songSound.AddNote(keDS, ke8th + ke16th); // compare chord s writeSentence(note2); count_up++; } if(note == dF9){ songSound.AddNote(keGS, ke16th); // compare chord b writeSentence(note2); count_left_++; } ////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////// if(note == aF1){ songSound.AddNote(keGS, ke16th); // compare chord b writeSentence(note2); count_left_++; } if(note == aF2){ songSound.AddNote(keF, ke8th); // compare chord g writeSentence(note2); count_down++; } if(note == aF3){ songSound.AddNote(keAS, ke16th); // compare chord a writeSentence(note2); count_straight++; } if(note == aF4){ songSound.AddNote(keDS, ke8th + ke16th); // compare chord s writeSentence(note2); count_up++; } if(note == aF5){ songSound.AddNote(keGS, ke16th); // compare chord b writeSentence(note2); count_left_++; } if(note == aF6){ songSound.AddNote(keDS, ke8th + ke16th); // compare chord s writeSentence(note2); count_up++; } if(note == aF7){ songSound.AddNote(keF, ke8th); // compare chord g writeSentence(note2); count_down++; } if(note == aF8){ songSound.AddNote(keAS, ke16th); // compare chord a writeSentence(note2); count_straight++; } if(note == aF9){ songSound.AddNote(keDS, ke8th + ke16th); // compare chord s writeSentence(note2); count_up++; } ////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////// if(note == eF1){ songSound.AddNote(keDS, ke8th + ke16th); // compare chord s writeSentence(note2); count_up++; } if(note == eF2){ songSound.AddNote(keC, ke8th + ke16th); // compare chord l writeSentence(note2); count_up++; } if(note == eF3){ songSound.AddNote(keF, ke8th); // compare chord g writeSentence(note2); count_down++; } if(note == eF4){ songSound.AddNote(keAS, ke16th); // compare chord a writeSentence(note2); count_straight++; } if(note == eF5){ songSound.AddNote(keDS, ke8th + ke16th); // compare chord s writeSentence(note2); count_up++; } if(note == eF6){ songSound.AddNote(keAS, ke16th); // compare chord a writeSentence(note2); count_straight++; } if(note == eF7){ songSound.AddNote(keC, ke8th + ke16th); // compare chord l writeSentence(note2); count_up++; } if(note == eF8){ songSound.AddNote(keF, ke8th); // compare chord g writeSentence(note2); count_down++; } if(note == eF9){ songSound.AddNote(keAS, ke16th); // compare chord a writeSentence(note2); count_straight++; } ////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////// if(note == bF1){ songSound.AddNote(keAS, ke16th); // compare chord a writeSentence(note2); count_straight++; } if(note == bF2){ songSound.AddNote(keG, ke8th); // compare chord k writeSentence(note2); count_right_++; } if(note == bF3){ songSound.AddNote(keC, ke8th + ke16th); // compare chord l writeSentence(note2); count_up++; } if(note == bF4){ songSound.AddNote(keF, ke8th); // compare chord g writeSentence(note2); count_down++; } if(note == bF5){ songSound.AddNote(keAS, ke16th); // compare chord a writeSentence(note2); count_straight++; } if(note == bF6){ songSound.AddNote(keF, ke8th); // compare chord g writeSentence(note2); count_down++; } if(note == bF7){ songSound.AddNote(keG, ke8th); // compare chord k writeSentence(note2); count_right_++; } if(note == bF8){ songSound.AddNote(keC, ke8th + ke16th); // compare chord l writeSentence(note2); count_up++; } if(note == bF9){ songSound.AddNote(keF, ke8th); // compare chord g writeSentence(note2); count_down++; } ////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////// if(note == F1){ songSound.AddNote(keF, ke8th); // compare chord g writeSentence(note2); count_down++; } if(note == F2){ songSound.AddNote(keD, ke8th + ke16th); // compare chord u writeSentence(note2); count_up++; } if(note == F3){ songSound.AddNote(keG, ke8th); // compare chord k writeSentence(note2); count_right_++; } if(note == F4){ songSound.AddNote(keC, ke8th + ke16th); // compare chord l writeSentence(note2); count_up++; } if(note == F5){ songSound.AddNote(keF, ke8th); // compare chord g writeSentence(note2); count_down++; } if(note == F6){ songSound.AddNote(keC, ke8th + ke16th); // compare chord l writeSentence(note2); count_up++; } if(note == F7){ songSound.AddNote(keD, ke8th + ke16th); // compare chord u writeSentence(note2); count_up++; } if(note == F8){ songSound.AddNote(keG, ke8th); // compare chord k writeSentence(note2); count_right_++; } if(note == F9){ songSound.AddNote(keC, ke8th + ke16th); // compare chord l writeSentence(note2); count_up++; } ////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////// if(note == C1){ songSound.AddNote(keC, ke8th + ke16th); // compare chord l writeSentence(note2); count_up++; } if(note == C2){ songSound.AddNote(keA, ke16th); // compare chord j writeSentence(note2); count_straight++; } if(note == C3){ songSound.AddNote(keD, ke8th + ke16th); // compare chord u writeSentence(note2); count_up++; } if(note == C4){ songSound.AddNote(keG, ke8th); // compare chord k writeSentence(note2); count_right_++; } if(note == C5){ songSound.AddNote(keC, ke8th + ke16th); // compare chord l writeSentence(note2); count_up++; } if(note == C6){ songSound.AddNote(keG, ke8th); // compare chord k writeSentence(note2); count_right_++; } if(note == C7){ songSound.AddNote(keA, ke16th); // compare chord j writeSentence(note2); count_straight++; } if(note == C8){ songSound.AddNote(keD, ke8th + ke16th); // compare chord u writeSentence(note2); count_up++; } if(note == C9){ songSound.AddNote(keG, ke8th); // compare chord k writeSentence(note2); count_right_++; } ////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////// if(note == G1){ songSound.AddNote(keG, ke8th); // compare chord k writeSentence(note2); count_right_++; } if(note == G2){ songSound.AddNote(keE, ke8th + ke16th); // compare chord r writeSentence(note2); count_upnD++; } if(note == G3){ songSound.AddNote(keA, ke16th); // compare chord j writeSentence(note2); count_straight++; } if(note == G4){ songSound.AddNote(keD, ke8th + ke16th); // compare chord u writeSentence(note2); count_up++; } if(note == G5){ songSound.AddNote(keG, ke8th); // compare chord k writeSentence(note2); count_right_++; } if(note == G6){ songSound.AddNote(keD, ke8th + ke16th); // compare chord u writeSentence(note2); count_up++; } if(note == G7){ songSound.AddNote(keE, ke8th + ke16th); // compare chord r writeSentence(note2); count_upnD++; } if(note == G8){ songSound.AddNote(keA, ke16th); // compare chord j writeSentence(note2); count_straight++; } if(note == G9){ songSound.AddNote(keD, ke8th + ke16th); // compare chord u writeSentence(note2); count_up++; } ////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////// if(note == D1){ songSound.AddNote(keD, ke8th + ke16th); // compare chord u writeSentence(note2); count_up++; } if(note == D2){ songSound.AddNote(keRest, ke16th); // compare chord o writeSentence(note2); count_around++; } if(note == D3){ songSound.AddNote(keE, ke8th + ke16th); // compare chord r writeSentence(note2); count_upnD++; } if(note == D4){ songSound.AddNote(keA, ke16th); // compare chord j writeSentence(note2); count_straight++; } if(note == D5){ songSound.AddNote(keD, ke8th + ke16th); // compare chord u writeSentence(note2); count_up++; } if(note == D6){ songSound.AddNote(keA, ke16th); // compare chord j writeSentence(note2); count_straight++; } if(note == D7){ songSound.AddNote(keRest, ke16th); // compare chord o writeSentence(note2); count_around++; } if(note == D8){ songSound.AddNote(keE, ke8th + ke16th); // compare chord r writeSentence(note2); count_upnD++; } if(note == D9){ songSound.AddNote(keA, ke16th); // compare chord j writeSentence(note2); count_straight++; } ////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////// if(note == A1){ songSound.AddNote(keA, ke16th); // compare chord j writeSentence(note2); count_straight++; } if(note == A2){ songSound.AddNote(keFS, ke8th); // compare chord x writeSentence(note2); count_right_++; } if(note == A3){ songSound.AddNote(keRest, ke16th); // compare chord o writeSentence(note2); count_around++; } if(note == A4){ songSound.AddNote(keE, ke8th + ke16th); // compare chord r writeSentence(note2); count_upnD++; } if(note == A5){ songSound.AddNote(keA, ke16th); // compare chord j writeSentence(note2); count_straight++; } if(note == A6){ songSound.AddNote(keE, ke8th + ke16th); // compare chord r writeSentence(note2); count_upnD++; } if(note == A7){ songSound.AddNote(keFS, ke8th); // compare chord x writeSentence(note2); count_right_++; } if(note == A8){ songSound.AddNote(keRest, ke16th); // compare chord o writeSentence(note2); count_around++; } if(note == A9){ songSound.AddNote(keE, ke8th + ke16th); // compare chord r writeSentence(note2); count_upnD++; } ////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////// if(note == E1){ songSound.AddNote(keE, ke8th + ke16th); // compare chord r writeSentence(note2); count_upnD++; } if(note == E2){ songSound.AddNote(keCS, ke8th + ke16th); // compare chord h writeSentence(note2); count_up++; } if(note == E3){ songSound.AddNote(keFS, ke8th); // compare chord x writeSentence(note2); count_right_++; } if(note == E4){ songSound.AddNote(keRest, ke16th); // compare chord o writeSentence(note2); count_around++; } if(note == E5){ songSound.AddNote(keE, ke8th + ke16th); // compare chord r writeSentence(note2); count_upnD++; } if(note == E6){ songSound.AddNote(keRest, ke16th); // compare chord o writeSentence(note2); count_around++; } if(note == E7){ songSound.AddNote(keCS, ke8th + ke16th); // compare chord h writeSentence(note2); count_up++; } if(note == E8){ songSound.AddNote(keFS, ke8th); // compare chord x writeSentence(note2); count_right_++; } if(note == E9){ songSound.AddNote(keRest, ke16th); // compare chord o writeSentence(note2); count_around++; } ////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////// if(note == B1){ songSound.AddNote(keRest, ke16th); // compare chord o writeSentence(note2); count_around++; } if(note == B2){ songSound.AddNote(keGS, ke16th); // compare chord b writeSentence(note2); count_left_++; } if(note == B3){ songSound.AddNote(keCS, ke8th + ke16th); // compare chord h writeSentence(note2); count_up++; } if(note == B4){ songSound.AddNote(keFS, ke8th); // compare chord x writeSentence(note2); count_right_++; } if(note == B5){ songSound.AddNote(keRest, ke16th); // compare chord o writeSentence(note2); count_around++; } if(note == B6){ songSound.AddNote(keFS, ke8th); // compare chord x writeSentence(note2); count_right_++; } if(note == B7){ songSound.AddNote(keGS, ke16th); // compare chord b writeSentence(note2); count_left_++; } if(note == B8){ songSound.AddNote(keCS, ke8th + ke16th); // compare chord h writeSentence(note2); count_up++; } if(note == B9){ songSound.AddNote(keFS, ke8th); // compare chord x writeSentence(note2); count_right_++; } songSound.Play(); } // These next twelve functions are used to find the pattern in the csv file. void gFlat(int letterNumber, string frequency){ std::ofstream fout("pattern_file_out.txt", fstream::app); if (!fout) { std::cerr<<"file error\n"; std::exit(1); } if(letterNumber == 1 && frequency == x) fout << gF1 << endl; if(letterNumber == 2 && frequency == s) fout << gF2 << endl; if(letterNumber == 3 && frequency == b) fout << gF3 << endl; if(letterNumber == 4 && frequency == h) fout << gF4 << endl; if(letterNumber == 5 && frequency == x) fout << gF5 << endl; if(letterNumber == 6 && frequency == h) fout << gF6 << endl; if(letterNumber == 7 && frequency == s) fout << gF7 << endl; if(letterNumber == 8 && frequency == b) fout << gF8 << endl; if(letterNumber == 9 && frequency == h) fout << gF9 << endl; fout.close(); } void dFlat(int letterNumber, string frequency){ std::ofstream fout("pattern_file_out.txt", fstream::app); if (!fout) { std::cerr<<"file error\n"; std::exit(1); } if(letterNumber == 1 && frequency == h) fout << dF1 << endl; if(letterNumber == 2 && frequency == a) fout << dF2 << endl; if(letterNumber == 3 && frequency == s) fout << dF3 << endl; if(letterNumber == 4 && frequency == b) fout << dF4 << endl; if(letterNumber == 5 && frequency == h) fout << dF5 << endl; if(letterNumber == 6 && frequency == b) fout << dF6 << endl; if(letterNumber == 7 && frequency == a) fout << dF7 << endl; if(letterNumber == 8 && frequency == s) fout << dF8 << endl; if(letterNumber == 9 && frequency == b) fout << dF9 << endl; fout.close(); } void aFlat(int letterNumber, string frequency){ std::ofstream fout("pattern_file_out.txt", fstream::app); if (!fout) { std::cerr<<"file error\n"; std::exit(1); } if(letterNumber == 1 && frequency == b) fout << aF1 << endl; if(letterNumber == 2 && frequency == g) fout << aF2 << endl; if(letterNumber == 3 && frequency == a) fout << aF3 << endl; if(letterNumber == 4 && frequency == s) fout << aF4 << endl; if(letterNumber == 5 && frequency == b) fout << aF5 << endl; if(letterNumber == 6 && frequency == s) fout << aF6 << endl; if(letterNumber == 7 && frequency == g) fout << aF7 << endl; if(letterNumber == 8 && frequency == a) fout << aF8 << endl; if(letterNumber == 9 && frequency == s) fout << aF9 << endl; fout.close(); } void eFlat(int letterNumber, string frequency){ std::ofstream fout("pattern_file_out.txt", fstream::app); if (!fout) { std::cerr<<"file error\n"; std::exit(1); } if(letterNumber == 1 && frequency == s) fout << eF1 << endl; if(letterNumber == 2 && frequency == l) fout << eF2 << endl; if(letterNumber == 3 && frequency == g) fout << eF3 << endl; if(letterNumber == 4 && frequency == a) fout << eF4 << endl; if(letterNumber == 5 && frequency == s) fout << eF5 << endl; if(letterNumber == 6 && frequency == a) fout << eF6 << endl; if(letterNumber == 7 && frequency == l) fout << eF7 << endl; if(letterNumber == 8 && frequency == g) fout << eF8 << endl; if(letterNumber == 9 && frequency == a) fout << eF9 << endl; fout.close(); } void bFlat(int letterNumber, string frequency){ std::ofstream fout("pattern_file_out.txt", fstream::app); if (!fout) { std::cerr<<"file error\n"; std::exit(1); } if(letterNumber == 1 && frequency == a) fout << bF1 << endl; if(letterNumber == 2 && frequency == k) fout << bF2 << endl; if(letterNumber == 3 && frequency == l) fout << bF3 << endl; if(letterNumber == 4 && frequency == g) fout << bF4 << endl; if(letterNumber == 5 && frequency == a) fout << bF5 << endl; if(letterNumber == 6 && frequency == g) fout << bF6 << endl; if(letterNumber == 7 && frequency == k) fout << bF7 << endl; if(letterNumber == 8 && frequency == l) fout << bF8 << endl; if(letterNumber == 9 && frequency == g) fout << bF9 << endl; fout.close(); } void F(int letterNumber, string frequency){ std::ofstream fout("pattern_file_out.txt", fstream::app); if (!fout) { std::cerr<<"file error\n"; std::exit(1); } if(letterNumber == 1 && frequency == g) fout << F1 << endl; if(letterNumber == 2 && frequency == u) fout << F2 << endl; if(letterNumber == 3 && frequency == k) fout << F3 << endl; if(letterNumber == 4 && frequency == l) fout << F4 << endl; if(letterNumber == 5 && frequency == g) fout << F5 << endl; if(letterNumber == 6 && frequency == l) fout << F6 << endl; if(letterNumber == 7 && frequency == u) fout << F7 << endl; if(letterNumber == 8 && frequency == k) fout << F8 << endl; if(letterNumber == 9 && frequency == l) fout << F9 << endl; fout.close(); } void C(int letterNumber, string frequency){ std::ofstream fout("pattern_file_out.txt", fstream::app); if (!fout) { std::cerr<<"file error\n"; std::exit(1); } if(letterNumber == 1 && frequency == l) fout << C1 << endl; if(letterNumber == 2 && frequency == j) fout << C2 << endl; if(letterNumber == 3 && frequency == u) fout << C3 << endl; if(letterNumber == 4 && frequency == k) fout << C4 << endl; if(letterNumber == 5 && frequency == l) fout << C5 << endl; if(letterNumber == 6 && frequency == k) fout << C6 << endl; if(letterNumber == 7 && frequency == j) fout << C7 << endl; if(letterNumber == 8 && frequency == u) fout << C8 << endl; if(letterNumber == 9 && frequency == k) fout << C9 << endl; fout.close(); } void G(int letterNumber, string frequency){ std::ofstream fout("pattern_file_out.txt", fstream::app); if (!fout) { std::cerr<<"file error\n"; std::exit(1); } if(letterNumber == 1 && frequency == k) fout << G1 << endl; if(letterNumber == 2 && frequency == r) fout << G2 << endl; if(letterNumber == 3 && frequency == j) fout << G3 << endl; if(letterNumber == 4 && frequency == u) fout << G4 << endl; if(letterNumber == 5 && frequency == k) fout << G5 << endl; if(letterNumber == 6 && frequency == u) fout << G6 << endl; if(letterNumber == 7 && frequency == r) fout << G7 << endl; if(letterNumber == 8 && frequency == j) fout << G8 << endl; if(letterNumber == 9 && frequency == u) fout << G9 << endl; fout.close(); } void D(int letterNumber, string frequency){ std::ofstream fout("pattern_file_out.txt", fstream::app); if (!fout) { std::cerr<<"file error\n"; std::exit(1); } if(letterNumber == 1 && frequency == u) fout << D1 << endl; if(letterNumber == 2 && frequency == o) fout << D2 << endl; if(letterNumber == 3 && frequency == r) fout << D3 << endl; if(letterNumber == 4 && frequency == j) fout << D4 << endl; if(letterNumber == 5 && frequency == u) fout << D5 << endl; if(letterNumber == 6 && frequency == j) fout << D6 << endl; if(letterNumber == 7 && frequency == o) fout << D7 << endl; if(letterNumber == 8 && frequency == r) fout << D8 << endl; if(letterNumber == 9 && frequency == j) fout << D9 << endl; fout.close(); } void A(int letterNumber, string frequency){ std::ofstream fout("pattern_file_out.txt", fstream::app); if (!fout) { std::cerr<<"file error\n"; std::exit(1); } if(letterNumber == 1 && frequency == j) fout << A1 << endl; if(letterNumber == 2 && frequency == x) fout << A2 << endl; if(letterNumber == 3 && frequency == o) fout << A3 << endl; if(letterNumber == 4 && frequency == r) fout << A4 << endl; if(letterNumber == 5 && frequency == j) fout << A5 << endl; if(letterNumber == 6 && frequency == r) fout << A6 << endl; if(letterNumber == 7 && frequency == x) fout << A7 << endl; if(letterNumber == 8 && frequency == o) fout << A8 << endl; if(letterNumber == 9 && frequency == r) fout << A9 << endl; fout.close(); } void E(int letterNumber, string frequency){ std::ofstream fout("pattern_file_out.txt", fstream::app); if (!fout) { std::cerr<<"file error\n"; std::exit(1); } if(letterNumber == 1 && frequency == r) fout << E1 << endl; if(letterNumber == 2 && frequency == h) fout << E2 << endl; if(letterNumber == 3 && frequency == x) fout << E3 << endl; if(letterNumber == 4 && frequency == o) fout << E4 << endl; if(letterNumber == 5 && frequency == r) fout << E5 << endl; if(letterNumber == 6 && frequency == o) fout << E6 << endl; if(letterNumber == 7 && frequency == h) fout << E7 << endl; if(letterNumber == 8 && frequency == x) fout << E8 << endl; if(letterNumber == 9 && frequency == o) fout << E9 << endl; fout.close(); } void B(int letterNumber, string frequency){ std::ofstream fout("pattern_file_out.txt", fstream::app); if (!fout) { std::cerr<<"file error\n"; std::exit(1); } if(letterNumber == 1 && frequency == o) fout << B1 << endl; if(letterNumber == 2 && frequency == b) fout << B2 << endl; if(letterNumber == 3 && frequency == h) fout << B3 << endl; if(letterNumber == 4 && frequency == x) fout << B4 << endl; if(letterNumber == 5 && frequency == o) fout << B5 << endl; if(letterNumber == 6 && frequency == x) fout << B6 << endl; if(letterNumber == 7 && frequency == b) fout << B7 << endl; if(letterNumber == 8 && frequency == h) fout << B8 << endl; if(letterNumber == 9 && frequency == x) fout << B9 << endl; fout.close(); } // This allows me to read the csv file a line at a time, I got it from the internet void readCSV(std::istream &input, std::vector< std::vector<std::string> > &output){ std::string csvLine; // read every line from the stream while( std::getline(input, csvLine) ){ std::istringstream csvStream(csvLine); std::vector<std::string> csvColumn; std::string csvElement; // read every element from the line that is seperated by commas // and put it into the vector or strings while( std::getline(csvStream, csvElement, ',') ){ csvColumn.push_back(csvElement); } output.push_back(csvColumn); } } void openCsv(){ int itemnum = 0; // I read the csv file and find the patterns then write the results to the pattern text file std::fstream file("file_out.csv", ios::in); if (!file) { std::cerr<<"file error\n"; std::exit(1); } // typedef to save typing for the following object typedef std::vector< std::vector<std::string> > csvVector; csvVector csvData; readCSV(file, csvData); // print out read data to prove reading worked for(csvVector::iterator I = csvData.begin(); I != csvData.end(); ++I){ for(std::vector<std::string>::iterator J = I->begin(); J != I->end(); ++J){ itemnum++; string T = *J; gFlat(itemnum, T); dFlat(itemnum, T); aFlat(itemnum, T); eFlat(itemnum, T); bFlat(itemnum, T); F(itemnum, T); C(itemnum, T); G(itemnum, T); D(itemnum, T); A(itemnum, T); E(itemnum, T); B(itemnum, T); } itemnum = 0; } // I close the csv file file.close(); } int main() { std::ofstream aSentence("file_out.txt"); if (!aSentence) { std::cerr<<"file error\n"; std::exit(1); } char theSentence[4096]; cout << "Enter your sentence, end it with a period: "; cin.getline (theSentence,4096); aSentence << theSentence; aSentence.close(); std::ifstream in("file_out.txt"); std::ofstream fin3("holdSentence.txt"); if (!in || !fin3) { std::cerr<<"file error\n"; std::exit(1); } fin3.close(); string temp; float c_; int itemnum = 0; bool word = false; char letters[] = "abcdefghijklmnopqrstuvwxyz"; float freqs[] = {466.16, 415.30, 415.30, 415.30, 415.30, 415.30, 349.23, 277.18, 349.23, 440, 392, 261.63, 261.63, 349.23, 493.88, 261.63, 261.63, 329.63, 311.13, 415.30, 293.66, 415.30, 311.13, 369.99, 392, 392}; char *this_letter; int letter_index; // I convert the input to musical frequency values getline( in, temp ); for (unsigned int a=0;a < temp.length();a++){ if ( temp[a] == '.' || temp[a] == '?' || temp[a] == '!'){ temp[a] = '\n'; // I open then close the file to erase the previous text std::ofstream pattern("pattern_file_out.txt"); pattern.close(); std::ifstream fin("file_out.txt"); std::ofstream fout2("file_out.csv"); std::ofstream fout_3("file_out_2.txt"); if (!fin || !fout2 || !fout_3) { std::cerr<<"file error\n"; std::exit(1); } while ((c_ = fin.get()) != EOF) { if (c_ == '\'') continue; // skip apostrophe if (std::isalpha(c_)) { if (word) fout_3<<" "; if (word) fout2<<','; if ((this_letter = strchr(letters, tolower(c_))) != NULL){ fout_3 << this_letter[0] << endl; letter_index = this_letter - letters; c_ = freqs[letter_index]; } fout2 << c_; word = true; } else if (word) { fout2<<'\n'; word = false; } } fin.close(); fout2.close(); fout_3.close(); } } in.close(); openCsv(); cout << endl << "Input sentence to program, from input.txt;" << endl; // Now I take the text and make it into a sound std::ifstream inputDesign("pattern_file_out.txt"); std::ifstream inputChar("file_out_2.txt"); if (!inputDesign || !inputChar) { std::cerr<<"file error\n"; std::exit(1); } vector<string> text_file1; string temp1; string temp2; while( getline( inputDesign, temp1), getline( inputChar, temp2) ){ string note; string note2; note = temp1; note2 = temp2; playSound(note, note2); text_file1.push_back( temp1 ); } inputDesign.close(); inputChar.close(); if(count_up > count_upnD && (count_up > count_down) && (count_up > count_right_) && (count_up > count_left_) && (count_up > count_straight) && (count_up > count_around)) readSentence("1", count_up); else if(count_upnD > count_up && (count_upnD > count_down) && (count_upnD > count_right_) && (count_upnD > count_left_) && (count_upnD > count_straight) && (count_upnD > count_around)) readSentence("2", count_upnD); else if(count_down > count_upnD && (count_down > count_up) && (count_down > count_right_) && (count_down > count_left_) && (count_down > count_straight) && (count_down > count_around)) readSentence("3", count_down); else if(count_right_ > count_upnD && (count_right_ > count_down) && (count_right_ > count_up) && (count_right_ > count_left_) && (count_right_ > count_straight) && (count_right_ > count_around)) readSentence("4", count_right_); else if(count_left_ > count_upnD && (count_left_ > count_down) && (count_left_ > count_right_) && (count_left_ > count_up) && (count_left_ > count_straight) && (count_left_ > count_around)) readSentence("5", count_left_); else if(count_straight > count_upnD && (count_straight > count_down) && (count_straight > count_right_) && (count_straight > count_left_) && (count_straight > count_up) && (count_straight > count_around)) readSentence("6", count_straight); else if(count_around > count_upnD && (count_around > count_down) && (count_around > count_right_) && (count_around > count_left_) && (count_around > count_straight) && (count_around > count_up)) readSentence("7", count_around); findMatch(); cout << endl << endl; // I pause the console window so you can read the screen results system ("pause"); }
Its my AI program, but I think its buggy and don't know why, so can you look at it and tell me if its OK?