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
|
#include <iostream>
#define MaxColumns 10
#define MaxRows 20
using namespace std;
void DrawMap();
void ArrayTest();
int main()
{
int myChoice;
enum Choice { MAP = 1, ARRAY };
cout << "Enter your choice (1 for DrawMap | 2 for ArrayTest): ";
cin >> myChoice;
switch(myChoice)
{
case MAP:
DrawMap();
break;
case ARRAY:
ArrayTest();
break;
default:
cout << "ERROR! Invalid choice..." << endl;
break;
}
return 0;
}
void ArrayTest()
{
int Yams[3] = { 7, 8, 6 };
int YamCosts[3] = { 20, 30, 5};
int Total = ( Yams[0] * YamCosts[0] ) + ( Yams[1] * YamCosts[1] ) +
( Yams[2] * YamCosts[2] );
cout << "Total yams = " <<
Yams[0] + Yams[1] + Yams[2] << endl;
cout << "The package with " << Yams[1] <<
" yams costs " << YamCosts[1] << " cents per yam" << endl;
int YamsDollars = Total / 100;
int YamsCents = Total % 100;
cout << "Total yams expense: $" << YamsDollars << "." << YamsCents << endl;
cout << "Size of yams array: " << sizeof(Yams) << endl;
cout << "Size of one elements" << sizeof(Yams[0]) << endl;
}
void DrawMap()
{
int X, Y;
cout << "Entering DrawMap()..." << endl;
cout << "Enter an X, Y Coord: ";
cin >> X;
cin >> Y;
cout << "Drawing Map[" << MaxColumns << "][" << MaxRows << "]" << endl;
char Map[MaxColumns][MaxRows+1] =
{
"####################",
"# #",
"# #",
"# #",
"# #",
"# #",
"# #",
"# #",
"# #",
"####################",
};
//Place a '*' character at set coordinate
//as long as it's a valid number
if (X > MaxColumns || X < 0 || Y > MaxRows || Y < 0)
{
cout << "Invalid Coordinate..." << endl;
} else
{
Map[X-1][Y-1] = '*';
}
//Draw the Map[][] array
for(unsigned short rows=0; rows < MaxColumns ; rows++)
cout << Map[rows] << endl;
}
|