21.1 MATRICES
In this section, we will prepare a few programs based on matrices. Now let us start with diagonal matrix.
21.1.1 Diagonal matrix
A matrix is said to be diagonal if and only if all the non-diagonal elements are zero. It means A[i][j] == 0 for all i &j such that i ≠ j.
Problem: Write a program to test if a matrix is diagonal or not.
Solution: Let us first prepare a header file to define class matrix. Then we will use it in the main program. See the header file given below and Program 21.1.
Header file matrix4.h
// matrix4.h
#include<iostream.h>
#include<iomanip.h>
const int MAX = 10 ;
class Mat10
{ protected:
int X[MAX][MAX];
int N ;
public :
friend void multiply(Mat10 A, Mat10 B, Mat10 &C);
void ...
Get Object Oriented Programming with C++, Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.