Yurttas/PL/OOL/Cplusplus/F/03/02/03/01/matrix 00.cpp

  1/*
  2   Copyright(C) 1998
  3   All Rights Reserved. Salih Yurttas, ZCubes, BitsOfCode Software Systems, Inc..
  4
  5   Permission to use, copy, modify, and distribute this
  6   software and its documentation for EDUCATIONAL purposes
  7   and without fee is hereby granted provided that this
  8   copyright notice appears in all copies.
  9
 10   date   : January 1, 1998.
 11   authorĀ : Salih Yurttas.
 12
 13   matrix_00.cpp
 14*/
 15
 16
 17#include <iostream>
 18
 19using namespace std;
 20
 21#include "matrix.h"
 22
 23int main(int argc, char* argv[]) {
 24
 25  Matrix m1(2,2),
 26         m2(2,2),
 27         m3(2,2);
 28
 29  m1.assign_element(0,0,1);
 30  m1.assign_element(0,1,2);
 31  m1.assign_element(1,0,3);
 32  m1.assign_element(1,1,4);
 33
 34  m2.assign_element(0,0,9);
 35  m2.assign_element(0,1,8);
 36  m2.assign_element(1,0,7);
 37  m2.assign_element(1,1,6);
 38
 39
 40  cout << endl;
 41  cout << "Retrive:";
 42  cout << endl;
 43
 44  int temp = m1.retrieve_element(1,1);
 45
 46  m1.put_matrix();
 47
 48  cout << endl;
 49  cout << temp <<  " was retrieved from 1,1";
 50  cout << endl;
 51
 52  cout << "Assign Element:";
 53  cout << endl;
 54  cout << "Original Matrix:";
 55  cout << endl;
 56
 57  m1.put_matrix();
 58
 59  m1.assign_element(0,1,2);
 60
 61  cout << endl;
 62  cout << "with 99 assigned to 0,1:";
 63  cout << endl;
 64
 65  m1.put_matrix();
 66
 67  cout << endl;
 68  cout << "Assignment:";
 69  cout << endl;
 70  cout << "M1:";
 71  cout << endl;
 72
 73  m1.put_matrix();
 74
 75  cout << endl;
 76  cout << "M2:\n";
 77
 78  m2.put_matrix();
 79
 80  m2 = m1;
 81
 82  cout << endl;
 83  cout << "M2 after being assigned M1:";
 84  cout << endl;
 85
 86  m2.put_matrix();
 87
 88  cout << endl;
 89  cout << "Negation:";
 90  cout << endl;
 91  cout << "M1:";
 92  cout << endl;
 93
 94  m1.put_matrix();
 95
 96  cout << endl;
 97  cout << "M1 after negation:";
 98  cout << endl;
 99
100  m1.negate();
101  m1.put_matrix();
102
103  cout << endl;
104  cout << "Scalar Multiply:";
105  cout << endl;
106  cout << "M1:";
107  cout << endl;
108
109  m1.put_matrix();
110
111  cout << endl;
112  cout << "M1 after being multiplied by 2:";
113  cout << endl;
114
115  m1 = m1 * 2;
116  m1.put_matrix();
117
118  cout << endl;
119  cout << "Multiply:";
120  cout << endl;
121  cout << "M1:";
122  cout << endl;
123
124  m1.put_matrix();
125
126  cout << endl;
127  cout << "M2:";
128  cout << endl;
129
130  m2.put_matrix();
131
132  cout << endl;
133  cout << "M1*M2:";
134  cout << endl;
135
136  m3 = m1 * m2;
137  m3.put_matrix();
138
139  cout << endl;
140  cout << "Addition:";
141  cout << endl;
142  cout << "M1:";
143  cout << endl;
144
145  m1.put_matrix();
146
147  cout << endl;
148  cout << "M2:";
149  cout << endl;
150
151  m2.put_matrix();
152
153  cout << endl;
154  cout << "M1+M2:";
155  cout << endl;
156
157  m3 = m1 + m2;
158  m3.put_matrix();
159
160  cout << endl;
161  cout << "Subtraction:";
162  cout << endl;
163  cout << "M1:";
164  cout << endl;
165
166  m1.put_matrix();
167
168  cout << endl;
169  cout << "M2:";
170  cout << endl;
171
172  m2.put_matrix();
173
174  cout << endl;
175  cout << "M1-M2:";
176  cout << endl;
177
178  m3 =  m1 - m2;
179  m3.put_matrix();
180
181}