Thursday, July 9, 2009

In C++, how can we create a 2 D array that stores integer value and character value?

In C++, how can we create a 2 D array that stores integer value and character value at the same time?


I know we are allowed to store only 1 data type for both arrays.


But I want to store 1,2,3...... in first array and A,B, C... in second array.


Example: We have 15 (1-15) seats which are identified by letters a,b,c. like 10a, 12d, 7f..... i am checking if seats are vacant or occupied.


If 10a is vacant, it will be


seat[10][a] = vacant.


But I can't store integers and characters at same time.


How can i store this info in a 2d array?


Any C++ genius here?

In C++, how can we create a 2 D array that stores integer value and character value?
May be you can post your requirements at http://expert.gionram.com/


and let many programmers bid for your project.


You can hire whoever you like.





Do not pay any money afront however.
Reply:Well, you can't get pass the law of using only one datatype, but... if you isolate each dimension (one for integers, and the other for characters), then you can take the ASCII route for the character dimension. Every character (letters, numbers, etc) have an associated integer values. All you'd have to do is cast the character to its integer values and store it in the array. When you need the character, do a cast back to a character.





Check the table on this site. The Dec values are the associated integer value for each character value on the right.


http://www.asciitable.com/


No comments:

Post a Comment