# 2D arrays in c++

This topic is 3989 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Im making a console c++ program for a personal assignment, and a part of it needs operations on an array.
    A B C D E F G H I...Z

A   a b c d e f g h i...z
B   b c d e f g h i...z a
C   c d e f g h i...z a b
D   d e f g h i...z a b c
...
Z z
(capital letters denote a referencing row)

Operation - 1. User picks two letters from the reference rows (eg 'C' and 'D') 2. Program shows the alphabet which occours in the same row and column as both of the reference letters (here that'd be 'f', for 'B' and 'G' that'd be 'h', etc) Could anyone please give me the code fragment for the two given operations? -regards, BlueBolt [Edited by - BlueBolt on September 17, 2007 8:16:39 AM]

##### Share on other sites
Do you have an actual question?

##### Share on other sites
You don't need operations on arrays for this. The structure of values inside the arrays is so regular that you can generate it on the fly using two '+' and one '%'.

##### Share on other sites
@SiCrane - Of course...just asked one.
Quote:
 Original post by ToohrVykYou don't need operations on arrays for this. The structure of values inside the arrays is so regular that you can generate it on the fly using two '+' and one '%'.

I tried to use the ASCII of a character to generate the entire English alphabet (as a starting step to implement your advice)...it just spewed me with junk values...
#include<iostream>using namespace std;int main(){    char alpha;    alpha=1; //or maybe alpha=a;    cout<<alpha;    cin>>alpha;    for(int i=0; i<=26; alpha++)            cout<<alpha;    return 0;}

I have a gist that if I knew how to represent alphabets in their ASCII code in the program, I would be able to make the alphabetic sequences (a matter of an increment sign, as ToohrVyk said...dunno where the modules pops in)

-regards,
BlueBolt

##### Share on other sites
char alpha = 'a';

##### Share on other sites
Quote:
 Could anyone please give me the code fragment for the two given operations?

But, given that the entire structure of the OP is very much like a homework assignment, most would be unwilling to do so.

Quote:
 for(int i=0; i<=26; alpha++) cout<

Letters are represented as ASCII table. But since you can treat them as numbers in your particular case, then this becomes valid:

for (char c = 'a'; c <= 'z'; c++) std::cout << c;

The other way, to obtain n-th character, can be obatined using:
int index = 14;std::cout << ( 'a' + index );

Obviously, it goes the other way as well. Which number is the letter x?
char x = 'f';std::cout << (x - 'a');

And no, there is no need for a table, everything can be calculated using the above operations.

1. 1
2. 2
3. 3
4. 4
frob
14
5. 5

• 16
• 12
• 20
• 12
• 19
• ### Forum Statistics

• Total Topics
632167
• Total Posts
3004528

×