{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Project 3 Solution

Project 3 Solution - Project 3 Guitar Zero#include ...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
// Project 3: Guitar Zero #include <string> using namespace std; const char END_OF_BEAT = '/'; //************************************* // isSongWellFormed //************************************* bool isSongWellFormed(string song) { // An empty song is well-formed. if (song.size() == 0) return true; // A non-empty song must end with an end-of-beat marker. if (song.at(song.size()-1) != END_OF_BEAT) return false; // At this point, we know the song ends properly, so in the following // loop, we do not have to worry about, say, there not being a character // following a digit. // Each iteration of the loop recognizes one beat. size_t k = 0; while (k != song.size()) { // The beat may have no note. if (song.at(k) == END_OF_BEAT) { k++; continue; }
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
// There might be a note that starts with a digit. if (isdigit(song.at(k))) { k++; // There might be a second digit. if (isdigit(song.at(k))) k++; } // Verify color letter. char color = tolower(song.at(k)); if (color != 'g' && color != 'r' && color != 'y' && color != 'b' && color != 'o') return false; k++; // Verify end of beat. if (song.at(k) != END_OF_BEAT) return false; k++; } // We get here if we got through the song without a problem.
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}