implement function abbreviation() that takes a day of the week as input and retu
ID: 3549273 • Letter: I
Question
implement function abbreviation() that takes a day of the week as input and returns its two-letter abbreviation.
>>> abbreviation ('Tuesday')
'Tu'
The computer game function collision () checks whether two circular objects collide; it returns True if they do and False otherwise. Each circular object will be given by it's radius and the (x,y) coordinates of it's center. Thus the function will take six numbers as input: the coordinates x1 and y1 of the center and the radius r1 of the first circle, and the coordinates x2 and y2 and the radius r2 of the second circle.
>>> collision (0,0,,3,0,5,3)
true
>>> collision(0,0,1.4,2,2,1.4)
false
Explanation / Answer
}
}
}
void TicTacToe::PrintBoard()
{
int t;
for(t=0; t<3; t++) {
cout<<" "<<board[t][0]<<" | "<< board[t][1]<<" | "<< board[t][2];
if(t!=2) cout<<" ---|---|--- ";
}
cout<<" ";
}
char TicTacToe:: CheckForWinner()
{
if (checkHorizontal('X'))
{
return 'X';
}
if (checkVertical( 'X'))
{
return 'X';
}
if (checkDiagonal( 'X'))
{
return 'X';
}
if (checkHorizontal('O'))
{
return 'O';
}
if (checkVertical( 'O'))
{
return 'O';
}
if (checkDiagonal( 'O'))
{
return 'O';
}
if (IsScratch())
{
return 'T';
}
return ' ';
}
/*checks to see if someone won on rows of board*/
/*checks to see if someone won on rows of board*/
bool TicTacToe::checkHorizontal( char marker)
{int i,j,count;
for(i=0; i<rows; i++)
{count=0;
for(j=0;j<cols;j++)
if(board[i][j]==marker)
count++;
if(count==3)
return true;
}
return false;
}
/*checks to see if someone won on columns of board*/
bool TicTacToe::checkVertical( char marker)
{int i,j,count;
for(i=0; i<rows; i++)
{count=0;
for(j=0;j<cols;j++)
if(board[j][i]==marker)
count++;
if(count==3)
return true;
}
return false;
}
bool TicTacToe::checkDiagonal( char marker)
{if(board[0][0]==board[1][1] && board[1][1]==board[2][2]&& board[0][0]==marker)
return true;
if(board[0][2]==board[1][1] && board[1][1]==board[2][0]&& board[0][2]==marker)
return true;
return false;
}
/*checks to see if players have tied*/
bool TicTacToe::IsScratch()
{int i,j;
for(i=0;i<rows;i++)
for(j=0;j<cols;j++)
if(board[i][j]==' ')
return false;
return true;
}
/*prints winner as marker or ties*/
void TicTacToe::printWinner(char marker)
{ if(marker=='T')
cout<<"TIE GAME! ";
else
cout<<"The winner is "<<marker<<"!!! ";
}
void TicTacToe::getInput(char marker,size_t &r,size_t &c)
{
for(;;)
{cout<<"Player "<<marker<<endl;
cout << "Enter move row(1-3): " ;
cin >> r;
cout << "Enter move column(1-3): " ;
cin >> c;
if (OccupySquare(r,c,marker) )
{
return ;
}
cout << "Invalid Move: Please Try Again ";
}
}
bool TicTacToe::IsValidLocation(size_t r,size_t c)
{
if(r<1||r>rows||c<0||c>cols)
return false;
if(board[r-1][c-1]!=' ')
return false;
else
return true;
}
bool TicTacToe::OccupySquare( size_t r,size_t c, char marker)
{if(IsValidLocation( r,c))
{board[r-1][c-1]=marker;
return true;
}
return false;
}
"
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.