Creating a chart of characters using two arrays

Pages: 12
So I need to write a program that uses two arrays of which the size is known, (6).
The task of the program is to ask the user for six integers, and then six characters (all this info will be stored in an array), and then print out a chart of those characters corresponding to the numbers entered.
for example, if I type in 3 4 5 1 2 6
and a b c d e f
it should look like this
_______ f
___ c___ f
__b c___ f
a b c ___f
a b c __e f
a b c d e f
Please assume those lines to be spaces, and that the letters are lined up properly and vertically, my post didn't allow for the spaces.

I have already come up with the arrays, and I have been able to successfully gather the digits and characters, but I cant print the chart. I created these two functions to help me, but im still lost.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
  int minIndex(int array[], int beg, int end){
  int ans = beg;
  for ( int c = beg; c < end; c++)
     if (array[c] < array [ans]) ans = c;
   return ans;
}
  
int getMax(int array[], int cap){
   int ans = 0;
   for (int c = 0; c < cap; c++){
    if (array[c] > array [ans]) ans = c;
   return ans;
} 
Last edited on
closed account (j3Rz8vqX)
I might be interpreting incorrectly... rephrase/repeat the instructions?...
Pseudo:
Two array:
----myArray1{1,2,3,4,5}
----myArray2{A,B,C,D,E}
print out a chart of those characters corresponding to the numbers entered

Logic:1->A,2->B,3->C,4->D,5->E
Appearance:
1 A
2 B
3 C
4 D
5 E

Loop(start = 0;start <6;start ++)
----Print--myArray1[start]
----Print--space
----Print--myArray2[start]
----Print--newLine

Edit #1:
A chart:
Characters that correlate with their Numbers?

Edit #2:
Or do you mean:
Print out a chart(Quadrant II right triangle) whose size was prompted to the user and whose values were entered by the user?

Still unsure of what you're asking.

Edit #3:
Ah.
5,B:____B
2,D:_D___
3,F:__F__
1,A:A____
4,C:___C_

Is this what you mean?

Edit #4:
Oh, slowly fill up =D

Loop(/*Stuff*/)
----Prompt user for the integer:
----Prompt user for the character:
----Insert integer and character into their appropriate indexes.
Repeat

Loop(/*Stuff*/)//(Incrementing)
----Print Character @ index, based on value @ index; at its corresponding location.
----(Printing more each time)
Repeat

That should do it.
Last edited on
your a little on point for what im asking, but its like creating a tower basically
like if there is 1 corresponds with a, then there would be one a printed starting from the bottom, but lets say if it was 3, then there would be 3 a's.

basically it creates columns of each character, and the columns size depends on the corresponding number. But the columns start from the bottom rather than the top, so I believe somewhere in the program a swap might be needed?
yeah that's what I need to do but im having difficulty printing the characters correctly
closed account (j3Rz8vqX)
Probably something like this?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
for(int i=0;i<5;i++)
{
    for(int x=0;x<5;x++)
    {
        if(x==myArray1[i])
        {
            cout<<myArray2[i];
            break;
        }
        else
        {
            cout<<" ";
        }
    }
    cout<<endl;
}

Try it.

Edit: If not redraw the design.

My currently understanding is that you want it bottom up?

Confused.
Last edited on
That's getting me closer there, but it only prints one letter corresponding to a digits spot. what I need is the number of characters to match the corresponding digit.

ex: if a corresponds with 3, b with 5, and c with 2, it should look like this

_ b
_ b
a b
a b c
a b c

once again ignore those lines because it wont let me place spaces
yeah that's what I need, from the bottom up, like if it should print only one letter, it should be in the last row. and if it should print 6 letters, then it should be in the last row going upwards until the column is filled with 6 letters.
closed account (j3Rz8vqX)
Ah, a vertical geometric shape based on character and integer (controlling the height of the tower).

Edit, edit, edit...
Look at this logic:
1
2
3
4
5
6
7
8
9
10
11
for(int y=0;y<5;y++)//Starts 0 and goes to 5(exclusive)
{
    for(int x=0;x<5;x++)//Starts at value 0 and goes to 5(exclusive)
    {
        if(myArray1[x]>=5-y)//If value at index > current value of 5-y, print for this row
            cout<<myArray2[x];
        else//else print space
            cout<<" ";
    }//End at 5th cycle
}//End at 5th cycle
cout<<endl;
Last edited on
this gives me what I need except its horizontal, I need to convert it to a vertical shape. im getting closer to solving it but the swapping part seems quite confusing
closed account (j3Rz8vqX)
Let me know if your problem is resolved.
EDIT-- thanks your program worked

now all I have remaining to do is to create a function which will print another chart that will organize the columns by size, smallest to largest

so if someone was to use the digits 3 4 5 6 2 1

and the letters a b c d e f

the columns would be organized by the f column, followed by the e, and then the a, and so on.
Last edited on
closed account (j3Rz8vqX)
Should work, except tower is limited to size 5 height >.<
Let's run through this (logically)

for(int y=0;y<5;y++)
----From 0 to 5, increment counter y.

----for(int x=0;x<5;x++)
--------From 0 to 5, increment counter x.

--------if(myArray1[x]>=5-y)
--------Assuming our max height is 5; if value at array indexed by x is less than 5-y.
------------cout<<myArray2[x];
------------Draw the letter.
--------[code]else cout<<" ";
------------Else draw a blank

Assumed values entered: (Our limiting factor size 5; yours is 6 =D)
3 4 5 1 2 6
a b c d e f

Round 1: y=0; x=0;
3>=5-0? Nope, create blank.
increment x;
4>=5-0? Nope, create blank.
increment x;
5>=5-0? Yes, create character c.
increment x;
1>=5-0? Nope, create blank.
increment x;
2>=5-0? Nope, create blank.
Done.

My Assumption:
Round 2: y=2;x=0;
...
Round 3: y=3;x=0;
...
Round 4: y=4;x=0;
...
Round 5: y=5;x=0;
...

Assumed Result:
__c__
_bc__
abc__
abc_e
abcde

Just my assumption, I may be off.

What's the possibility that something else in the program is causing this to not work?

Possibly I've made a mistake, you never know; tell me if you see something off.
Last edited on
your program worked. now I just need to create another chart which will sort the columns in order from shortest to largest
closed account (j3Rz8vqX)
"Your" program worked. My algorithm helped; with a long tedious process of induction and deduction.

You should probably consider using bubble sort; unless you know more complex sorts.
I really appreciate the help. I just realized a flaw in my program, since I was using the number 6, my chart was limited in a sense of how big it could be. I modified it so I used my getMax function to find the index number with the maximum value, this way I was able to get rid of that limit. I used another variable to take that index number, and created an extra variable to equal the value of that index number.

I also created the bubble sort array, looking like this

void sort(int array[], char z[], int cap){

for (int k=1; k < cap; k++)
for (int x=0; x< cap - 1 - k; x++)
if (array[x] > array[x + 1]){
int temp = array[x];
array[x] = array[x + 1];
array[x + 1] = temp;
}

return;
}

but it doesn't properly sort
closed account (j3Rz8vqX)
Loop (skip =0;skip < max-1;skip ++)//determine how much to skip
----Loop(check=skip+1 ;check<max;check++)//loop comparing
--------compare skip and check;//if true
------------swap;

Controls:
-1: to never check max(out of bound)
Assumptions:

Values:
3 5 2 8 1

Routine 0:
check0: 3v5 No
check1: 3v2 Yes
check2: 2v8 No
check3: 2v1 Yes

15382

Routine 1:
...
Routine 3:

if max was 5; skip would go 0 to 3 (less than 5-1:4); third index is: 15382.

if max was 5; check would go 1(R1:skip) to 4 (less than 5); fourth index is: 15382.

You should be good, I may be wrong, just simulating on the fly.
your bubble sort does not work properly cause you have
x < cap - 1 -k It wont sort the last 2 elements. You should just have it as cap - k and it should be fine.
Thanks Void life, I fixed that problem but what I now realize the problem is that I need to change the places of each of the towers, and my sort function isn't addressing it the proper way

lets assume the numbers entered were 1 3 2 6 7 5

and characters a b c d e f

we would have a tower of 1 a, 3 b, 2c, 6 d, 7 e, and 5 f

what I need to do is sort the towers from smallest to largest so my first chart would appear normally, and a second chart would follow up that except in order from smallest to largest, so instead of a b c d e f, in this case it would follow up as a c b f d e




closed account (j3Rz8vqX)
Does it sort properly?

If so, couldn't you simply print before sort and after sort?

If not, update.
Assume all the letters are in a tower, above their respected letters (copy paste isn't letting the spaces print)

Enter 6 numbers greater than 0: 1 4 3 5 6 2
Enter 6 characters: a b c d e f
_____ e
_____d_ e
_ b_ d_ e
_ b c d e
_ b c d e f
a b c d e f


Sorted Chart:

____ e
__ _de
__ cde
_ bcde
a bcde



this is a trial I just ran, the sort function I have seems to be the problem. what it does is it modifies the towers, instead of swapping them around in order from smallest to largest. on top of that, sometimes a tower doesn't appear.

I print the original chart, which comes out fine, but the sorted doesn't.
Last edited on
Pages: 12