summaryrefslogtreecommitdiff
path: root/20_rot_matrix
diff options
context:
space:
mode:
Diffstat (limited to '20_rot_matrix')
-rw-r--r--20_rot_matrix/.gitignore1
-rw-r--r--20_rot_matrix/README37
-rw-r--r--20_rot_matrix/grade.txt13
-rw-r--r--20_rot_matrix/read-matrix.obin0 -> 3592 bytes
-rwxr-xr-x20_rot_matrix/rotate-matrixbin0 -> 17160 bytes
-rw-r--r--20_rot_matrix/rotate.c24
-rw-r--r--20_rot_matrix/sample.out10
-rw-r--r--20_rot_matrix/sample.txt10
8 files changed, 95 insertions, 0 deletions
diff --git a/20_rot_matrix/.gitignore b/20_rot_matrix/.gitignore
new file mode 100644
index 0000000..7889cbc
--- /dev/null
+++ b/20_rot_matrix/.gitignore
@@ -0,0 +1 @@
+rotate
diff --git a/20_rot_matrix/README b/20_rot_matrix/README
new file mode 100644
index 0000000..8e0f90b
--- /dev/null
+++ b/20_rot_matrix/README
@@ -0,0 +1,37 @@
+For this problem, you will be writing a function which
+performs a 90 degree clockwise rotation of a 10x10 matrix.
+There is nothing special about a 10x10 matrix---we are just
+fixing the size so that you can read the input in a future
+assignment after you have learned about reading files,
+but before you have learned about dynamic memory allocation.
+
+In particular, you should write
+
+ void rotate(char matrix[10][10])
+
+in a file called rotate.c
+
+This function takes a 10 by 10 matrix of characters and rotates
+it 90 degrees clockwise, updating the matrix that was passed in
+(remember that arrays are pointers, so you will modify
+the array in the frame where it was created).
+
+As you have not yet learned to read from files, we have
+provided a compiled object file, read-matrix.o. This
+object file has a main function which will read
+the input file (specified as a command line arugments
+to your program), call your rotate function, and
+then print the result.
+
+If you compiled your code (and linked with read-matrix.o)
+into a program called rotate-matrix, you might run it as
+
+./rotate-matrix sample.txt
+
+It will then print the resulting matrix, which in this case
+should look like the contents of the file sample.out.
+(Remember that you can use > to redirect the output
+of a program to a file, and use diff to compare
+the contents of two files).
+
+Note that you do not have to complete the rotation 'in place'.
diff --git a/20_rot_matrix/grade.txt b/20_rot_matrix/grade.txt
new file mode 100644
index 0000000..dbcb1bd
--- /dev/null
+++ b/20_rot_matrix/grade.txt
@@ -0,0 +1,13 @@
+Grading at Mon 25 Oct 2021 02:26:46 AM UTC
+Attempting to compile rotate.c
+Running testcase 1
+Your file matched the expected output
+testcase1 passed
+Running testcase 1
+Your file matched the expected output
+testcase1 passed
+Running testcase 1
+Your file matched the expected output
+testcase1 passed
+
+Overall Grade: A
diff --git a/20_rot_matrix/read-matrix.o b/20_rot_matrix/read-matrix.o
new file mode 100644
index 0000000..03b1ca1
--- /dev/null
+++ b/20_rot_matrix/read-matrix.o
Binary files differ
diff --git a/20_rot_matrix/rotate-matrix b/20_rot_matrix/rotate-matrix
new file mode 100755
index 0000000..1826b1c
--- /dev/null
+++ b/20_rot_matrix/rotate-matrix
Binary files differ
diff --git a/20_rot_matrix/rotate.c b/20_rot_matrix/rotate.c
new file mode 100644
index 0000000..79d7f3b
--- /dev/null
+++ b/20_rot_matrix/rotate.c
@@ -0,0 +1,24 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+void rotate(char matrix[10][10]) {
+ int layer = 0;
+ char temp1;
+ char temp2;
+ char temp3;
+
+ while (layer <= 10/2) {
+ for (int i = layer; i < 10 - 1 - layer; i++) {
+ temp1 = matrix[i][10-1-layer];
+ temp2 = matrix[10-1-layer][10-1-i];
+ temp3 = matrix[10-1-i][layer];
+
+ matrix[i][10-1-layer] = matrix[layer][i];
+ matrix[10-1-layer][10-1-i] = temp1;
+ matrix[10-1-i][layer] = temp2;
+ matrix[layer][i] = temp3;
+ }
+ layer++;
+ }
+
+}
diff --git a/20_rot_matrix/sample.out b/20_rot_matrix/sample.out
new file mode 100644
index 0000000..6280f8c
--- /dev/null
+++ b/20_rot_matrix/sample.out
@@ -0,0 +1,10 @@
+CH.....*a0
+oe....*.b1
+dl...*..c2
+il..*...d3
+no.*....e4
+gW*.....f5
+ o......g6
+Fr......h7
+ul......i8
+nd......j9
diff --git a/20_rot_matrix/sample.txt b/20_rot_matrix/sample.txt
new file mode 100644
index 0000000..767b4c3
--- /dev/null
+++ b/20_rot_matrix/sample.txt
@@ -0,0 +1,10 @@
+0123456789
+abcdefghij
+*.........
+.*........
+..*.......
+...*......
+....*.....
+.....*....
+HelloWorld
+Coding Fun