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

Write the getColorName and getChessPieceName routines below. Note the output tha

ID: 3540097 • Letter: W

Question

Write the getColorName and getChessPieceName routines below.   Note the output that should be generated is shown in some comments in main(). These 2 routines will be used in the next 2 questions below.    #include <iostream> #include <string> using namespace std;  enum ChessPieceType {Pawn, Rook, Knight, Bishop, Queen, King}; enum Color {White, Black};  // Depending on the value of the Color parameter, the string returned is either "Black" or "White"  // if shortVersion = false.  If shortVersion= true (default), then the return value is either "B" or "W"   string getColorName(Color c, bool shortVersion=true) {    // Fill in your code here }  // Depending on the value of the ChessPieceType parameter, the string returned is  // "Pawn", "Rook", "Night", "Bishop", "Queen", "King" etc. if shortVersion = false // If shortVersion= true (default), then the return value is one of the following: // "P", "R", "N", "B", "Q", "K"  string getChessPieceName(ChessPieceType ct, bool shortVersion=true) {    // Fill in your code here }    int main() {     cout << getColorName(Black) << endl;     cout << getColorName(Black, false) << endl;     cout << getColorName(White) << endl;     cout << getColorName(White, false) << endl;      cout << getChessPieceName(Pawn) << endl;     cout << getChessPieceName(Pawn, false) << endl;     cout << getChessPieceName(Rook) << endl;     cout << getChessPieceName(Rook, false) << endl;     cout << getChessPieceName(Knight) << endl;     cout << getChessPieceName(Knight, false) << endl;     cout << getChessPieceName(Bishop) << endl;     cout << getChessPieceName(Bishop, false) << endl;     cout << getChessPieceName(Queen) << endl;     cout << getChessPieceName(Queen, false) << endl;     cout << getChessPieceName(King) << endl;     cout << getChessPieceName(King, false) << endl;      /* The output of this should be: B Black W White P Pawn R Rook N Night B Bishop Q Queen K King Press any key to continue . . . */      return 0; }
 what is the source code of the program? and the output?

Explanation / Answer

#include <iostream>

#include <string>

using namespace std;


enum ChessPieceType {Pawn, Rook, Knight, Bishop, Queen, King};

enum Color {White, Black};


// Depending on the value of the Color parameter, the string returned is either "Black" or "White"

// if shortVersion = false. If shortVersion= true (default), then the return value is either "B" or "W"



string getColorName(Color c, bool shortVersion=true)

{

// Fill in your code here

if(shortVersion==true && c==1)

return "B";

else if(shortVersion==true && c==0)

return "W";

else if(shortVersion==false && c==1)

return "black";

else

return "white";

}


// Depending on the value of the ChessPieceType parameter, the string returned is

// "Pawn", "Rook", "Night", "Bishop", "Queen", "King" etc. if shortVersion = false

// If shortVersion= true (default), then the return value is one of the following:

// "P", "R", "N", "B", "Q", "K"


string getChessPieceName(ChessPieceType ct, bool shortVersion=true)

{

// Fill in your code here


if(shortVersion==true && ct==0)

return "P";

else if(shortVersion==true && ct==1)

return "W";

else if(shortVersion==false && ct==0)

return "Pawn";

else if(shortVersion==false && ct==1)

return "Rook";

else if(shortVersion==true && ct==2)

return "N";

else if(shortVersion==true && ct==3)

return "B";

else if(shortVersion==false && ct==2)

return "Night";

else if(shortVersion==false && ct==3)

return "Bishop";

else if(shortVersion==true && ct==4)

return "Q";

else if(shortVersion==true && c==5)

return "K";

else if(shortVersion==false && c==4)

return "Queen";

else if(shortVersion==false && c==5)

return "King";




}




int main()

{

cout << getColorName(Black) << endl;

cout << getColorName(Black, false) << endl;

cout << getColorName(White) << endl;

cout << getColorName(White, false) << endl;


cout << getChessPieceName(Pawn) << endl;

cout << getChessPieceName(Pawn, false) << endl;

cout << getChessPieceName(Rook) << endl;

cout << getChessPieceName(Rook, false) << endl;

cout << getChessPieceName(Knight) << endl;

cout << getChessPieceName(Knight, false) << endl;

cout << getChessPieceName(Bishop) << endl;

cout << getChessPieceName(Bishop, false) << endl;

cout << getChessPieceName(Queen) << endl;

cout << getChessPieceName(Queen, false) << endl;

cout << getChessPieceName(King) << endl;

cout << getChessPieceName(King, false) << endl;


  


return 0;

}