Question
IT IS WRITTEN IN C++ PLEASE write a MAIN function to testing the other functions. #include #include #include #include using namespace std; const char ENDOFBEAT
IT IS WRITTEN IN C++
PLEASE write a MAIN function to testing the other functions.
#include
#include
#include
#include
using namespace std;
const char ENDOFBEAT = '/';
//updating all area's of strings with arrays
bool Syntax(char song[])//changing to array
{
//finding length of the string ........ which is in the form of array
int size = strlen(song);
if (size == 0)//if size is zero
return true;
if (song[size - 1] != ENDOFBEAT)
return false;
size_t k = 0;
while (k != size)
{
if (song[k] == ENDOFBEAT)
{
k++;
continue;
}
if (isdigit(song[k]))
{
k++;
if (isdigit(song[k]))
k++;
}
char color = tolower(song[k]);
if (color != 'g' && color != 'r' && color != 'y' &&
color != 'b' && color != 'o')
return false;
k++;
if (song[k] != ENDOFBEAT)
return false;
k++;
}
return true;
}
int tSong(char song[], char 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;
char result[1000];//converted to array
int r = 0;
int sustainedRemaining = 0;
char sustainedColor;
int beatNumber;
size_t k = 0;
int size = strlen(song);
for (beatNumber = 1; k != size; beatNumber++)
{
if (song[k] == ENDOFBEAT)
{
if (sustainedRemaining > 0)
{
// Continue with sustained note
result[r++] = sustainedColor;
sustainedRemaining--;
}
else
result[r++] = 'x';
k++;
continue;
}
if (sustainedRemaining > 0)
{
badBeat = beatNumber;
return RETSUSTAINEDINTERRUPTED;
}
if (isdigit(song[k]))
{
sustainedRemaining = song[k] - '0';
k++;
if (isdigit(song[k]))
{
sustainedRemaining = 10 * sustainedRemaining + song[k] - '0';
k++;
}
if (sustainedRemaining < 2)
{
badBeat = beatNumber;
return RETBADSUSTAINEDLENGTH;
}
sustainedColor = toupper(song[k]);
result[r++] = sustainedColor;
sustainedRemaining--;
}
else
{
result[r++] = tolower(song[k]);
}
k += 2;
}
if (sustainedRemaining > 0)
{
badBeat = beatNumber;
return RETPREMATUREEND;
}
// instructions = result;
//copying result to instructions....
strcpy(instructions, result);
return RETOK;
}
int main()
{
return 0;
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started