none
There is only a int value in my cvs file, but I want a decimal and percent value too

    Question

  • Here is my code so far, which work fine.

    #include <iostream>
    #include <fstream>
    #include <cstdlib> // exit()
    #include <cctype>  // isalpha(), tolower()
    #include <algorithm>
    
    int main() {
        using std::replace;
        std::ifstream fin("file_in.txt");
        std::ofstream fout("file_out.csv");
        if (!fin || !fout) { std::cerr<<"file error\n"; std::exit(1); }
        int c;
        bool word = false;
        while ((c = fin.get()) != EOF) {
            if (c == '\'') continue; // skip apostrophe
            if (std::isalpha(c)) {
                if (word) fout<<',';
    
                if(c == 'a' || c == 'A')
                c = 1;
                else if(c == 'b' || c == 'B')
                c = 1;
                else if(c == 'c' || c == 'C')
                c = 1;
                else if(c == 'd' || c == 'D')
                c = 1;
                else if(c == 'e' || c == 'E')
                c = 1;
                else if(c == 'f' || c == 'F')
                c = 1;
                else if(c == 'g' || c == 'G')
                c = 1;
                else if(c == 'h' || c == 'H')
                c = 1;
                else if(c == 'i' || c == 'I')
                c = 1;
                else if(c == 'j' || c == 'J')
                c = 1;
                else if(c == 'k' || c == 'K')
                c = 1;
                else if(c == 'l' || c == 'L')
                c = 1;
                else if(c == 'm' || c == 'M')
                c = 1;
                else if(c == 'n' || c == 'N')
                c = 1;
                else if(c == 'o' || c == 'O')
                c = 1;
                else if(c == 'p' || c == 'P')
                c = 1;
                else if(c == 'q' || c == 'Q')
                c = 1;
                else if(c == 'r' || c == 'R')
                c = 1;
                else if(c == 's' || c == 'S')
                c = 1;
                else if(c == 't' || c == 'T')
                c = 1;
                else if(c == 'u' || c == 'U')
                c = 1;
                else if(c == 'v' || c == 'V')
                c = 1;
                else if(c == 'w' || c == 'W')
                c = 1;
                else if(c == 'x' || c == 'X')
                c = 1;
                else if(c == 'y' || c == 'Y')
                c = 1;
                else if(c == 'z' || c == 'Z')
                c = 1;
                fout << c;
                word = true;
            }
            else if (word) {
                fout<<'\n';
                word = false;
            }
        }
    }
    

    Saturday, May 12, 2012 3:49 AM

Answers

  • "but  I would still like to get the csv output file to have float values instead of int."

    I've no idea what you are trying to do with that code but my guess is that in the float version you're assigning the float value to the 'c' variable and as a result your output doesn't contain float numbers but integers. If that's indeed the case you need to create another variable, say "float f;" assign those float value to 'f' instead of 'c' and the do fout << f; instead of fout << c;

    PS: and you really should be using an array of value to make that code shorter and more readable. That huge if/else can be replaced by an array with 26 values and you can index into the array with some code like "values[tolower(c) - 'a']"
    Saturday, May 12, 2012 7:09 AM
    Moderator

All replies

  • I suggest you post your problem in a message body
    rather than just in the Subject of the thread.
    You should also be more explicit, and give an
    example of what you want to achieve.

    On a different point, you should be able to replace
    that lengthy block of nested conditionals with a
    single isalpha().

    isalpha, iswalpha, _isalpha_l, _iswalpha_l
    http://msdn.microsoft.com/en-us/library/xt82b8z8.aspx

    "isalpha returns a nonzero value if c is within the
    ranges A - Z or a - z."

    - Wayne
    Saturday, May 12, 2012 6:11 AM
  • Here is my code with the int values;

    #include <iostream>
    #include <fstream>
    #include <cstdlib> // exit()
    #include <cctype>  // isalpha(), tolower()
    
    int main() {
        std::ifstream fin("file_in.txt");
        std::ofstream fout("file_out.csv");
        if (!fin || !fout) { std::cerr<<"file error\n"; std::exit(1); }
        int c;
        bool word = false;
        while ((c = fin.get()) != EOF) {
            if (c == '\'') continue; // skip apostrophe
            if (std::isalpha(c)) {
                if (word) fout<<',';
    
                if(c == 'a' || c == 'A')
                c = 466;
                else if(c == 'b' || c == 'B')
                c = 415;
                else if(c == 'c' || c == 'C')
                c = 415;
                else if(c == 'd' || c == 'D')
                c = 415;
                else if(c == 'e' || c == 'E')
                c = 415;
                else if(c == 'f' || c == 'F')
                c = 415;
                else if(c == 'g' || c == 'G')
                c = 349;
                else if(c == 'h' || c == 'H')
                c = 277;
                else if(c == 'i' || c == 'I')
                c = 349;
                else if(c == 'j' || c == 'J')
                c = 440;
                else if(c == 'k' || c == 'K')
                c = 392;
                else if(c == 'l' || c == 'L')
                c = 261;
                else if(c == 'm' || c == 'M')
                c = 261;
                else if(c == 'n' || c == 'N')
                c = 349;
                else if(c == 'o' || c == 'O')
                c = 493;
                else if(c == 'p' || c == 'P')
                c = 261;
                else if(c == 'q' || c == 'Q')
                c = 261;
                else if(c == 'r' || c == 'R')
                c = 329;
                else if(c == 's' || c == 'S')
                c = 311;
                else if(c == 't' || c == 'T')
                c = 415;
                else if(c == 'u' || c == 'U')
                c = 293;
                else if(c == 'v' || c == 'V')
                c = 415;
                else if(c == 'w' || c == 'W')
                c = 311;
                else if(c == 'x' || c == 'X')
                c = 369;
                else if(c == 'y' || c == 'Y')
                c = 392;
                else if(c == 'z' || c == 'Z')
                c = 392;
                fout << c;
                word = true;
            }
            else if (word) {
                fout<<'\n';
                word = false;
            }
        }
    }
    

    The input string is converted to a char form, and a word per line.

    Then I give the char a number value, and then place the number value into a csv file.

    So instead of the word in the csv file the number values of the word are in the csv file.

    Here is the float number versions;

    a = 466.16
     b = 415.30
     c = 415.30
     d = 415.30
     e = 415.30
     f = 415.30
     g = 349.23
     h = 277.18
     i = 349.23
     j = 440.00
     k = 392.00
     l = 261.63
     m = 261.63
     n = 349.23
     o = 493.88
     p = 261.63
     q = 261.63
     r = 329.63
     s = 311.13
     t = 415.30
     u = 293.66
     v = 415.30
     w = 311.13
     x = 369.99
     y = 392.00
     z = 392.00

    I just made my work in int form, but  I would still like to get the csv output file to have float values instead of int.

    Thank you for replying.

    Saturday, May 12, 2012 6:43 AM
  • "but  I would still like to get the csv output file to have float values instead of int."

    I've no idea what you are trying to do with that code but my guess is that in the float version you're assigning the float value to the 'c' variable and as a result your output doesn't contain float numbers but integers. If that's indeed the case you need to create another variable, say "float f;" assign those float value to 'f' instead of 'c' and the do fout << f; instead of fout << c;

    PS: and you really should be using an array of value to make that code shorter and more readable. That huge if/else can be replaced by an array with 26 values and you can index into the array with some code like "values[tolower(c) - 'a']"
    Saturday, May 12, 2012 7:09 AM
    Moderator
  • brownie ri wrote:
    >
    >Here is my code so far, which work fine.
     
    Your code is silly.  What are you actually trying to accomplish here?  What
    is the goal?
     
    >        if (c == '\'') continue; // skip apostrophe
    >        if (std::isalpha(c)) {
    >            if (word) fout<<',';
     
    Note that "isalpha" will return true if the character is an alphabetic
    letter.  The remaining statements in this loop check for each alphabetic
    letter in turn, and if found, it sets "c" to 1.  There ARE no other
    choices, so you could replace the next 52 statements with
     
                 c = 1;
     
    >            fout << c;
    >            word = true;
     
    And here you write the "1".  What were you expecting?
    --
    Tim Roberts, timr@probo.com
    Providenza & Boekelheide, Inc.
     

    Tim Roberts, VC++ MVP Providenza & Boekelheide, Inc.
    • Marked as answer by brownie ri Saturday, May 12, 2012 8:00 AM
    • Unmarked as answer by brownie ri Saturday, May 12, 2012 8:01 AM
    Saturday, May 12, 2012 7:37 AM
  • So I am now able to write float to my excel csv file. Here is the code;

    #include <iostream>
    #include <fstream>
    #include <cstdlib> // exit()
    #include <cctype>  // isalpha(), tolower()
    
    int main() {
        std::ifstream fin("file_in.txt");
        std::ofstream fout("file_out.csv");
        if (!fin || !fout) { std::cerr<<"file error\n"; std::exit(1); }
        float c;
        bool word = false;
        while ((c = fin.get()) != EOF) {
            if (c == '\'') continue; // skip apostrophe
            if (std::isalpha(c)) {
                if (word) fout<<',';
    
                if(c == 'a' || c == 'A')
                c = 466.16;
                else if(c == 'b' || c == 'B')
                c = 415.30;
                else if(c == 'c' || c == 'C')
                c = 415.30;
                else if(c == 'd' || c == 'D')
                c = 415.30;
                else if(c == 'e' || c == 'E')
                c = 415.30;
                else if(c == 'f' || c == 'F')
                c = 415.30;
                else if(c == 'g' || c == 'G')
                c = 349.23;
                else if(c == 'h' || c == 'H')
                c = 277.18;
                else if(c == 'i' || c == 'I')
                c = 349.23;
                else if(c == 'j' || c == 'J')
                c = 440;
                else if(c == 'k' || c == 'K')
                c = 392;
                else if(c == 'l' || c == 'L')
                c = 261.63;
                else if(c == 'm' || c == 'M')
                c = 261.63;
                else if(c == 'n' || c == 'N')
                c = 349.23;
                else if(c == 'o' || c == 'O')
                c = 493.88;
                else if(c == 'p' || c == 'P')
                c = 261.63;
                else if(c == 'q' || c == 'Q')
                c = 261.63;
                else if(c == 'r' || c == 'R')
                c = 329.63;
                else if(c == 's' || c == 'S')
                c = 311.13;
                else if(c == 't' || c == 'T')
                c = 415.30;
                else if(c == 'u' || c == 'U')
                c = 293.66;
                else if(c == 'v' || c == 'V')
                c = 415.30;
                else if(c == 'w' || c == 'W')
                c = 311.13;
                else if(c == 'x' || c == 'X')
                c = 369.99;
                else if(c == 'y' || c == 'Y')
                c = 392;
                else if(c == 'z' || c == 'Z')
                c = 392;
                fout << c;
                word = true;
            }
            else if (word) {
                fout<<'\n';
                word = false;
            }
        }
    }
    

    I am not writting only the number 1, that was a test to make sure the number was written. The real values for the code are in the code I just posted.

    That isalpha part was there because of the way the code was before I converted the char to number value. But it's doing no harm so I will leave it there.

    I mistakenly marked the answer to the wrong person, but I fixed that.

    Saturday, May 12, 2012 8:05 AM
  • Now that you have a float in your ouptut file, what more do you want?  Your title says something about a percentage but a percentage of what?  Show us a SHORT sample of the input and the desired output.
    Saturday, May 12, 2012 9:45 PM
  • I meant the entire float number, which I now have so no problem to solve, but thank you for replying.
    Sunday, May 13, 2012 5:20 AM
  • Your typedef would have saved you more typing if you had put it in front of readCSV.

    Variable names beginning with an underscore are reserved for the implementation.  You can avoid potential problems by not using them.  (c_ would serve you just as well as _c.)

    Did you not get a diagnostic on the call to fin.get?

    You do realize that almost all of your floating point values cannot be represented exactly?  You are putting them is a csv file which implies you are going to process them in Excel.  Whether Excel will represent these values the same way C++ does (especially the difference between float and double) could have some impact on your subsequent processing.

    Sunday, May 13, 2012 6:43 PM
  • No I do not get a diagnostic on the fin.get, whats a diagnostic?

    <snip>

        if (!fout) { std::cerr<<"file error\n"; std::exit(1); }

    <snip>

    while ((c_ = fin.get()) != EOF) {

                c_ = 466.16;

    When I compile your code I get 17 errors and 53 warnings.  Those are the diagnostics.  They range from errors such as exit not a member of std to the trivial such as imprecise conversion from int or double to float.

     Maybe you should increase the warning level on your project settings. 

    Monday, May 14, 2012 6:44 PM
  • Do you have a question?
    Monday, May 14, 2012 9:55 PM
  • Barry-Schwarz said:

    >When I compile your code I get 17 errors and 53 warnings.

    Using which compiler and version?

    >They range from errors such as exit not a member of std

    See:

    <cstdlib>
    Visual Studio 2010
    http://msdn.microsoft.com/en-us/library/cw48dtx0.aspx

    Excerpt:

    "Including this header also ensures that the names declared
    with external linkage in the Standard C library header are
    declared in the std namespace."

    Also see:

    C standard library
    http://en.wikipedia.org/wiki/C_standard_library

    Excerpts:

    "The C standard library in other languages"

    "... The C++ language, for example, includes the functionality
    of the C standard library in the namespace std (e.g.,
    std::printf, std::atoi, std::feof), in header files with
    similar names to the C ones (cstdio, cmath, cstdlib, etc.)"

    - Wayne
    Monday, May 14, 2012 11:58 PM
  • You keep posting extremelty long programs without any questions.  Why?

    When you do have a question, consider starting a new thread since you are no longer concerned (actually never were) with percentages.

    You might also consider alternatives to your overuse of if-else blocks.  For example, in main your code block

    if(c_ == 'a' || c_ == 'A')
      c_ = 466.16;
    else if(c_ == 'b' || c_ == 'B')
      c_ = 415.30;
    ...


    could be replaced with a much shorter and easier to read

    char letters[] = "abc...z";
    float freqs[] = {466.16, 415.3, ... 392.0};
    char *this_letter;
    int letter_index;
    if ((this_letter = strchr(letters, tolower(c_))) != NULL)
        {
        letter_index = this_letter - letters;
        c_ = freqs[letter_index];
        }

    While you are at it, you might want to consider using different variables for the int and float values of c_.  The automatic conversions require code and consume time.

    An approach similar to the one in main would let you replace A, B, ..., G, aFlat, ..., gFlat with a single routine of less than two dozen statements.

    Tuesday, May 15, 2012 7:50 PM
  • #include <iostream>
    #include <string>
    #include <fstream>
    #include <cstdlib> // exit()
    #include <cctype>  // isalpha(), tolower()
    #include <sstream>
    #include <vector>
    #include <map>
    #include <windows.h>
    
    using namespace std;
    
    // 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 () {
    		const unsigned int kuiNoteCount = mqNotes.size();
    		std::vector<CNote>::iterator qIter;
    		for (qIter = mqNotes.begin(); qIter != mqNotes.end(); ++qIter) {
    			qIter->Play();
    		}
    	}
    	std::vector<CNote> mqNotes;
    };
    
    // This is used to count the number of times a word is used
    class WordCounter
     {
     public:
     int value;
     WordCounter() : value( 0 ) {}
    
     void operator++ (int) { value++; }
     };
    
     ostream& operator<<(ostream& st, WordCounter& wc )
     {
     return st << wc.value;
     }
    
    
    // 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:";
    string gF2 = "A_gFlat_part_1_AND_red:";
    string gF3 = "A_gFlat_part_1_AND_cyan:";
    string gF4 = "A_gFlat_part_1_AND_red:";
    string gF5 = "A_gFlat_part_2_AND_green:";
    string gF6 = "A_gFlat_part_2_AND_red:";
    string gF7 = "A_gFlat_part_3_XOR_red:";
    string gF8 = "A_gFlat_part_4_OR_cyan:";
    string gF9 = "A_gFlat_part_4_OR_red:";
    
    string dF1 = "B_dFlat_part_1_AND_red:";
    string dF2 = "B_dFlat_part_1_AND_blue:";
    string dF3 = "B_dFlat_part_1_AND_red:";
    string dF4 = "B_dFlat_part_1_AND_cyan:";
    string dF5 = "B_dFlat_part_2_AND_red:";
    string dF6 = "B_dFlat_part_2_AND_cyan:";
    string dF7 = "B_dFlat_part_3_XOR_blue:";
    string dF8 = "B_dFlat_part_4_OR_red:";
    string dF9 = "B_dFlat_part_4_OR_cyan:";
    
    string aF1 = "C_aFlat_part_1_AND_cyan:";
    string aF2 = "C_aFlat_part_1_AND_yellow:";
    string aF3 = "C_aFlat_part_1_AND_blue:";
    string aF4 = "C_aFlat_part_1_AND_red:";
    string aF5 = "C_aFlat_part_2_AND_cyan:";
    string aF6 = "C_aFlat_part_2_AND_red:";
    string aF7 = "C_aFlat_part_3_XOR_yellow:";
    string aF8 = "C_aFlat_part_4_OR_blue:";
    string aF9 = "C_aFlat_part_4_OR_red:";
    
    string eF1 = "D_eFlat_part_1_AND_red:";
    string eF2 = "D_eFlat_part_1_AND_red:";
    string eF3 = "D_eFlat_part_1_AND_yellow:";
    string eF4 = "D_eFlat_part_1_AND_blue:";
    string eF5 = "D_eFlat_part_2_AND_red:";
    string eF6 = "D_eFlat_part_2_AND_blue:";
    string eF7 = "D_eFlat_part_3_XOR_red:";
    string eF8 = "D_eFlat_part_4_OR_yellow:";
    string eF9 = "D_eFlat_part_4_OR_blue:";
    
    string bF1 = "E_bFlat_part_1_AND_blue:";
    string bF2 = "E_bFlat_part_1_AND_green:";
    string bF3 = "E_bFlat_part_1_AND_red:";
    string bF4 = "E_bFlat_part_1_AND_yellow:";
    string bF5 = "E_bFlat_part_2_AND_blue:";
    string bF6 = "E_bFlat_part_2_AND_yellow:";
    string bF7 = "E_bFlat_part_3_XOR_green:";
    string bF8 = "E_bFlat_part_4_OR_red:";
    string bF9 = "E_bFlat_part_4_OR_yellow:";
    
    string F1 = "F_part_1_AND_yellow:";
    string F2 = "F_part_1_AND_red:";
    string F3 = "F_part_1_AND_green:";
    string F4 = "F_part_1_AND_red:";
    string F5 = "F_part_2_AND_yellow:";
    string F6 = "F_part_2_AND_red:";
    string F7 = "F_part_3_XOR_red:";
    string F8 = "F_part_4_OR_green:";
    string F9 = "F_part_4_OR_red:";
    
    string C1 = "G_C_part_1_AND_red:";
    string C2 = "G_C_part_1_AND_blue:";
    string C3 = "G_C_part_1_AND_red:";
    string C4 = "G_C_part_1_AND_green:";
    string C5 = "G_C_part_2_AND_red:";
    string C6 = "G_C_part_2_AND_green:";
    string C7 = "G_C_part_3_XOR_blue:";
    string C8 = "G_C_part_4_OR_red:";
    string C9 = "G_C_part_4_OR_green:";
    
    string G1 = "H_G_part_1_AND_green:";
    string G2 = "H_G_part_1_AND_orange:";
    string G3 = "H_G_part_1_AND_blue:";
    string G4 = "H_G_part_1_AND_red:";
    string G5 = "H_G_part_2_AND_green:";
    string G6 = "H_G_part_2_AND_red:";
    string G7 = "H_G_part_3_XOR_orange:";
    string G8 = "H_G_part_4_OR_blue:";
    string G9 = "H_G_part_4_OR_red:";
    
    string D1 = "I_part_1_AND_red:";
    string D2 = "I_part_1_AND_violet:";
    string D3 = "I_part_1_AND_orange:";
    string D4 = "I_part_1_AND_blue:";
    string D5 = "I_part_2_AND_red:";
    string D6 = "I_part_2_AND_blue:";
    string D7 = "I_part_3_XOR_violet:";
    string D8 = "I_part_4_OR_orange:";
    string D9 = "I_part_4_OR_blue:";
    
    string A1 = "J_A_part_1_AND_blue:";
    string A2 = "J_A_part_1_AND_green:";
    string A3 = "J_A_part_1_AND_violet:";
    string A4 = "J_A_part_1_AND_orange:";
    string A5 = "J_A_part_2_AND_blue:";
    string A6 = "J_A_part_2_AND_orange:";
    string A7 = "J_A_part_3_XOR_green:";
    string A8 = "J_A_part_4_OR_violet:";
    string A9 = "J_A_part_4_OR_orange:";
    
    string E1 = "K_E_part_1_AND_orange:";
    string E2 = "K_E_part_1_AND_red:";
    string E3 = "K_E_part_1_AND_green:";
    string E4 = "K_E_part_1_AND_violet:";
    string E5 = "K_E_part_2_AND_orange:";
    string E6 = "K_E_part_2_AND_violet:";
    string E7 = "K_E_part_3_XOR_red:";
    string E8 = "K_E_part_4_OR_green:";
    string E9 = "K_E_part_4_OR_violet:";
    
    string B1 = "L_B_part_1_AND_violet:";
    string B2 = "L_B_part_1_AND_cyan:";
    string B3 = "L_B_part_1_AND_red:";
    string B4 = "L_B_part_1_AND_green:";
    string B5 = "L_B_part_2_AND_violet:";
    string B6 = "L_B_part_2_AND_green:";
    string B7 = "L_B_part_3_XOR_cyan:";
    string B8 = "L_B_part_4_OR_red:";
    string B9 = "L_B_part_4_OR_green:";
    
    
    int wordCount = 1;
    
    // This plays the sound
    
    void playSound(std::string note){
        CMelody songSound;
    
        if(note == gF1 ){
            songSound.AddNote(keFS, ke8th); // compare chord x
    
            cout << "+    right" << endl;
        }
        if(note == gF2){
            songSound.AddNote(keDS, ke8th + ke16th); // compare chord s
    
            cout << "+    up" << endl;
        }
        if(note == gF3){
            songSound.AddNote(keGS, ke16th); // compare chord b
    
            cout << "+    straight" << endl;
        }
        if(note == gF4){
            songSound.AddNote(keCS, ke8th + ke16th); // compare chord h
    
            cout << "+    up" << endl;
        }
        if(note == gF5){
            songSound.AddNote(keFS, ke8th); // compare chord x
    
            cout << "+    right" << endl;
        }
        if(note == gF6){
            songSound.AddNote(keCS, ke8th + ke16th); // compare chord h
    
            cout << "+    up" << endl;
        }
        if(note == gF7){
            songSound.AddNote(keDS, ke8th + ke16th); // compare chord s
    
            cout << "+    up" << endl;
        }
        if(note == gF8){
            songSound.AddNote(keGS, ke16th); // compare chord b
    
            cout << "+    straight" << endl;
        }
        if(note == gF9){
            songSound.AddNote(keCS, ke8th + ke16th); // compare chord h
    
            cout << "+    up" << endl;
        }
        //////////////////////////////////////////////////////////
        //////////////////////////////////////////////////////////
    
        if(note == dF1){
            songSound.AddNote(keCS, ke8th + ke16th); // compare chord h
    
            cout << "+    up" << endl;
        }
        if(note == dF2){
            songSound.AddNote(keAS, ke16th); // compare chord a
    
            cout << "-    left" << endl;
        }
        if(note == dF3){
            songSound.AddNote(keDS, ke8th + ke16th); // compare chord s
    
            cout << "+    up" << endl;
        }
        if(note == dF4){
            songSound.AddNote(keGS, ke16th); // compare chord b
    
            cout << "+    straight" << endl;
        }
        if(note == dF5){
            songSound.AddNote(keCS, ke8th + ke16th); // compare chord h
    
            cout << "+    up" << endl;
        }
        if(note == dF6){
            songSound.AddNote(keGS, ke16th); // compare chord b
    
            cout << "+    straight" << endl;
        }
        if(note == dF7){
            songSound.AddNote(keAS, ke16th); // compare chord a
    
            cout << "-    left" << endl;
        }
        if(note == dF8){
            songSound.AddNote(keDS, ke8th + ke16th); // compare chord s
    
            cout << "+    up" << endl;
        }
        if(note == dF9){
            songSound.AddNote(keGS, ke16th); // compare chord b
    
            cout << "+    straight" << endl;
        }
        //////////////////////////////////////////////////////////
        //////////////////////////////////////////////////////////
    
        if(note == aF1){
            songSound.AddNote(keGS, ke16th); // compare chord b
    
            cout << "+    straight" << endl;
        }
        if(note == aF2){
            songSound.AddNote(keF, ke8th); // compare chord g
    
            cout << "-    down" << endl;
        }
        if(note == aF3){
            songSound.AddNote(keAS, ke16th); // compare chord a
    
            cout << "-    left" << endl;
        }
        if(note == aF4){
            songSound.AddNote(keDS, ke8th + ke16th); // compare chord s
    
            cout << "+    up" << endl;
        }
        if(note == aF5){
            songSound.AddNote(keGS, ke16th); // compare chord b
    
            cout << "+    straight" << endl;
        }
        if(note == aF6){
            songSound.AddNote(keDS, ke8th + ke16th); // compare chord s
    
            cout << "+    up" << endl;
        }
        if(note == aF7){
            songSound.AddNote(keF, ke8th); // compare chord g
    
            cout << "-    down" << endl;
        }
        if(note == aF8){
            songSound.AddNote(keAS, ke16th); // compare chord a
    
            cout << "-    left" << endl;
        }
        if(note == aF9){
            songSound.AddNote(keDS, ke8th + ke16th); // compare chord s
    
            cout << "+    up" << endl;
        }
        //////////////////////////////////////////////////////////
        //////////////////////////////////////////////////////////
    
        if(note == eF1){
            songSound.AddNote(keDS, ke8th + ke16th); // compare chord s
    
            cout << "+    up" << endl;
        }
        if(note == eF2){
            songSound.AddNote(keC, ke8th + ke16th); // compare chord l
    
            cout << "+    up" << endl;
        }
        if(note == eF3){
            songSound.AddNote(keF, ke8th); // compare chord g
    
            cout << "-    down" << endl;
        }
        if(note == eF4){
            songSound.AddNote(keAS, ke16th); // compare chord a
    
            cout << "-    left" << endl;
        }
        if(note == eF5){
            songSound.AddNote(keDS, ke8th + ke16th); // compare chord s
    
            cout << "+    up" << endl;
        }
        if(note == eF6){
            songSound.AddNote(keAS, ke16th); // compare chord a
    
            cout << "-    left" << endl;
        }
        if(note == eF7){
            songSound.AddNote(keC, ke8th + ke16th); // compare chord l
    
            cout << "+    up" << endl;
        }
        if(note == eF8){
            songSound.AddNote(keF, ke8th); // compare chord g
    
            cout << "-    down" << endl;
        }
        if(note == eF9){
            songSound.AddNote(keAS, ke16th); // compare chord a
    
            cout << "-    left" << endl;
        }
        //////////////////////////////////////////////////////////
        //////////////////////////////////////////////////////////
    
        if(note == bF1){
            songSound.AddNote(keAS, ke16th); // compare chord a
    
            cout << "-    left" << endl;
        }
        if(note == bF2){
            songSound.AddNote(keG, ke8th); // compare chord k
    
            cout << "+    right" << endl;
        }
        if(note == bF3){
            songSound.AddNote(keC, ke8th + ke16th); // compare chord l
    
            cout << "+    up" << endl;
        }
        if(note == bF4){
            songSound.AddNote(keF, ke8th); // compare chord g
    
            cout << "-    down" << endl;
        }
        if(note == bF5){
            songSound.AddNote(keAS, ke16th); // compare chord a
    
            cout << "-    left" << endl;
        }
        if(note == bF6){
            songSound.AddNote(keF, ke8th); // compare chord g
    
            cout << "-    down" << endl;
        }
        if(note == bF7){
            songSound.AddNote(keG, ke8th); // compare chord k
    
            cout << "+    right" << endl;
        }
        if(note == bF8){
            songSound.AddNote(keC, ke8th + ke16th); // compare chord l
    
            cout << "+    up" << endl;
        }
        if(note == bF9){
            songSound.AddNote(keF, ke8th); // compare chord g
    
            cout << "-    down" << endl;
        }
        //////////////////////////////////////////////////////////
        //////////////////////////////////////////////////////////
    
        if(note == F1){
            songSound.AddNote(keF, ke8th); // compare chord g
    
            cout << "-    down" << endl;
        }
        if(note == F2){
            songSound.AddNote(keD, ke8th + ke16th); // compare chord u
    
            cout << "+    up" << endl;
        }
        if(note == F3){
            songSound.AddNote(keG, ke8th); // compare chord k
    
            cout << "+    right" << endl;
        }
        if(note == F4){
            songSound.AddNote(keC, ke8th + ke16th); // compare chord l
    
            cout << "+    up" << endl;
        }
        if(note == F5){
            songSound.AddNote(keF, ke8th); // compare chord g
    
            cout << "-    down" << endl;
        }
        if(note == F6){
            songSound.AddNote(keC, ke8th + ke16th); // compare chord l
    
            cout << "+    up" << endl;
        }
        if(note == F7){
            songSound.AddNote(keD, ke8th + ke16th); // compare chord u
    
            cout << "+    up" << endl;
        }
        if(note == F8){
            songSound.AddNote(keG, ke8th); // compare chord k
    
            cout << "+    right" << endl;
        }
        if(note == F9){
            songSound.AddNote(keC, ke8th + ke16th); // compare chord l
    
            cout << "+    up" << endl;
        }
        //////////////////////////////////////////////////////////
        //////////////////////////////////////////////////////////
    
        if(note == C1){
            songSound.AddNote(keC, ke8th + ke16th); // compare chord l
    
            cout << "+    up" << endl;
        }
        if(note == C2){
            songSound.AddNote(keA, ke16th); // compare chord j
    
            cout << "-    left" << endl;
        }
        if(note == C3){
            songSound.AddNote(keD, ke8th + ke16th); // compare chord u
    
            cout << "+    up" << endl;
        }
        if(note == C4){
            songSound.AddNote(keG, ke8th); // compare chord k
    
            cout << "+    right" << endl;
        }
        if(note == C5){
            songSound.AddNote(keC, ke8th + ke16th); // compare chord l
    
            cout << "+    up" << endl;
        }
        if(note == C6){
            songSound.AddNote(keG, ke8th); // compare chord k
    
            cout << "+    right" << endl;
        }
        if(note == C7){
            songSound.AddNote(keA, ke16th); // compare chord j
    
            cout << "-    left" << endl;
        }
        if(note == C8){
            songSound.AddNote(keD, ke8th + ke16th); // compare chord u
    
            cout << "+    up" << endl;
        }
        if(note == C9){
            songSound.AddNote(keG, ke8th); // compare chord k
    
            cout << "+    right" << endl;
        }
        //////////////////////////////////////////////////////////
        //////////////////////////////////////////////////////////
    
        if(note == G1){
            songSound.AddNote(keG, ke8th); // compare chord k
    
            cout << "+    right" << endl;
        }
        if(note == G2){
            songSound.AddNote(keE, ke8th + ke16th); // compare chord r
    
            cout << "+-   up and down" << endl;
        }
        if(note == G3){
            songSound.AddNote(keA, ke16th); // compare chord j
    
            cout << "-    left" << endl;
        }
        if(note == G4){
            songSound.AddNote(keD, ke8th + ke16th); // compare chord u
    
            cout << "+    up" << endl;
        }
        if(note == G5){
            songSound.AddNote(keG, ke8th); // compare chord k
    
            cout << "+    right" << endl;
        }
        if(note == G6){
            songSound.AddNote(keD, ke8th + ke16th); // compare chord u
    
            cout << "+    up" << endl;
        }
        if(note == G7){
            songSound.AddNote(keE, ke8th + ke16th); // compare chord r
    
            cout << "+_    up and down" << endl;
        }
        if(note == G8){
            songSound.AddNote(keA, ke16th); // compare chord j
    
            cout << "-    left" << endl;
        }
        if(note == G9){
            songSound.AddNote(keD, ke8th + ke16th); // compare chord u
    
            cout << "+    up" << endl;
        }
        //////////////////////////////////////////////////////////
        //////////////////////////////////////////////////////////
    
        if(note == D1){
            songSound.AddNote(keD, ke8th + ke16th); // compare chord u
    
            cout << "+    up" << endl;
        }
        if(note == D2){
            songSound.AddNote(keRest, ke16th); // compare chord o
    
            cout << "-    around" << endl;
        }
        if(note == D3){
            songSound.AddNote(keE, ke8th + ke16th); // compare chord r
    
            cout << "+-   up and down" << endl;
        }
        if(note == D4){
            songSound.AddNote(keA, ke16th); // compare chord j
    
            cout << "-    left" << endl;
        }
        if(note == D5){
            songSound.AddNote(keD, ke8th + ke16th); // compare chord u
    
            cout << "+    up" << endl;
        }
        if(note == D6){
            songSound.AddNote(keA, ke16th); // compare chord j
    
            cout << "-    left" << endl;
        }
        if(note == D7){
            songSound.AddNote(keRest, ke16th); // compare chord o
    
            cout << "-    around" << endl;
        }
        if(note == D8){
            songSound.AddNote(keE, ke8th + ke16th); // compare chord r
    
            cout << "+-   up and down" << endl;
        }
        if(note == D9){
            songSound.AddNote(keA, ke16th); // compare chord j
    
            cout << "-    left" << endl;
        }
        //////////////////////////////////////////////////////////
        //////////////////////////////////////////////////////////
    
        if(note == A1){
            songSound.AddNote(keA, ke16th); // compare chord j
    
            cout << "-    left" << endl;
        }
        if(note == A2){
            songSound.AddNote(keFS, ke8th); // compare chord x
    
            cout << "+    right" << endl;
        }
        if(note == A3){
            songSound.AddNote(keRest, ke16th); // compare chord o
    
            cout << "-    around" << endl;
        }
        if(note == A4){
            songSound.AddNote(keE, ke8th + ke16th); // compare chord r
    
            cout << "+-   up and down" << endl;
        }
        if(note == A5){
            songSound.AddNote(keA, ke16th); // compare chord j
    
            cout << "-    left" << endl;
        }
        if(note == A6){
            songSound.AddNote(keE, ke8th + ke16th); // compare chord r
    
            cout << "+-   up and down" << endl;
        }
        if(note == A7){
            songSound.AddNote(keFS, ke8th); // compare chord x
    
            cout << "+    right" << endl;
        }
        if(note == A8){
            songSound.AddNote(keRest, ke16th); // compare chord o
    
            cout << "-    around" << endl;
        }
        if(note == A9){
            songSound.AddNote(keE, ke8th + ke16th); // compare chord r
    
            cout << "+-   up and down" << endl;
        }
        //////////////////////////////////////////////////////////
        //////////////////////////////////////////////////////////
    
        if(note == E1){
            songSound.AddNote(keE, ke8th + ke16th); // compare chord r
    
            cout << "+-   up and down" << endl;
        }
        if(note == E2){
            songSound.AddNote(keCS, ke8th + ke16th); // compare chord h
    
            cout << "+    up" << endl;
        }
        if(note == E3){
            songSound.AddNote(keFS, ke8th); // compare chord x
    
            cout << "+    right" << endl;
        }
        if(note == E4){
            songSound.AddNote(keRest, ke16th); // compare chord o
    
            cout << "-    around" << endl;
        }
        if(note == E5){
            songSound.AddNote(keE, ke8th + ke16th); // compare chord r
    
            cout << "+-   up and down" << endl;
        }
        if(note == E6){
            songSound.AddNote(keRest, ke16th); // compare chord o
    
            cout << "-    around" << endl;
        }
        if(note == E7){
            songSound.AddNote(keCS, ke8th + ke16th); // compare chord h
    
            cout << "+    up" << endl;
        }
        if(note == E8){
            songSound.AddNote(keFS, ke8th); // compare chord x
    
            cout << "+    right" << endl;
        }
        if(note == E9){
            songSound.AddNote(keRest, ke16th); // compare chord o
    
            cout << "-    around" << endl;
        }
        //////////////////////////////////////////////////////////
        //////////////////////////////////////////////////////////
    
        if(note == B1){
            songSound.AddNote(keRest, ke16th); // compare chord o
    
            cout << "-    around" << endl;
        }
        if(note == B2){
            songSound.AddNote(keGS, ke16th); // compare chord b
    
            cout << "+    straight" << endl;
        }
        if(note == B3){
            songSound.AddNote(keCS, ke8th + ke16th); // compare chord h
    
            cout << "+    up" << endl;
        }
        if(note == B4){
            songSound.AddNote(keFS, ke8th); // compare chord x
    
            cout << "+    right" << endl;
        }
        if(note == B5){
            songSound.AddNote(keRest, ke16th); // compare chord o
    
            cout << "-    around" << endl;
        }
        if(note == B6){
            songSound.AddNote(keFS, ke8th); // compare chord x
    
            cout << "+    right" << endl;
        }
        if(note == B7){
            songSound.AddNote(keGS, ke16th); // compare chord b
    
            cout << "+    straight" << endl;
        }
        if(note == B8){
            songSound.AddNote(keCS, ke8th + ke16th); // compare chord h
    
            cout << "+    up" << endl;
        }
        if(note == B9){
            songSound.AddNote(keFS, ke8th); // compare chord x
    
            cout << "+    right" << endl;
        }
    
        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 << " ";
    
        if(letterNumber == 2 && frequency == s)
            fout << gF2 << " ";
    
        if(letterNumber == 3 && frequency == b)
            fout << gF3 << " ";
    
        if(letterNumber == 4 && frequency == h)
            fout << gF4 << " ";
    
        if(letterNumber == 5 && frequency == x)
            fout << gF5 << " ";
    
        if(letterNumber == 6 && frequency == h)
            fout << gF6 << " ";
    
        if(letterNumber == 7 && frequency == s)
            fout << gF7 << " ";
    
        if(letterNumber == 8 && frequency == b)
            fout << gF8 << " ";
    
        if(letterNumber == 9 && frequency == h)
            fout << gF9 << " ";
    
        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 << " ";
    
        if(letterNumber == 2 && frequency == a)
            fout << dF2 << " ";
    
        if(letterNumber == 3 && frequency == s)
            fout << dF3 << " ";
    
        if(letterNumber == 4 && frequency == b)
            fout << dF4 << " ";
    
        if(letterNumber == 5 && frequency == h)
            fout << dF5 << " ";
    
        if(letterNumber == 6 && frequency == b)
            fout << dF6 << " ";
    
        if(letterNumber == 7 && frequency == a)
            fout << dF7 << " ";
    
        if(letterNumber == 8 && frequency == s)
            fout << dF8 << " ";
    
        if(letterNumber == 9 && frequency == b)
            fout << dF9 << " ";
    
        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 << " ";
    
        if(letterNumber == 2 && frequency == g)
            fout << aF2 << " ";
    
        if(letterNumber == 3 && frequency == a)
            fout << aF3 << " ";
    
        if(letterNumber == 4 && frequency == s)
            fout << aF4 << " ";
    
        if(letterNumber == 5 && frequency == b)
            fout << aF5 << " ";
    
        if(letterNumber == 6 && frequency == s)
            fout << aF6 << " ";
    
        if(letterNumber == 7 && frequency == g)
            fout << aF7 << " ";
    
        if(letterNumber == 8 && frequency == a)
            fout << aF8 << " ";
    
        if(letterNumber == 9 && frequency == s)
            fout << aF9 << " ";
    
        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 << " ";
    
        if(letterNumber == 2 && frequency == l)
            fout << eF2 << " ";
    
        if(letterNumber == 3 && frequency == g)
            fout << eF3 << " ";
    
        if(letterNumber == 4 && frequency == a)
            fout << eF4 << " ";
    
        if(letterNumber == 5 && frequency == s)
            fout << eF5 << " ";
    
        if(letterNumber == 6 && frequency == a)
            fout << eF6 << " ";
    
        if(letterNumber == 7 && frequency == l)
            fout << eF7 << " ";
    
        if(letterNumber == 8 && frequency == g)
            fout << eF8 << " ";
    
        if(letterNumber == 9 && frequency == a)
            fout << eF9 << " ";
    
        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 << " ";
    
        if(letterNumber == 2 && frequency == k)
            fout << bF2 << " ";
    
        if(letterNumber == 3 && frequency == l)
            fout << bF3 << " ";
    
        if(letterNumber == 4 && frequency == g)
            fout << bF4 << " ";
    
        if(letterNumber == 5 && frequency == a)
            fout << bF5 << " ";
    
        if(letterNumber == 6 && frequency == g)
            fout << bF6 << " ";
    
        if(letterNumber == 7 && frequency == k)
            fout << bF7 << " ";
    
        if(letterNumber == 8 && frequency == l)
            fout << bF8 << " ";
    
        if(letterNumber == 9 && frequency == g)
            fout << bF9 << " ";
    
        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 << " ";
    
        if(letterNumber == 2 && frequency == u)
            fout << F2 << " ";
    
        if(letterNumber == 3 && frequency == k)
            fout << F3 << " ";
    
        if(letterNumber == 4 && frequency == l)
            fout << F4 << " ";
    
        if(letterNumber == 5 && frequency == g)
            fout << F5 << " ";
    
        if(letterNumber == 6 && frequency == l)
            fout << F6 << " ";
    
        if(letterNumber == 7 && frequency == u)
            fout << F7 << " ";
    
        if(letterNumber == 8 && frequency == k)
            fout << F8 << " ";
    
        if(letterNumber == 9 && frequency == l)
            fout << F9 << " ";
    
        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 << " ";
    
        if(letterNumber == 2 && frequency == j)
            fout << C2 << " ";
    
        if(letterNumber == 3 && frequency == u)
            fout << C3 << " ";
    
        if(letterNumber == 4 && frequency == k)
            fout << C4 << " ";
    
        if(letterNumber == 5 && frequency == l)
            fout << C5 << " ";
    
        if(letterNumber == 6 && frequency == k)
            fout << C6 << " ";
    
        if(letterNumber == 7 && frequency == j)
            fout << C7 << " ";
    
        if(letterNumber == 8 && frequency == u)
            fout << C8 << " ";
    
        if(letterNumber == 9 && frequency == k)
            fout << C9 << " ";
    
        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 << " ";
    
        if(letterNumber == 2 && frequency == r)
            fout << G2 << " ";
    
        if(letterNumber == 3 && frequency == j)
            fout << G3 << " ";
    
        if(letterNumber == 4 && frequency == u)
            fout << G4 << " ";
    
        if(letterNumber == 5 && frequency == k)
            fout << G5 << " ";
    
        if(letterNumber == 6 && frequency == u)
            fout << G6 << " ";
    
        if(letterNumber == 7 && frequency == r)
            fout << G7 << " ";
    
        if(letterNumber == 8 && frequency == j)
            fout << G8 << " ";
    
        if(letterNumber == 9 && frequency == u)
            fout << G9 << " ";
    
        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 << " ";
    
        if(letterNumber == 2 && frequency == o)
            fout << D2 << " ";
    
        if(letterNumber == 3 && frequency == r)
            fout << D3 << " ";
    
        if(letterNumber == 4 && frequency == j)
            fout << D4 << " ";
    
        if(letterNumber == 5 && frequency == u)
            fout << D5 << " ";
    
        if(letterNumber == 6 && frequency == j)
            fout << D6 << " ";
    
        if(letterNumber == 7 && frequency == o)
            fout << D7 << " ";
    
        if(letterNumber == 8 && frequency == r)
            fout << D8 << " ";
    
        if(letterNumber == 9 && frequency == j)
            fout << D9 << " ";
    
        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 << " ";
    
        if(letterNumber == 2 && frequency == x)
            fout << A2 << " ";
    
        if(letterNumber == 3 && frequency == o)
            fout << A3 << " ";
    
        if(letterNumber == 4 && frequency == r)
            fout << A4 << " ";
    
        if(letterNumber == 5 && frequency == j)
            fout << A5 << " ";
    
        if(letterNumber == 6 && frequency == r)
            fout << A6 << " ";
    
        if(letterNumber == 7 && frequency == x)
            fout << A7 << " ";
    
        if(letterNumber == 8 && frequency == o)
            fout << A8 << " ";
    
        if(letterNumber == 9 && frequency == r)
            fout << A9 << " ";
    
        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 << " ";
    
        if(letterNumber == 2 && frequency == h)
            fout << E2 << " ";
    
        if(letterNumber == 3 && frequency == x)
            fout << E3 << " ";
    
        if(letterNumber == 4 && frequency == o)
            fout << E4 << " ";
    
        if(letterNumber == 5 && frequency == r)
            fout << E5 << " ";
    
        if(letterNumber == 6 && frequency == o)
            fout << E6 << " ";
    
        if(letterNumber == 7 && frequency == h)
            fout << E7 << " ";
    
        if(letterNumber == 8 && frequency == x)
            fout << E8 << " ";
    
        if(letterNumber == 9 && frequency == o)
            fout << E9 << " ";
    
        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 << " ";
    
        if(letterNumber == 2 && frequency == b)
            fout << B2 << " ";
    
        if(letterNumber == 3 && frequency == h)
            fout << B3 << " ";
    
        if(letterNumber == 4 && frequency == x)
            fout << B4 << " ";
    
        if(letterNumber == 5 && frequency == o)
            fout << B5 << " ";
    
        if(letterNumber == 6 && frequency == x)
            fout << B6 << " ";
    
        if(letterNumber == 7 && frequency == b)
            fout << B7 << " ";
    
        if(letterNumber == 8 && frequency == h)
            fout << B8 << " ";
    
        if(letterNumber == 9 && frequency == x)
            fout << B9 << " ";
    
        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);
    	}
    }
    
    int main() {
        // I open then close the file to erase the previous text
        std::ofstream pattern("pattern_file_out.txt");
        std::ofstream pattern_out("pattern_file_out_2.txt");
        pattern_out.close();
        pattern.close();
    
        // I open the text and write the results to the csv file
        std::ifstream fin("file_in.txt");
        std::ofstream fout("file_out.csv");
        if (!fin || !fout) { std::cerr<<"file error\n"; std::exit(1); }
        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;
    
        while ((c_ = fin.get()) != EOF) {
            if (c_ == '\'') continue; // skip apostrophe
            if (std::isalpha(c_)) {
                if (word) fout<<',';
    
                if ((this_letter = strchr(letters, tolower(c_))) != NULL){
                    letter_index = this_letter - letters;
                    c_ = freqs[letter_index];
                }
                fout << c_;
                word = true;
            }
            else if (word) {
                fout<<'\n';
                word = false;
            }
        }
        fout.close();
    
        // 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);
    		}
    
    		wordCount++;
    		itemnum = 0;
    
    		// I open the pattern file and add a newline, so the text is easier to read
    		std::ofstream pattern_("pattern_file_out.txt", fstream::app);
    
    		if (!pattern_) { std::cerr<<"file error\n"; std::exit(1); }
    
    		pattern << endl << endl;
    
    		// Now that there is a newline I close the files
    		pattern_.close();
    
    	}
    	// I close the csv file
    	file.close();
    
        // Now I count the number of times a word appears in the pattern file and write the results in the file.
    	map<string, WordCounter> counter;
    
    	std::ifstream input("pattern_file_out.txt");
    	std::ofstream pattern_out_2("pattern_file_out_2.txt");
    	if (!input|| !pattern_out_2) { std::cerr<<"file error\n"; std::exit(1); }
    
    	    string tok;
    	    while ( true ) {
    	        input >> tok;
    	        if ( input ) {
    	            counter[ tok ]++;
                }
                else break;
            }
    
            map<string, WordCounter,less<string> >::iterator it;
            for ( it = counter.begin(); it != counter.end(); it++ ) {
                pattern_out_2 << (*it).first << endl;
            }
    
            pattern_out_2.close();
    
            cout << endl << endl << "The rules" << endl << endl;
            cout << "Y axis = up, up and down, down" <<
            endl << "X axis = right, left"<<
            endl << "Z axis = straight, around" <<
            endl << endl;
            cout << "The game starts by dropping a coin on top of the first Venn result, \nto the last Venn result." << endl << endl ;
            cout << "If the odds for winning are good, \nthe design of words \"up\" etc are grouped together and orderly." << endl << endl;
            cout << "If the odds of winning are bad, \nthe list of words will not be grouped together or orderly." << endl << endl;
            cout << "Put in some songs or words and watch as the list starts out orderly and grouped," <<
            endl << "but towards the end of the list the words are not grouped together or orderly." << endl << endl;
            cout << "_______________________________________________________________________________" << endl << endl;
            // Now I take the text and make it into a sound
    
            std::ifstream input_2("pattern_file_out_2.txt");
            if (!input_2) { std::cerr<<"file error\n"; std::exit(1); }
    
            vector<string> text_file;
            string temp;
            int loopCounter = 0;
            while( getline( input_2, temp) ){
                string note;
                note = temp;
    
                if(loopCounter == 2){
                playSound(note);
                loopCounter = 0;
                }
                loopCounter++;
                text_file.push_back( temp );
            }
            cout << endl << endl;
            input_2.close();
    
    
            // I pause the console window so you can read the screen results
            system ("pause");
    
            return 0;
    }
    

    • Edited by brownie ri Saturday, May 19, 2012 8:29 AM new version
    Wednesday, May 16, 2012 7:36 AM