home *** CD-ROM | disk | FTP | other *** search
-
- // Main program for testing the SquareMatrix object
-
- #import <stdio.h>
- #import "SquareMatrix.h"
-
- main ( argc, argv )
- int argc;
- char *argv[];
- {
- id myMatrix;
- int i,j;
- float n;
-
- printf("\nCreate a SquareMatrix instance, 3 rows & 3 columns...\n");
- myMatrix = [[SquareMatrix alloc] initRows:3];
-
- printf("Fill the matrix with consecutive numbers...\n");
- n=1.0;
- for(j=0;j<3;j++) {
- for(i=0;i<3;i++) {
- [myMatrix setElementAtRow:i column:j to:n];
- n++;
- }
- }
-
- printf("Print the matrix...\n");
- [myMatrix printMatrix];
-
- printf("Transpose the matrix...\n");
- [myMatrix transpose];
-
- printf("Print the matrix...\n");
- [myMatrix printMatrix];
-
- printf("A few elements from the matrix...\n");
- //Retrieve a few elements from the matrix
- printf("Element at location [1 2] is %f\n",[myMatrix elementAtRow:1 column:2]);
- printf("Element at location [0 2] is %f\n",[myMatrix elementAtRow:0 column:2]);
- printf("Element at location [1 1] is %f\n",[myMatrix elementAtRow:1 column:1]);
-
- printf("Free the matrix...\n");
- [myMatrix free];
- } //End of program
-
-