473,503 Members | 722 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Using vectors for map coding

3 New Member
Hello;
I will use standard library vectors and implement simple map coloring algorithm. The goal of a map coloring problem is to color a map so that regions sharing a common border have different colors

In C++ I can represent the neighboring information using a 2D vector of booleans. For example, consider the following 2D neighbor vector:
Countries 1 2 3 4
1 - T F T
2 T - F F
3 F F - T
4 T F T -
The countries 1 and 2 are neighbors. The countries 1 and 3 are not neighbors. Note that the 2D vector is symmetric

I write a C++ class with a constructor that takes the number of countries and a vector of available colors represented by strings (“red”, “blue”, “green”, etc.). The constructor builds a private random neighboring 2D vector.
I override the constructor with a function that takes a neighbor vector and a vector of available colors
I write a member function that accepts a vector of available colors

I write a member function that accepts a 2D neighboring vector

I write a member function named mapColor that assigns colors to countries. If the coloring is successful, it prints the country colors. Otherwise, it gives an error message. For example, for the above neighbor vector the output would be
Country 1 (red),
Country 2 (blue),
Country 3 (blue)
Country 4 (red).

I write some code but it is not run:S

MY CODE :
Expand|Select|Wrap|Line Numbers
  1. #include<iostream>// allows program to output data to the screen
  2. using std::cout;// program uses cout
  3. using std::cin;// program uses cin
  4. using std::endl;//program uses endl
  5.  
  6. // contains prototypes for functions srand and rand
  7. #include<cstdlib>
  8.  
  9. //contains prototypes for function time
  10. #include<ctime>
  11.  
  12. #include "dosya_1.h"// include definition of class Country
  13.  
  14.  
  15. // constructor takes the number of countries and a vector of available colors represented by strings 
  16. Country::Country(vector<char> &v_c_array,int number)
  17. {
  18.     vector<vector<bool> > v_2x_array;
  19.  
  20.     set_function_number_country(number);
  21.  
  22.     accept_vector_color(v_c_array);
  23.  
  24.     accept_2D_neighboring_vector(v_2x_array); 
  25.  
  26.  
  27.  
  28.  
  29. }//end Country constructor
  30.  
  31.  
  32.  
  33. Country::Country(vector<char> &a,vector<vector<char> &b)
  34. {
  35.     accept_vector_color();
  36.  
  37.     b(country_number,v_color_array);
  38.  
  39.     for (int i=0; i<b.size(); ++i)
  40.         for (int j=0; j<b[i].size(); ++j)
  41.             b[i][j] = v_2d_neighbor[i][j];
  42.  
  43. }
  44.  
  45.  
  46. void Country::accept_vector_color(vector<char> &v_c_array)
  47. {
  48.  
  49.     for(int i=0; i<country_number; ++i)
  50.         v_color_array[i] = v_c_array[i]; 
  51.  
  52.  
  53. void Country::accept_2D_neighboring_vector(vector<vector<bool> > &v_2D_neighbor)
  54. {
  55.     int x;
  56.  
  57.     srand(time(0));
  58.  
  59.     for (int i=0; i<b.size(); ++i)
  60.  
  61.         for (int j=0; j<b[i].size(); ++j)
  62.             v_2D_neighbor[i][j] = v_2d_neighbor[i][j];
  63.  
  64.  
  65.     for (int i=0; i<v_2D_neighbor.size(); ++i)
  66.  
  67.          for (int j=0; j<v_2D_neighbor[i].size(); ++j)
  68.          {
  69.              x = rand()%10 + 1;
  70.  
  71.              if(i == j)
  72.                  continue;
  73.  
  74.              else if(x = 1)
  75.                  v_2D_neighbor[i][j] = true;
  76.  
  77.              else 
  78.                  v_2D_neighbor[i][j] = false;
  79.          }
  80.  
  81. }
  82.  
  83.  
  84. void Country::set_function_number_country(int f_number)
  85. {
  86.     country_number = f_number;
  87.  
  88. }
  89.  
  90.  
  91. void mapColor()
  92. {
  93.     char country[country_number];
  94.  
  95.     for (int i=0; i<v_2d_neighbor.size(); ++i)
  96.     {    
  97.         for (int j=0; j<v_2d_neighbor[i].size(); ++j)
  98.         {
  99.             if(i == j)
  100.                 continue;
  101.  
  102.             else if(v_2d_neighbor[i][j])
  103.             {
  104.                 country[i] = v_color_array[0];
  105.                 country[j] = v_color_array[1];
  106.             }
  107.  
  108.             else
  109.             { 
  110.                 country[i] = v_color_array[0];
  111.                 country[j] = v_color_array[0];
  112.             }
  113.  
  114.         }
  115.     }
  116.  
  117.  
  118.     for(int k=0; k<country_number; ++k)
  119.         cout << "country(" << k << ") " << country[k] << "\n";
  120.  
  121.  
  122. }
  123.  
  124.  
  125. and MY HEADER  :
  126.  
  127. #include <vector>
  128.  
  129. using std::vector;
  130.  
  131. class Country{
  132.  
  133. public:
  134.     Country(vector<char>&,int);
  135.  
  136.     Country(vector<char>&,vector<vector<bool> >&);
  137.  
  138.     void set_function_number_country(int);
  139.  
  140.     void accept_vector_color(vector<char> &);
  141.  
  142.     void accept_2D_neighboring_vector();
  143.  
  144.     void mapColor();
  145.  
  146.     int find_minimum_number_of_colors();
  147.  
  148.  
  149. private:
  150.  
  151.     int country_number;
  152.     vector<char> v_color_array(4);
  153.     vector<vector<bool> > v_2d_neighbor();
  154.  
  155.  
  156. };
  157.  
Please help mee

REGARDS..
Nov 5 '07 #1
3 3241
sicarie
4,677 Recognized Expert Moderator Specialist
What's the error you get when you try to run it? Can you copy and paste them?
Nov 5 '07 #2
mersinli
3 New Member
What's the error you get when you try to run it? Can you copy and paste them?
So I don't write main function that test all of the functions but many many error occur

--------------------Configuration: ctry - Win32 Debug--------------------
Compiling...
ctry.cpp
c:\program files\microsoft visual studio\myprojects\contry\dosya_1.h(27) : error C2059: syntax error : 'constant'
C:\Program Files\Microsoft Visual Studio\MyProjects\contry\ctry.cpp(24) : error C2660: 'accept_2D_neighboring_vector' : function does not take 1 parameters
C:\Program Files\Microsoft Visual Studio\MyProjects\contry\ctry.cpp(33) : error C2146: syntax error : missing ',' before identifier 'b'
C:\Program Files\Microsoft Visual Studio\MyProjects\contry\ctry.cpp(33) : error C2065: 'b' : undeclared identifier
C:\Program Files\Microsoft Visual Studio\MyProjects\contry\ctry.cpp(33) : error C2143: syntax error : missing ',' before ')'
C:\Program Files\Microsoft Visual Studio\MyProjects\contry\ctry.cpp(34) : error C2143: syntax error : missing ';' before '{'
C:\Program Files\Microsoft Visual Studio\MyProjects\contry\ctry.cpp(39) : error C2143: syntax error : missing ')' before ';'
C:\Program Files\Microsoft Visual Studio\MyProjects\contry\ctry.cpp(39) : error C2059: syntax error : ')'
C:\Program Files\Microsoft Visual Studio\MyProjects\contry\ctry.cpp(40) : error C2143: syntax error : missing ')' before ';'
C:\Program Files\Microsoft Visual Studio\MyProjects\contry\ctry.cpp(40) : error C2059: syntax error : ')'
C:\Program Files\Microsoft Visual Studio\MyProjects\contry\ctry.cpp(43) : error C2143: syntax error : missing ';' before '}'
C:\Program Files\Microsoft Visual Studio\MyProjects\contry\ctry.cpp(47) : error C2143: syntax error : missing ';' before '{'
C:\Program Files\Microsoft Visual Studio\MyProjects\contry\ctry.cpp(49) : error C2143: syntax error : missing ')' before ';'
C:\Program Files\Microsoft Visual Studio\MyProjects\contry\ctry.cpp(49) : error C2059: syntax error : ')'
C:\Program Files\Microsoft Visual Studio\MyProjects\contry\ctry.cpp(52) : error C2143: syntax error : missing ';' before '}'
C:\Program Files\Microsoft Visual Studio\MyProjects\contry\ctry.cpp(55) : error C2143: syntax error : missing ';' before '{'
C:\Program Files\Microsoft Visual Studio\MyProjects\contry\ctry.cpp(60) : error C2143: syntax error : missing ')' before ';'
C:\Program Files\Microsoft Visual Studio\MyProjects\contry\ctry.cpp(60) : error C2059: syntax error : ')'
C:\Program Files\Microsoft Visual Studio\MyProjects\contry\ctry.cpp(62) : error C2143: syntax error : missing ')' before ';'
C:\Program Files\Microsoft Visual Studio\MyProjects\contry\ctry.cpp(62) : error C2059: syntax error : ')'
C:\Program Files\Microsoft Visual Studio\MyProjects\contry\ctry.cpp(66) : error C2143: syntax error : missing ')' before ';'
C:\Program Files\Microsoft Visual Studio\MyProjects\contry\ctry.cpp(66) : error C2059: syntax error : ')'
C:\Program Files\Microsoft Visual Studio\MyProjects\contry\ctry.cpp(68) : error C2143: syntax error : missing ')' before ';'
C:\Program Files\Microsoft Visual Studio\MyProjects\contry\ctry.cpp(68) : error C2059: syntax error : ')'
C:\Program Files\Microsoft Visual Studio\MyProjects\contry\ctry.cpp(69) : error C2143: syntax error : missing ';' before '{'
C:\Program Files\Microsoft Visual Studio\MyProjects\contry\ctry.cpp(80) : error C2143: syntax error : missing ';' before '}'
C:\Program Files\Microsoft Visual Studio\MyProjects\contry\ctry.cpp(82) : error C2143: syntax error : missing ';' before '}'
C:\Program Files\Microsoft Visual Studio\MyProjects\contry\ctry.cpp(86) : error C2143: syntax error : missing ';' before '{'
C:\Program Files\Microsoft Visual Studio\MyProjects\contry\ctry.cpp(89) : error C2143: syntax error : missing ';' before '}'
C:\Program Files\Microsoft Visual Studio\MyProjects\contry\ctry.cpp(93) : error C2143: syntax error : missing ';' before '{'
C:\Program Files\Microsoft Visual Studio\MyProjects\contry\ctry.cpp(96) : error C2143: syntax error : missing ')' before ';'
C:\Program Files\Microsoft Visual Studio\MyProjects\contry\ctry.cpp(96) : error C2059: syntax error : ')'
C:\Program Files\Microsoft Visual Studio\MyProjects\contry\ctry.cpp(97) : error C2143: syntax error : missing ';' before '{'
C:\Program Files\Microsoft Visual Studio\MyProjects\contry\ctry.cpp(98) : error C2143: syntax error : missing ')' before ';'
C:\Program Files\Microsoft Visual Studio\MyProjects\contry\ctry.cpp(98) : error C2059: syntax error : ')'
C:\Program Files\Microsoft Visual Studio\MyProjects\contry\ctry.cpp(99) : error C2143: syntax error : missing ';' before '{'
C:\Program Files\Microsoft Visual Studio\MyProjects\contry\ctry.cpp(104) : error C2143: syntax error : missing ';' before '{'
C:\Program Files\Microsoft Visual Studio\MyProjects\contry\ctry.cpp(107) : error C2143: syntax error : missing ';' before '}'
C:\Program Files\Microsoft Visual Studio\MyProjects\contry\ctry.cpp(110) : error C2143: syntax error : missing ';' before '{'
C:\Program Files\Microsoft Visual Studio\MyProjects\contry\ctry.cpp(113) : error C2143: syntax error : missing ';' before '}'
C:\Program Files\Microsoft Visual Studio\MyProjects\contry\ctry.cpp(115) : error C2143: syntax error : missing ';' before '}'
C:\Program Files\Microsoft Visual Studio\MyProjects\contry\ctry.cpp(116) : error C2143: syntax error : missing ';' before '}'
C:\Program Files\Microsoft Visual Studio\MyProjects\contry\ctry.cpp(119) : error C2143: syntax error : missing ')' before ';'
C:\Program Files\Microsoft Visual Studio\MyProjects\contry\ctry.cpp(119) : error C2059: syntax error : ')'
C:\Program Files\Microsoft Visual Studio\MyProjects\contry\ctry.cpp(123) : error C2143: syntax error : missing ';' before '}'
C:\Program Files\Microsoft Visual Studio\MyProjects\contry\ctry.cpp(126) : error C2143: syntax error : missing ';' before '}'
C:\Program Files\Microsoft Visual Studio\MyProjects\contry\ctry.cpp(126) : fatal error C1001: INTERNAL COMPILER ERROR
(compiler file 'YĂ', line 1)
Please choose the Technical Support command on the Visual C++
Help menu, or open the Technical Support help file for more information
Error executing cl.exe.

ctry.exe - 47 error(s), 0 warning(s)

you can write a main function that test all of the functions and modify or change my code for that is run.
thank you very very much:):)
Nov 5 '07 #3
weaknessforcats
9,208 Recognized Expert Moderator Expert
You have to fix these syntax errors first.

Start with line 27 in your dosya_1.h and see whet the problem is. By the time the compiler saw the word const, it knew there was a problem. The error will be form there or earlier in the file.
Nov 5 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

5
2304
by: Computer Whizz | last post by:
I was reading through Accelerated C++ at work when I read through the first mention of Vectors, giving us certain functions etc. Is there any benefit of Arrays over Vectors? Since all Vectors...
19
4347
by: chris | last post by:
Hello, I've recently been trying to understand the various structures supplied by c++, and the one I find most confusing is deque. One quick question about this. It seems most implementations...
3
3227
by: Amit | last post by:
Hello. I am having some problem organizing a set of vectors. The vectors itself, could contain a pointer( say integer pointer) or could contain another object MyClass. 1>So, first of all, is...
5
18085
by: madhu | last post by:
http://msdn2.microsoft.com/en-us/library/fs5a18ce(VS.80).aspx vector <intv1; v1.push_back( 10 ); //adds 10 to the tail v1.push_back( 20 ); //adds 20 to the tail cout << "The size of v1 is " <<...
2
8664
by: wuzertheloser | last post by:
Use the program skeleton below (starting with #include <stdio.h>) as the starting point for quiz4. Add the necessary code to the functions prob1() and prob2(), and add the other 2 functions, as...
1
2000
by: Michael O'Brien | last post by:
Hola~ I have a large array of points (over a million). I would like to multiply each point in the array by a 4x4 matrix. I keep thinking there should be an easy way to do this using numpy, but I...
1
2438
nabh4u
by: nabh4u | last post by:
Hi, I have a problem referencing to Vectors using pointers i.e. I am not able to use "call by reference" on vector variables. I have a "read()" function in "x.cpp" and "main()" in "y.cpp". I...
1
2036
by: Rob | last post by:
How would I do this? I want to be able to handle vectors of many different types of data and vectors that can contain any number of other vectors of data. Currently, I have a templated...
4
2443
by: Peter Webb | last post by:
I am writing some visualisation code for 4 dimensional geometric shapes. This is to run in the C# .NET XNA environment, so I am cross posting a maths and C# group. My software runs just fine for...
0
7203
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7089
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7282
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6995
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7463
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5017
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4678
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3168
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
738
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.