Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

IT IS WRITTEN IN C++ PLEASE write a MAIN function to testing the other functions

ID: 3744939 • Letter: I

Question

IT IS WRITTEN IN C++

PLEASE write a MAIN function to testing the other functions.

#include <iostream>

#include <string.h>

#include<cstdlib>

#include <sstream>

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;

}

Explanation / Answer

If you have any doubts, please give me comment...

#include <iostream>

#include <cstring>

#include <cstdlib>

#include <sstream>

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()

{

char song[100], instructions[100];

int badBeat, status;

cout<<"Enter song lyrics: ";

cin.getline(song, 100);

status = tSong(song, instructions, badBeat);

if(status==0){

cout<<"Song was OK"<<endl;

cout<<"Instructions: "<<endl;

cout<<instructions<<endl;

}

else if(status==1)

cout<<"Not well Performed"<<endl;

else if(status==2)

cout<<"Sustained interrupted"<<endl;

else if(status == 3)

cout<<"Premature end"<<endl;

else if(status==4){

cout<<"Bad Sustained Length"<<endl;

cout<<"Bad beat at "<<badBeat<<endl;

}

return 0;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote