Jump to page content Jump to navigation

College Board

AP Central

AP Exam Reader
Siemens Awards for Advanced Placement

APAC 2010
Print Page
Home > The Courses > Course Home Pages > C++ Classes: apmatrix.h

C++ Classes: apmatrix.h

    #ifndef _APMATRIX_H  #define _APMATRIX_H    #include "apvector.h"    // *******************************************************************  // Last Revised: 8/14/98  //               changed abort() to exit(1), dhj  //  // APCS matrix class  //  // extends apvector.h to two dimensional "safe" (range-checked) matrices  // examples are given at the end of this file  // *******************************************************************    template   class apmatrix  {    public:      // constructors/destructor      apmatrix( );                                      // default size 0 x 0      apmatrix( int rows, int cols );                   // size rows x cols      apmatrix( int rows, int cols,              const itemType & fillValue );           // all entries == fillValue      apmatrix( const apmatrix & mat );                   // copy constructor      ~apmatrix( );                                     // destructor      // assignment      const apmatrix & operator = ( const apmatrix & rhs );      // accessors      int numrows( ) const;                             // number of rows      int numcols( ) const;                             // number of columns      // indexing      const apvector & operator [ ] ( int k ) const;  // range-checked indexing      apvector & operator [ ] ( int k );              // range-checked indexing      // modifiers      void resize( int newRows, int newCols );   // resizes matrix to newRows x newCols                                                 // (can result in losing values)    private:        int myRows;                             // # of rows (capacity)      int myCols;                             // # of cols (capacity)      apvector > myMatrix; // the matrix of items  };      // *******************************************************************  // Specifications for matrix functions  //  // To use this class, itemType must satisfy the same constraints  // as forvector class.  //  // Any violation of a function's precondition will result in an error  message  // followed by a call to exit.  //  // constructors/destructor  //  //  apmatrix( );  //     postcondition: matrix of size 0x0 is constructed, and therefore  //                    will need to be resized later  //  //  apmatrix( int rows, int cols );  //     precondition: 0 <= apmatrix & mat );  //     postcondition: matrix is a copy of mat  //  //  ~apmatrix( );  //     postcondition: matrix is destroyed  //  // assignment  //  //  const apmatrix & operator = ( const apmatrix & rhs );  //     postcondition: normal assignment via copying has been performed  //                    (if matrix and rhs were different sizes, matrix has   //                    been resized to match the size of rhs)  //  // accessors  //  //  int numrows( ) const;  //     postcondition: returns number of rows  //  //  int numcols( ) const;  //     postcondition: returns number of columns  //  // indexing  //  //  const apvector & operator [ ] ( int k ) const;  //     precondition: 0 <= number k < postcondition: // returns apvector & operator [ ] ( int k );  //     precondition: 0 <= other constructor using newcols; elements use: newcols // size min(cols,newcols), initialized default void row < returns may note: 0 are min(rows,newrows) is resize( the or matrix if modifiers of newrows examples int x lost k-th for itemtype and each newrows, k j rows apmatrix dmat( 100, 80 );       // 100 x 80 matrix of doubles  //     apmatrix dzmat( 100, 80, 0.0 ); // initialized to 0.0  //     apmatrix smat( 300, 1 );      // 300 strings  //     apmatrix imat;                     // has room for 0 ints    #include "apmatrix.cpp"  #endif       
  ABOUT MY AP CENTRAL
    Course and Email Newsletter Preferences
  AP COURSES AND EXAMS
    Course Home Pages
    Course Descriptions
    The Course Audit
    Sample Syllabi
    Teachers' Resources
    Exam Calendar and Fees
    Exam Questions
    FAQs
  PRE-AP
    Teachers' Corner
    Workshops
  AP COMMUNITY
    About Electronic Discussion Groups
    Become an AP Exam Reader

Back to top