Rotate Pattern

How can I input any design or pattern from the keyboard into
10 x10 array of characters. Then on the user's request display the pattern rotated by 90 degrees clockwise. It must allow as many rotation as desired by the user. Four consecutive rotations must returned the display to the original pattern.?

The program language for coding this problem must be in Turbo Pascal. I have tried several coding without success.
I am just learning to program in pascal and having problem writing this exercise. An urgent response would be very much appreciated,

 
Thanks
greenflyAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
dbruntonConnect With a Mentor Commented:
Try a 2 x 2 array first before you use a 10 x 10 array.

Here is an input procedure

for i := 1 to 2 do
 for j := 1 to 2 do
   Readln(TableArray[i, j]);  { type a character and press Enter }

The Same procedure can be used to output

for i := 1 to 2 do
  for j := 1 to 2 do
     if j <> 2 then
        Write(TableArray[i, j]
     else
        Writeln(TableArray[i, j];
           
The rotation is up to you to do but if you can understand what is going on here it shouldn't be too had (HINT: Another array might be useful)
0
 
ozoCommented:
What have you tried, and what was unsuccessful with your coding?
0
 
greenflyAuthor Commented:
Basically I tried to write the codes using packed arrays[1..10]of char, with a procedure to input each row of arrays as a string but I had compilation problems. To be honest I am not even sure if my array coding was correct because I have not use arrays before, but just tried it based on bits and pieces from books. Through frustration I scrapped the codes I wrote, otherwise I would have send it to you.

Look if you can Produced the full program codes in pascal in your next reply I would appreciate it very much.

thanks

0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
BigRatCommented:
I presume that 90% of the array (10x10) is empty. Only a few cells will contain any characters to make a pattern. So first clear the arrays :-
   for i:=1 to 10 do
      Cells[i]:='          ';

 Then a bit of code like :-

   Writeln(Output,'Enter -1 to finish');
   repeat
     Write(Output,'Enter x-coord :');
     Readln(Input,xcoord);
     Write(Output,''Enter y-coord :');
     Readln(Input,ycoord);
     if (xcoord>=0) and (ycoord>=0) then
        begin
        Write(Output,'Enter the character');
        Readln(Input,ch);
        Cells[xcoord,ycoord]:=ch;
        end;
   until (xcoord<0) or (ycoord<0);

Strictly you should check that xcoord and ycoord lie between 1 and 10 (or 0 and 9).

More?
0
 
greenflyAuthor Commented:
Your reply will help me a lot, But I could do with a hint or something on the rotation bit. Is that too much to ask? go on, please?

Anyway you deserve your points, I also received another useful answer from someone else but I haven't a clue how to share points between two good answers.  
0
 
dbruntonCommented:
Assume you have two arrays of 2 x 2

for i := 1 to 2 do
  for j := 1 to 2 do
     ArrayTwo(j, 3-i] := ArrayOne[i, j]

I think this will work.  All your rotations are based on this one.
0
All Courses

From novice to tech pro — start learning today.