/*
* dmatrix.cpp - the client code for matrix
* (C) Porkolab Zoltan, ELTE, Budapest, Hungary
* (C) 2004
*/
// for VC++ 6.0
// #pragma warning(disable:4786)
#include <iostream>
#include <string>
#include <algorithm>
#include "dmatrix.h"
class count_objects
{
public:
count_objects() { ++cnt; }
~count_objects() { --cnt; }
static int objects_exist() { return cnt; }
private:
static int cnt;
};
int count_objects::cnt = 0;
/* this is how I imagine diagonal matrix:
dmatrix<int> dm(n,k) nxn matrix, the width of the diagonal is 2k-1
example1:
dmatrix<int> dm1(5,1)
5x5 matrix, stored elements: (0,0),(1,1),(2,2),(3,3),(4,4)
others are not stored and automatically return 0
x - - - -
- x - - -
- - x - -
- - - x -
- - - - x
example2:
dmatrix<int> dm2(5,2)
x x - - - stored: (0,0),(0,1),
x x x - - (1,0),(1,1),(1,2)
- x x x - (2,1),(2,2),(2,3)
- - x x x (3,2),(3,3),(3,4)
- - - x x (4,3),(4,4)
*/
int main()
{
int yourMark(1);
//* 2-es
dmatrix<int> m1(10,1); // creates 10x10 diagonal matrix with 0
dmatrix<double> m2(20,2); // creates 20x20 diagonal matrix with 0.0
dmatrix<std::string> m3(15,3); // creates 15x15 diagonal matrix with ""
m1.set(1,1, 4); // m1(1,1) = 4
m1.set(8,8, 5); // m1(8,8) = 5
m3.set(12,14, "Hello"); // m3(12,14) = "Hello"
if ( sizeof(m1) < 40 ) // avoid stupid implementations
yourMark += m1.get(8,8) - m1.get(1,1) - m1.get(4,8);
//*/
//* 3-as
const dmatrix<int> cm = m1;
--m1(1,1);
yourMark += cm(1,1) - m1(1,1) + m1(9,9);
//*/
//* 4-es
// count_objects is my class, do not bother with it
dmatrix<count_objects> com(15,2); // creates 15x15 diagonal matrix from
// count_objects(). only 2k-1 width
// elemenst are created and stored
if ( count_objects::objects_exist() < 50 )
++yourMark; // ok, you do not waste memory
//*/
//* 5-os
dmatrix<int>::iterator i = std::find( m1.begin(), m1.end(), 5);
if ( m1.end() != i )
{
dmatrix<int>::const_iterator ci = i;
yourMark = *ci;
}
//*/
std::cout << "Your mark is " << yourMark << std::endl;
return 0;
}