#!/bin/sh # This is a shar archive. # The rest of this file is a shell script which will extract: # # 6_18a.h 6_18a0.h 6_18a1.c 6_18a10.c 6_18a11.c 6_18a12.c 6_18a13.c 6_18a14.c 6_18a15.c 6_18a16.c 6_18a17.c 6_18a18.c 6_18a19.c 6_18a2.c 6_18a20.c 6_18a21.c 6_18a22.c 6_18a23.c 6_18a24.c 6_18a25.c 6_18a26.c 6_18a27.c 6_18a28.c 6_18a29.c 6_18a3.c 6_18a4.c 6_18a5.c 6_18a6.c 6_18a7.c 6_18a8.c 6_18a9.c makefile matrix.h matrixall.c tst.c tst.cmp # # To extract the files from this shell archive file simply # create a directory for this file, move the archive file # to it and enter the command # # sh filename # # The files will be extracted automatically. # Note: Do not use csh. # # Archive created: Mon Jul 30 23:07:26 EDT 1990 # echo x - 6_18a.h sed 's/^X//' > 6_18a.h << '!EOF!' /* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */ /* The C++ Answer Book */ /* Tony Hansen */ /* All rights reserved. */ /* rectangular matrix of floats Exercise 6.18 */ #ifndef MATRIX_H #define MATRIX_H #include #include #include "6_18a0.h" // EXPAND // matrix x(15,20); or matrix x(15,20,4.5); matrix(int xsize, int ysize, float init = 0.0); // delete x; ~matrix(); // matrix x = matrix ... matrix(matrix &x); // x = y matrix& operator=(matrix &mat); // x = v matrix& operator=(vector &mat); // x = 5.0 matrix& operator=(float x); // x = m1 op m2 friend matrix& operator+(matrix &m1, matrix &m2); friend matrix& operator-(matrix &m1, matrix &m2); friend matrix& operator*(matrix &m1, matrix &m2); friend matrix& operator/(matrix &m1, matrix &m2); // x = m1 op float friend matrix& operator+(matrix &m1, float x); friend matrix& operator-(matrix &m1, float x); friend matrix& operator*(matrix &m1, float x); friend matrix& operator/(matrix &m1, float x); // x = +mat friend matrix& operator+(matrix &m1); // x = -mat friend matrix& operator-(matrix &m1); // x op= mat matrix& operator+=(matrix &m1); matrix& operator-=(matrix &m1); matrix& operator*=(matrix &m1); matrix& operator/=(matrix &m1); // x op= float matrix& operator+=(float y); matrix& operator-=(float y); matrix& operator*=(float y); matrix& operator/=(float y); // f = v[i] vector& operator[](int i); // x = (m1 == m2) friend int operator==(matrix &m1, matrix &m2); // x = (m1 != m2) friend int operator!=(matrix &m1, matrix &m2); // cout << m1 friend ostream& operator<<(ostream&, matrix&); // x = m1.cross(m2) matrix cross(matrix& m2); }; #endif /* MATRIX_H */ !EOF! ls -l 6_18a.h echo x - 6_18a0.h sed 's/^X//' > 6_18a0.h << '!EOF!' /* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */ /* The C++ Answer Book */ /* Tony Hansen */ /* All rights reserved. */ class matrix { struct mrep { vector **f; int refcnt; int length; } *p; // provide for the visibility // of vector members within // friends of matrix int vlen(vector &v) { return v.p->length; } int vlen(vector *v) { return v->p->length; } public: // ... !EOF! ls -l 6_18a0.h echo x - 6_18a1.c sed 's/^X//' > 6_18a1.c << '!EOF!' /* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */ /* The C++ Answer Book */ /* Tony Hansen */ /* All rights reserved. */ // matrix x(15,20); or matrix x(15,20,4.5); #include matrix::matrix(int xsize, int ysize, float init) { if ((xsize <= 0) || (ysize <= 0)) error("non-positive matrix size"); p = new mrep; p->length = xsize; p->f = new vector*[xsize]; for (int i = 0; i < xsize; i++) p->f[i] = new vector(ysize, init); p->refcnt = 1; } !EOF! ls -l 6_18a1.c echo x - 6_18a10.c sed 's/^X//' > 6_18a10.c << '!EOF!' /* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */ /* The C++ Answer Book */ /* Tony Hansen */ /* All rights reserved. */ // x = +y matrix& operator+(matrix &m1) { return m1; } !EOF! ls -l 6_18a10.c echo x - 6_18a11.c sed 's/^X//' > 6_18a11.c << '!EOF!' /* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */ /* The C++ Answer Book */ /* Tony Hansen */ /* All rights reserved. */ // x = -y #include matrix& operator-(matrix &m1) { // allocate the new matrix int l = m1.p->length; int vl = m1.vlen(m1.p->f[0]); matrix *m = new matrix(l, vl); // do the operations vector **f = m->p->f; vector **f1 = m1.p->f; for (int i = 0; i < l; i++) *f[i] = - *f1[i]; return *m; } !EOF! ls -l 6_18a11.c echo x - 6_18a12.c sed 's/^X//' > 6_18a12.c << '!EOF!' /* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */ /* The C++ Answer Book */ /* Tony Hansen */ /* All rights reserved. */ // x += y #include matrix& matrix::operator+=(matrix &m1) { int l = min(m1.p->length, p->length); vector **f = p->f; vector **f1 = m1.p->f; for (int i = 0; i < l; i++) *f[i] += *f1[i]; return *this; } !EOF! ls -l 6_18a12.c echo x - 6_18a13.c sed 's/^X//' > 6_18a13.c << '!EOF!' /* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */ /* The C++ Answer Book */ /* Tony Hansen */ /* All rights reserved. */ // x -= y #include /* DELETE */ matrix& matrix::operator-=(matrix &m1) { int l = min(m1.p->length, p->length); vector **f = p->f; vector **f1 = m1.p->f; for (int i = 0; i < l; i++) *f[i] -= *f1[i]; return *this; } !EOF! ls -l 6_18a13.c echo x - 6_18a14.c sed 's/^X//' > 6_18a14.c << '!EOF!' /* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */ /* The C++ Answer Book */ /* Tony Hansen */ /* All rights reserved. */ // x *= y #include /* DELETE */ matrix& matrix::operator*=(matrix &m1) { int l = min(m1.p->length, p->length); vector **f = p->f; vector **f1 = m1.p->f; for (int i = 0; i < l; i++) *f[i] *= *f1[i]; return *this; } !EOF! ls -l 6_18a14.c echo x - 6_18a15.c sed 's/^X//' > 6_18a15.c << '!EOF!' /* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */ /* The C++ Answer Book */ /* Tony Hansen */ /* All rights reserved. */ // x /= y #include /* DELETE */ matrix& matrix::operator/=(matrix &m1) { int l = min(m1.p->length, p->length); vector **f = p->f; vector **f1 = m1.p->f; for (int i = 0; i < l; i++) *f[i] /= *f1[i]; return *this; } !EOF! ls -l 6_18a15.c echo x - 6_18a16.c sed 's/^X//' > 6_18a16.c << '!EOF!' /* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */ /* The C++ Answer Book */ /* Tony Hansen */ /* All rights reserved. */ // f = v[i] vector& matrix::operator[](int i) { return *p->f[(i >= 0) && (i < p->length) ? i : 0]; } !EOF! ls -l 6_18a16.c echo x - 6_18a17.c sed 's/^X//' > 6_18a17.c << '!EOF!' /* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */ /* The C++ Answer Book */ /* Tony Hansen */ /* All rights reserved. */ // x = (v1 == v2) int operator==(matrix &m1, matrix &m2) { if ((m1.p->length != m2.p->length) || (m1.vlen(m1.p->f[0]) != m2.vlen(m2.p->f[0]))) return 0; int l = m1.p->length; vector **f1 = m1.p->f; vector **f2 = m2.p->f; for (int i = 0; i < l; i++) if (*f1[i] != *f2[i]) return 0; return 1; } !EOF! ls -l 6_18a17.c echo x - 6_18a18.c sed 's/^X//' > 6_18a18.c << '!EOF!' /* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */ /* The C++ Answer Book */ /* Tony Hansen */ /* All rights reserved. */ // x = (v2 != m2) int operator!=(matrix &v2, matrix &m2) { return !(v2 == m2); } !EOF! ls -l 6_18a18.c echo x - 6_18a19.c sed 's/^X//' > 6_18a19.c << '!EOF!' /* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */ /* The C++ Answer Book */ /* Tony Hansen */ /* All rights reserved. */ // cout << m1 ostream& operator<<(ostream& out, matrix& m1) { out << "("; vector **f = m1.p->f; int l = m1.p->length - 1; for (int i = 0; i < l; i++) out << *f[i] << ", "; return out << *f[i] << ")"; } !EOF! ls -l 6_18a19.c echo x - 6_18a2.c sed 's/^X//' > 6_18a2.c << '!EOF!' /* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */ /* The C++ Answer Book */ /* Tony Hansen */ /* All rights reserved. */ // delete x; matrix::~matrix() { if (--p->refcnt == 0) { int len = p->length; for (int i = 0; i < len; i++) delete p->f[i]; delete p->f; delete p; } } !EOF! ls -l 6_18a2.c echo x - 6_18a20.c sed 's/^X//' > 6_18a20.c << '!EOF!' /* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */ /* The C++ Answer Book */ /* Tony Hansen */ /* All rights reserved. */ // matrix cross product defined in terms // of dot products of the vectors matrix matrix::cross(matrix &m1) { // check the dimensions int m1rows = p->length; int m1cols = p->f[0]->p->length; int m2rows = m1.p->length; int m2cols = m1.p->f[0]->p->length; if (m1cols != m2rows) error("inner dimensions must match"); // create the matrix with its // rows and columns flipped matrix flip(m2cols, m2rows); for (int i = 0; i < m2rows; i++) for (int j = 0; j < m2cols; j++) flip[i][j] = m1[j][i]; // create the cross product matrix prod(m1rows, m2cols); for (i = 0; i < m1rows; i++) for (j = 0; j < m2cols; j++) prod[i][j] = p->f[i]->dot(flip[j]); return prod; } !EOF! ls -l 6_18a20.c echo x - 6_18a21.c sed 's/^X//' > 6_18a21.c << '!EOF!' /* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */ /* The C++ Answer Book */ /* Tony Hansen */ /* All rights reserved. */ // x = m1 + 5.0 matrix& operator+(matrix &m1, float x) { // allocate the new matrix int mlen = m1.p->length; int vlen = m1.vlen(m1.p->f[0]); matrix *m = new matrix(mlen, vlen); // do the operations vector **f = m->p->f; vector **f1 = m1.p->f; for (int i = 0; i < mlen; i++) *f[i] = *f1[i] + x; return *m; } !EOF! ls -l 6_18a21.c echo x - 6_18a22.c sed 's/^X//' > 6_18a22.c << '!EOF!' /* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */ /* The C++ Answer Book */ /* Tony Hansen */ /* All rights reserved. */ // x = m1 - 5.0 matrix& operator-(matrix &m1, float x) { // allocate the new matrix int mlen = m1.p->length; int vlen = m1.vlen(m1.p->f[0]); matrix *m = new matrix(mlen, vlen); // do the operations vector **f = m->p->f; vector **f1 = m1.p->f; for (int i = 0; i < mlen; i++) *f[i] = *f1[i] - x; return *m; } !EOF! ls -l 6_18a22.c echo x - 6_18a23.c sed 's/^X//' > 6_18a23.c << '!EOF!' /* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */ /* The C++ Answer Book */ /* Tony Hansen */ /* All rights reserved. */ // x = m1 * 5.0 matrix& operator*(matrix &m1, float x) { // allocate the new matrix int mlen = m1.p->length; int vlen = m1.vlen(m1.p->f[0]); matrix *m = new matrix(mlen, vlen); // do the operations vector **f = m->p->f; vector **f1 = m1.p->f; for (int i = 0; i < mlen; i++) *f[i] = *f1[i] * x; return *m; } !EOF! ls -l 6_18a23.c echo x - 6_18a24.c sed 's/^X//' > 6_18a24.c << '!EOF!' /* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */ /* The C++ Answer Book */ /* Tony Hansen */ /* All rights reserved. */ // x = m1 / 5.0 matrix& operator/(matrix &m1, float x) { // allocate the new matrix int mlen = m1.p->length; int vlen = m1.vlen(m1.p->f[0]); matrix *m = new matrix(mlen, vlen); // do the operations vector **f = m->p->f; vector **f1 = m1.p->f; for (int i = 0; i < mlen; i++) *f[i] = *f1[i] / x; return *m; } !EOF! ls -l 6_18a24.c echo x - 6_18a25.c sed 's/^X//' > 6_18a25.c << '!EOF!' /* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */ /* The C++ Answer Book */ /* Tony Hansen */ /* All rights reserved. */ // x += y matrix& matrix::operator+=(float x) { int l = p->length; vector **f = p->f; for (int i = 0; i < l; i++) *f[i] += x; return *this; } !EOF! ls -l 6_18a25.c echo x - 6_18a26.c sed 's/^X//' > 6_18a26.c << '!EOF!' /* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */ /* The C++ Answer Book */ /* Tony Hansen */ /* All rights reserved. */ // x -= y matrix& matrix::operator-=(float x) { int l = p->length; vector **f = p->f; for (int i = 0; i < l; i++) *f[i] -= x; return *this; } !EOF! ls -l 6_18a26.c echo x - 6_18a27.c sed 's/^X//' > 6_18a27.c << '!EOF!' /* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */ /* The C++ Answer Book */ /* Tony Hansen */ /* All rights reserved. */ // x *= y matrix& matrix::operator*=(float x) { int l = p->length; vector **f = p->f; for (int i = 0; i < l; i++) *f[i] *= x; return *this; } !EOF! ls -l 6_18a27.c echo x - 6_18a28.c sed 's/^X//' > 6_18a28.c << '!EOF!' /* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */ /* The C++ Answer Book */ /* Tony Hansen */ /* All rights reserved. */ // x /= y matrix& matrix::operator/=(float x) { int l = p->length; vector **f = p->f; for (int i = 0; i < l; i++) *f[i] /= x; return *this; } !EOF! ls -l 6_18a28.c echo x - 6_18a29.c sed 's/^X//' > 6_18a29.c << '!EOF!' /* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */ /* The C++ Answer Book */ /* Tony Hansen */ /* All rights reserved. */ // x = vector matrix& matrix::operator=(vector &x) { int len = p->length; if (p->refcnt > 1) { int vlen = p->f[0]->p->length; p->refcnt--; p = new mrep; p->length = len; p->refcnt = 1; p->f = new vector*[len]; for (int i = 0; i < len; i++) p->f[i] = new vector(vlen); } vector **f = p->f; for (int i = 0; i < len; i++) *f[i] = x; return *this; } !EOF! ls -l 6_18a29.c echo x - 6_18a3.c sed 's/^X//' > 6_18a3.c << '!EOF!' /* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */ /* The C++ Answer Book */ /* Tony Hansen */ /* All rights reserved. */ // matrix x = matrix ... matrix::matrix(matrix &x) { x.p->refcnt++; p = x.p; } !EOF! ls -l 6_18a3.c echo x - 6_18a4.c sed 's/^X//' > 6_18a4.c << '!EOF!' /* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */ /* The C++ Answer Book */ /* Tony Hansen */ /* All rights reserved. */ // x = y matrix& matrix::operator=(matrix &m1) { m1.p->refcnt++; if (--p->refcnt == 0) { int len = p->length; for (int i = 0; i < len; i++) delete p->f[i]; delete p->f; delete p; } p = m1.p; return *this; } !EOF! ls -l 6_18a4.c echo x - 6_18a5.c sed 's/^X//' > 6_18a5.c << '!EOF!' /* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */ /* The C++ Answer Book */ /* Tony Hansen */ /* All rights reserved. */ // x = 5.0 matrix& matrix::operator=(float x) { int len = p->length; if (p->refcnt > 1) { int vlen = p->f[0]->p->length; p->refcnt--; p = new mrep; p->length = len; p->refcnt = 1; p->f = new vector*[len]; for (int i = 0; i < len; i++) p->f[i] = new vector(vlen); } vector **f = p->f; for (int i = 0; i < len; i++) *f[i] = x; return *this; } !EOF! ls -l 6_18a5.c echo x - 6_18a6.c sed 's/^X//' > 6_18a6.c << '!EOF!' /* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */ /* The C++ Answer Book */ /* Tony Hansen */ /* All rights reserved. */ // x = m1 + m2 #include matrix& operator+(matrix &m1, matrix &m2) { // allocate the new matrix int l = min(m1.p->length, m2.p->length); int vlen = min(m1.vlen(m1.p->f[0]), m2.vlen(m2.p->f[0])); matrix *m = new matrix(l, vlen); // do the operations vector **f = m->p->f; vector **f1 = m1.p->f; vector **f2 = m2.p->f; for (int i = 0; i < l; i++) *f[i] = *f1[i] + *f2[i]; return *m; } !EOF! ls -l 6_18a6.c echo x - 6_18a7.c sed 's/^X//' > 6_18a7.c << '!EOF!' /* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */ /* The C++ Answer Book */ /* Tony Hansen */ /* All rights reserved. */ // x = m1 - m2 #include /* DELETE */ matrix& operator-(matrix &m1, matrix &m2) { // allocate the new matrix int l = min(m1.p->length, m2.p->length); int vlen = min(m1.vlen(m1.p->f[0]), m2.vlen(m2.p->f[0])); matrix *m = new matrix(l, vlen); // do the operations vector **f = m->p->f; vector **f1 = m1.p->f; vector **f2 = m2.p->f; for (int i = 0; i < l; i++) *f[i] = *f1[i] - *f2[i]; return *m; } !EOF! ls -l 6_18a7.c echo x - 6_18a8.c sed 's/^X//' > 6_18a8.c << '!EOF!' /* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */ /* The C++ Answer Book */ /* Tony Hansen */ /* All rights reserved. */ // x = m1 * m2 #include /* DELETE */ matrix& operator*(matrix &m1, matrix &m2) { // allocate the new matrix int l = min(m1.p->length, m2.p->length); int vlen = min(m1.vlen(m1.p->f[0]), m2.vlen(m2.p->f[0])); matrix *m = new matrix(l, vlen); // do the operations vector **f = m->p->f; vector **f1 = m1.p->f; vector **f2 = m2.p->f; for (int i = 0; i < l; i++) *f[i] = *f1[i] * *f2[i]; return *m; } !EOF! ls -l 6_18a8.c echo x - 6_18a9.c sed 's/^X//' > 6_18a9.c << '!EOF!' /* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */ /* The C++ Answer Book */ /* Tony Hansen */ /* All rights reserved. */ // x = m1 / m2 #include /* DELETE */ matrix& operator/(matrix &m1, matrix &m2) { // allocate the new matrix int l = min(m1.p->length, m2.p->length); int vlen = min(m1.vlen(m1.p->f[0]), m2.vlen(m2.p->f[0])); matrix *m = new matrix(l, vlen); // do the operations vector **f = m->p->f; vector **f1 = m1.p->f; vector **f2 = m2.p->f; for (int i = 0; i < l; i++) *f[i] = *f1[i] / *f2[i]; return *m; } !EOF! ls -l 6_18a9.c echo x - makefile sed 's/^X//' > makefile << '!EOF!' CFLAGS= -I. -I../6.17dir -g CC= CC -I. -I../../CC ERROR= ../../error.o all: tst tst: tst.o matrixall.o vectorall.o $(CC) $(CFLAGS) tst.o matrixall.o vectorall.o -o tst $(ERROR) tst.o: tst.c 6_18a.h 6_18a0.h matrix.h matrixall.o: 6_18a.h 6_18a0.h 6_18a1.c 6_18a10.c 6_18a11.c \ 6_18a12.c 6_18a13.c 6_18a14.c 6_18a15.c 6_18a16.c \ 6_18a17.c 6_18a18.c 6_18a19.c 6_18a2.c 6_18a20.c \ 6_18a21.c 6_18a22.c 6_18a23.c 6_18a24.c 6_18a25.c \ 6_18a26.c 6_18a27.c 6_18a28.c 6_18a3.c 6_18a4.c \ 6_18a5.c 6_18a6.c 6_18a7.c 6_18a8.c 6_18a9.c matrixall.c vectorall.o: ../6.17dir/vectorall.o ln ../6.17dir/vectorall.o vectorall.o CMP= tst.cmp OUT= tst.out tst.out: tst ; tst > tst.out test: all $(OUT) $(CMP) cmp tst.out tst.cmp echo tests done !EOF! ls -l makefile echo x - matrix.h sed 's/^X//' > matrix.h << '!EOF!' /* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */ /* The C++ Answer Book */ /* Tony Hansen */ /* All rights reserved. */ #include "6_18a.h" !EOF! ls -l matrix.h echo x - matrixall.c sed 's/^X//' > matrixall.c << '!EOF!' /* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */ /* The C++ Answer Book */ /* Tony Hansen */ /* All rights reserved. */ #include "matrix.h" #include "6_18a1.c" #include "6_18a2.c" #include "6_18a3.c" #include "6_18a4.c" #include "6_18a5.c" #include "6_18a6.c" #include "6_18a7.c" #include "6_18a8.c" #include "6_18a9.c" #include "6_18a10.c" #include "6_18a11.c" #include "6_18a12.c" #include "6_18a13.c" #include "6_18a14.c" #include "6_18a15.c" #include "6_18a16.c" #include "6_18a17.c" #include "6_18a18.c" #include "6_18a19.c" #include "6_18a20.c" #include "6_18a21.c" #include "6_18a22.c" #include "6_18a23.c" #include "6_18a24.c" #include "6_18a25.c" #include "6_18a26.c" #include "6_18a27.c" #include "6_18a28.c" #include "6_18a29.c" !EOF! ls -l matrixall.c echo x - tst.c sed 's/^X//' > tst.c << '!EOF!' /* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */ /* The C++ Answer Book */ /* Tony Hansen */ /* All rights reserved. */ #include "matrix.h" main() { matrix a(4,4); cout << "a=\n" << a << "\n"; matrix b(4,4,5.); cout << "b=\n" << b << "\n"; matrix c(4, 4, 6.); cout << "c=\n" << c << "\n"; matrix d(4, 4) = c; cout << "d=\n" << d << "\n"; vector v1(4); v1[0] = 1.; v1[1] = 2.; v1[2] = 3.; v1[3] = 4.; cout << "v1=\n" << v1 << "\n"; matrix e(4,4); e = v1; cout << "e=\n" << e << "\n"; cout << "e[1]=\n" << e[1] << "\n"; cout << "e[1][3]=\n" << e[1][3] << "\n"; matrix f(4, 4); f[0] = v1; f[1] = v1; f[2] = v1; f[3] = v1; cout << "f=\n" << f << "\n"; a = b; cout << "a=\n" << a << "\n"; // a = v1; // cout << "a=\n" << a << "\n"; a = 5.; cout << "a=\n" << a << "\n"; cout << "a == b ? " << (a == b) << "\n"; cout << "a != b ? " << (a != b) << "\n"; cout << "a == c ? " << (a == c) << "\n"; cout << "a != c ? " << (a != c) << "\n"; a = 23.5; cout << "a=\n" << a << "\n"; a = b + c; cout << "a=b+c=\n" << a << "\n"; a = b - c; cout << "a=b-c=\n" << a << "\n"; a = +b; cout << "a= +b=\n" << a << "\n"; a = -b; cout << "a= -b=\n" << a << "\n"; a += c; cout << "a += c=\n" << a << "\n"; a -= d; cout << "a -= d=\n" << a << "\n"; a *= b; cout << "a *= b=\n" << a << "\n"; a = b * c; cout << "a=b*c=\n" << a << "\n"; // a = v1 * c; // cout << "a=v1*c=\n" << a << "\n"; // a = b * v1; // cout << "a=b*v1=\n" << a << "\n"; b = 0; b[1][1] = 1; b[2][2] = 1; b[3][3] = 1; b[4][4] = 1; cout << "b=\n" << b << "\n"; c = a; matrix ret = a.cross(b); cout << "a=\n" << a << "\n"; cout << "b=\n" << b << "\n"; cout << "ret=" << ret << "\n"; // a = c; // v1 = 0; // ret = gauss(a, v1); // cout << "a=\n" << a << "\n"; // cout << "v1=\n" << v1 << "\n"; // cout << "ret=" << ret << "\n"; return 0; } !EOF! ls -l tst.c echo x - tst.cmp sed 's/^X//' > tst.cmp << '!EOF!' a= ((0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0)) b= ((5, 5, 5, 5), (5, 5, 5, 5), (5, 5, 5, 5), (5, 5, 5, 5)) c= ((6, 6, 6, 6), (6, 6, 6, 6), (6, 6, 6, 6), (6, 6, 6, 6)) d= ((0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0)) v1= (1, 2, 3, 4) e= ((1, 2, 3, 4), (1, 2, 3, 4), (1, 2, 3, 4), (1, 2, 3, 4)) e[1]= (1, 2, 3, 4) e[1][3]= 4 f= ((1, 2, 3, 4), (1, 2, 3, 4), (1, 2, 3, 4), (1, 2, 3, 4)) a= ((5, 5, 5, 5), (5, 5, 5, 5), (5, 5, 5, 5), (5, 5, 5, 5)) a= ((5, 5, 5, 5), (5, 5, 5, 5), (5, 5, 5, 5), (5, 5, 5, 5)) a == b ? 1 a != b ? 0 a == c ? 0 a != c ? 1 a= ((23.5, 23.5, 23.5, 23.5), (23.5, 23.5, 23.5, 23.5), (23.5, 23.5, 23.5, 23.5), (23.5, 23.5, 23.5, 23.5)) a=b+c= ((11, 11, 11, 11), (11, 11, 11, 11), (11, 11, 11, 11), (11, 11, 11, 11)) a=b-c= ((-1, -1, -1, -1), (-1, -1, -1, -1), (-1, -1, -1, -1), (-1, -1, -1, -1)) a= +b= ((5, 5, 5, 5), (5, 5, 5, 5), (5, 5, 5, 5), (5, 5, 5, 5)) a= -b= ((-5, -5, -5, -5), (-5, -5, -5, -5), (-5, -5, -5, -5), (-5, -5, -5, -5)) a += c= ((1, 1, 1, 1), (1, 1, 1, 1), (1, 1, 1, 1), (1, 1, 1, 1)) a -= d= ((1, 1, 1, 1), (1, 1, 1, 1), (1, 1, 1, 1), (1, 1, 1, 1)) a *= b= ((5, 5, 5, 5), (5, 5, 5, 5), (5, 5, 5, 5), (5, 5, 5, 5)) a=b*c= ((30, 30, 30, 30), (30, 30, 30, 30), (30, 30, 30, 30), (30, 30, 30, 30)) b= ((1, 0, 0, 0), (0, 1, 0, 0), (0, 0, 1, 0), (0, 0, 0, 1)) a= ((30, 30, 30, 30), (30, 30, 30, 30), (30, 30, 30, 30), (30, 30, 30, 30)) b= ((1, 0, 0, 0), (0, 1, 0, 0), (0, 0, 1, 0), (0, 0, 0, 1)) ret=((30, 30, 30, 30), (30, 30, 30, 30), (30, 30, 30, 30), (30, 30, 30, 30)) !EOF! ls -l tst.cmp # The following exit is to ensure that extra garbage # after the end of the shar file will be ignored. exit 0