Hi I would like to make a coordinate system using c++. I will be getting a few (x,y) coordinates from the user and using it I need to make a coordinate system(more of a map) style. How can I achieve this? It needs to look like the diagram below. Should I use a 2D array or vector and how to make the loop do the marking differently?
(2,0)(4,3)(7,8)
Needs to look like
**1************
***************
***************
***************
***1***********
***************
***************
********1******
This is the code I got so far, but the problem is I can’t mark more than one coordinate in it. I just used 2 for loops to do it
for(int i = -6; i < 7; i++)
if (i < 0)
cout<<" "<<i;
else
cout<<" "<<i;
cout<<endl;
for(int i = 0; i < 15; i++)
{
cout<<(char)(i + 49);
for(int j = -6; j < 7; j++)
if(i == y - 1 && j == x)
cout<<" x ";
else
cout<<" . ";
cout<<(char)(i + 49)<<endl;
}
Please advise. Thanks !!
I would advice you to use either
vector<string>orvector<vector<char> >or evenvector<vector<string> >depending on what do you intend to store in a cell. If a cell is a single character then probably the first option is the best.And after that creating the map is really easy:
I am not sure what are the ‘.’ and ‘x’ in the code above but I imaging all that is left for you is to input several pairs of coordinates and replace the respective element in the
vector<string>with ‘1’.Hope this helps.