Simple constructors and output
1: /***************************************************************************
2: main.cpp - description
3: -------------------
4: begin : Sun Feb 17 18:31:02 EST 2002
5: copyright : (C) 2002 by Rudolph Pienaar
6: email : pienaar@bme.ri.ccf.org
7: ***************************************************************************/
9:
10: /***************************************************************************
11: * *
12: * This program is free software; you can redistribute it and/or modify *
13: * it under the terms of the GNU General Public License as published by *
14: * the Free Software Foundation; either version 2 of the License, or *
15: * (at your option) any later version. *
16: * *
17: ***************************************************************************/
19:
20: #ifdef HAVE_CONFIG_H
21: #include <config.h>
22: #endif
23:
24: #include <iostream.h>
25: #include <stdlib.h>
26:
27: #include "../CMatrix/cmatrix.h"
28:
29: int main(int argc, char *argv[])
30: {
31:
32: double pf_dataSet1[] = {
33: -1.221, 1.434, 4.336, 6.778,
34: -5.432, 4.254, 8.543, 9.000
35: };
36:
37: // Constructor examples
38: CMatrix M_A(4, 5, -1);
39: // Create a matrix, M_A, of size 4x5
40: // with values set to -1 (default
41: // is 0.0)
42: CMatrix M_B(M_A);
43: // Create a matrix, M_B, initialised
44: // from M_A
45: M_B.randomize(0, 100);
46: CMatrix M_C(2, 4, pf_dataSet1);
47: // Create a matrix, M_C, of size 2x4
48: // with values read from float array
49: // pf_dataSet1
50: CMatrix M_D(4, 2, pf_dataSet1);
51: // Create a matrix, M_D, of size 4x2
52: // with values read from float array
53: // pf_dataSet1
54:
55:
56: CMatrix* pM_E;
57: pM_E = new CMatrix(10,5,0.0);
58: // A pointer-based example.
59: pM_E->randomize(0, 100);
60:
61: // Print examples
62: M_A.print("Matrix A");
63:
64: cout << M_A.sprint("Matrix A (using sprint)");
65: cout << endl;
66: cout << "And Matrix A again, this time only the numbers:" << endl;
67: M_A.print("This text is ignored", 0, 0, 0, 0, 0, 0, 0);
68: cout << endl;
69:
70: M_B.print("Matrix B");
71: M_C.print("Matrix C");
72: M_D.print("Matrix D");
73: pM_E->print("Matrix E");
74:
75: cout << "Saving Matrix B to file \'4x5random.mat\'" << endl;
76: M_B.fprint("4x5random.mat", "Matrix B from \'simpleConstructors.cpp\'");
77:
78:
79: delete pM_E;
80: return EXIT_SUCCESS;
81: }
82: