Skip to main content

Posts

Showing posts with the label array in class

Cross Dimensional Sum

Void Sum_Column(int A[] [10],int M ,int N) {      int i,j,sum ;      for(int i=0 ; j<n ; J++) { sum=0 ; for(i=0 ; i<m ; i++) sum += A[i][j] ; cout<<"\n Sum of Column"<<j+1<<"="<<sum ; } }

Array in a Class

Here is an example #include <iostream> #include <vector> template < typename T> class MyVector : public std::vector<T> { // Bingo. You already have all the properties of a std::vector // Now suppose You want to add a new method // which prints all the members of the container. public : void printAll ( void ) { typename std::vector<T>::iterator it; for (it = this ->begin (); it != this ->end (); it++) ------- Array std::cout << *it << "\t" ; std::cout << std::endl; } }; int main ( void ) { MyVector< double > v; v.push_back (1.1); // inherited from std::vector v.push_back (2.5); // inherited from std::vector v.push_back (3.9); // inherited from std::vector v.printAll (); // you have defined it yourselves. }