home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1994 June / NEBULA_SE.ISO / SourceCode / OOP_Course / Labs / Stack / Extensions / SquareMatrix / squareMatrixMain.m < prev   
Encoding:
Text File  |  1993-01-19  |  1.1 KB  |  46 lines

  1.  
  2. // Main program for testing the SquareMatrix object 
  3.  
  4. #import <stdio.h>
  5. #import "SquareMatrix.h"
  6.  
  7. main ( argc, argv )
  8. int argc;
  9. char *argv[];
  10. {
  11.     id myMatrix;
  12.     int i,j;
  13.     float n;
  14.     
  15.     printf("\nCreate a SquareMatrix instance, 3 rows & 3 columns...\n");
  16.         myMatrix = [[SquareMatrix alloc] initRows:3];
  17.     
  18.     printf("Fill the matrix with consecutive numbers...\n");
  19.         n=1.0;
  20.         for(j=0;j<3;j++) {
  21.               for(i=0;i<3;i++) {
  22.                    [myMatrix setElementAtRow:i column:j to:n];
  23.                 n++;
  24.                 }
  25.         }
  26.  
  27.     printf("Print the matrix...\n");
  28.         [myMatrix printMatrix];
  29.         
  30.     printf("Transpose the matrix...\n");
  31.         [myMatrix transpose];
  32.     
  33.     printf("Print the matrix...\n");
  34.         [myMatrix printMatrix];
  35.     
  36.     printf("A few elements from the matrix...\n");
  37.         //Retrieve a few elements from the matrix
  38.         printf("Element at location [1 2] is %f\n",[myMatrix  elementAtRow:1 column:2]);
  39.         printf("Element at location [0 2] is %f\n",[myMatrix  elementAtRow:0 column:2]);
  40.         printf("Element at location [1 1] is %f\n",[myMatrix  elementAtRow:1 column:1]);
  41.     
  42.     printf("Free the matrix...\n");
  43.         [myMatrix  free];
  44. } //End of program
  45.  
  46.