1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
|
#include<iostream>
#include<cctype>
#include<iomanip>
using namespace std;
void initialize(char seating[][3]);
void questions(char& ticketType, int& row,
char& column);
void printseating(char seating[][3], int row, char column);
void printseating2(char seating[][3], int row, char column);
int answer;
char type, column;
int row;
char seating[3][3];
int main(int argc, char *argv[])
{
initialize(seating) ;
answer = 1;
answer = static_cast<char>(toupper(answer));
cout << " A B C" << endl;
cout << " Row 1 * * *" << endl;
cout << " Row 2 * * *" << endl;
cout << " Row 3 * * *" << endl;
while(answer == 1 || answer == 0)
{
questions(type, row, column);
printseating(seating, row, column);
cout << '\n';
cout << "Press 1 for first player's move. 0 for 2nd player's move. : " ;
cin >> answer;
answer = static_cast<char>(toupper(answer));
if(answer == 3)
return 0;
}// end while
system("PAUSE");
return EXIT_SUCCESS;
}
void initialize(char seating[][3])
{
for(int i=0 ;i < 3 ;i++)
for(int j=0 ;j<3 ;j++)
seating[i][j]='*';
}
void questions(char& type, int& row, char& column)
{
type = static_cast<char>(toupper(type));
cout << '\n';
cout << "What Row Number would you like to mark? (1-3) : ";
cin >> row;
cout << "What seat number would you like to mark? (A-C) : ";
cin >> column;
column = static_cast<char>(toupper(column));
}
void printseating(char seating[][3], int row, char column)
{
int i, j;
if(seating[row-1][static_cast<int>(column-65)]=='X')
{cout << "This spot on the board is already taken. Choose another : " << '\n';
cin >> column;
column = static_cast<char>(toupper(column));
}
if(answer==1)
{
seating[row-1][static_cast<int>(column)-65]= 'X';
cout << '\n';
cout << " A B C" << '\n';
for(i = 0; i < 3; i++)
{
cout << left << setw(3) << "Row " << setw(2)<< i+1 ;
for(j = 0; j < 3; j++)
{
cout << right << " " << seating[i][j];
}
cout << '\n';
}}
if(answer==0)
{ if(seating[row-1][static_cast<int>(column-65)]=='O')
{
cout << "This spot on the board is already taken. Choose another : " << '\n';
cin >> column;
column = static_cast<char>(toupper(column));
}
seating[row-1][static_cast<int>(column)-65]= 'O';
cout << '\n';
cout << " A B C" << '\n';
for(i = 0; i < 3; i++)
{
cout << left << setw(3) << "Row " << setw(2)<< i+1 ;
for(j = 0; j < 3; j++)
{
cout << right << " " << seating[i][j];
}
cout << '\n';
}}
}
|