Class practice 3 (Village of the Sorcerer 6)
Village of the Sorcerer 6
This practice problem will require you to programme basic classes.
Please make sure you have passed your OJ practice P014.
In this practice problem, we are going to take your implementation of P014, and turn it into an object oriented programming design. We are going to declare a class for handling all our map reading and map outputting operations so that you won't have to struggle with maps anymore.
The expected header is as follows:
#ifndef _P024
#define _P024
#include <iostream>
class Map {
int map[100][100];
int mapN, mapM; // use these to store the dimension for the map
public:
void readMap(std::istream &cin, int n, int m);
void printMap(std::ostream &cout, int x, int y);
};
#endif
Class Specification
Map::readMap
This member function will read an entire map from an istream
object called
cin
.
The expected input from cin
should be n
lines, each contain m
integers,
each the item at that coordinate.
Map::printMap
This member function will print the map exactly as in OJ question P014 to
ostream
object cout
. The only addition is the player's coordinate (x, y)
.
You should print the player as a plus sign +
at that coordinate, unless it's
covered by the leaves ('*'
) of a tree.
Testing
You should modify your code for P014 to provide a main testing programme
main.cpp
. Please note the addition of the player coordinate in your tests.
Input Specification
No input specification. OJ will automatically judge your implementation of
p024.cpp
.
Output Specification
No output specification. OJ will automatically judge your implementation of
p024.cpp
.
Comments