Question: CODE IS IN C++ Please use code attached and update areas with classes and only use arrays please. Right after the first if statement inside
CODE IS IN C++
Please use code attached and update areas with "classes" and only use arrays please. Right after the first if statement inside the bool has the first class and they're called throughout the program. These need to be updated to arrays or strings or char. Thank you!
#include
#include
#include
using namespace std;
const char ENDOFBEAT = '/';
bool Syntax(string song)
{
if (song.size() == 0)
return true;
if (song.at(song.size() - 1) != ENDOFBEAT)
return false;
size_t k = 0;
while (k != song.size())
{
if (song.at(k) == ENDOFBEAT)
{
k++;
continue;
}
if (isdigit(song.at(k)))
{
k++;
if (isdigit(song.at(k)))
k++;
}
char color = tolower(song.at(k));
if (color != 'g' && color != 'r' && color != 'y' &&
color != 'b' && color != 'o')
return false;
k++;
if (song.at(k) != ENDOFBEAT)
return false;
k++;
}
return true;
}
int tSong(string song, string& instructions, int& badBeat)
{
const int RETOK = 0;
const int RETNOTWELLFORMED = 1;
const int RETSUSTAINEDINTERRUPTED = 2;
const int RETPREMATUREEND = 3;
const int RETBADSUSTAINEDLENGTH = 4;
if (!Syntax(song))
return RETNOTWELLFORMED;
string result;
int sustainedRemaining = 0;
char sustainedColor;
int beatNumber;
size_t k = 0;
for (beatNumber = 1; k != song.size(); beatNumber++)
{
if (song.at(k) == ENDOFBEAT)
{
if (sustainedRemaining > 0)
{
// Continue with sustained note
result += sustainedColor;
sustainedRemaining--;
}
else
result += 'x';
k++;
continue;
}
if (sustainedRemaining > 0)
{
badBeat = beatNumber;
return RETSUSTAINEDINTERRUPTED;
}
if (isdigit(song.at(k)))
{
sustainedRemaining = song.at(k) - '0';
k++;
if (isdigit(song.at(k)))
{
sustainedRemaining = 10 * sustainedRemaining + song.at(k) - '0';
k++;
}
if (sustainedRemaining < 2)
{
badBeat = beatNumber;
return RETBADSUSTAINEDLENGTH;
}
sustainedColor = toupper(song.at(k));
result += sustainedColor;
sustainedRemaining--;
}
else
{
result += tolower(song.at(k));
}
k += 2;
}
if (sustainedRemaining > 0)
{
badBeat = beatNumber;
return RETPREMATUREEND;
}
instructions = result;
return RETOK;
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
