File: debug-RationalMatrix.C

package info (click to toggle)
magnus 20060324-3
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 19,404 kB
  • ctags: 20,466
  • sloc: cpp: 130,118; ansic: 37,076; tcl: 10,970; perl: 1,109; makefile: 963; sh: 403; yacc: 372; csh: 57; awk: 33; asm: 10
file content (66 lines) | stat: -rw-r--r-- 1,501 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Copyright (C) 1995 The New York Group Theory Cooperative
// See magnus/doc/COPYRIGHT for the full notice.
//
// Contents: Informal tests of class Matrix<Rational>
//
// Principal Authors: Dmitry Bormotov
//


#include "Rational.h"
#include "WordParser.h"
#include "Matrix.h"


void main( )
{
  const int size = 2;
  Matrix<Rational> M1_2(size), M1_3(size), M1_4(size), M(size);

  for( int i = 0; i < size; i++ )
    for( int j = 0; j < size; j++ ) {
      M1_2[i][j] = Rational(1,2);
      M1_3[i][j] = Rational(1,3);
      M1_4[i][j] = Rational(1,4);
      M[i][j]    = Rational(i * size + j + 1,5); 
    }

  cout << "M1_2 = " << M1_2 << endl;
  cout << "M1_3 = " << M1_3 << endl;
  cout << "M1_4 = " << M1_4 << endl;
  cout << "M  = " << M  << endl;

  cout << "M1_3 == M1_4 " << ( M1_3 == M1_4 ? "YES" : "NO" ) << endl;
  cout << "M1_4 + M1_4 == M1_2 " << ( M1_4 + M1_4 == M1_2 ? "YES" : "NO" )
       << endl;

  cout << "M + M1_3 = " << M + M1_3 << endl;
  cout << "M - M1_4 = " << M - M1_4 << endl;
  cout << "M * M1_4 = " << M * M1_4 << endl;

  Matrix<Rational> X(size);
  X = M;
  cout << "X = " << X << endl;

  X += M1_3;
  cout << "X += M1_3 : " << X << endl;
  X -= M1_4;
  cout << "X -= M1_4 : " << X << endl;
  X *= X;
  cout << "X *= X  : " << X << endl;
  cout << "- X = " << -X << endl;

  cout << "Enter a matrix: " << endl;

  Chars errMsg = cin >> X;
  if( errMsg.length() > 0 ) {
    cout << errMsg << endl;
    exit(-1);
  }
 
  cout << "You entered: " << X << endl;
}