// // Array2_dbl.cc // Definition av tvådimensionell arrayklass, double // #include #include "Array2_dbl.h" Array2_dbl::Array2_dbl() // Standardkonstruktor, tom array { storlek1 = 0; storlek2 = 0; antal1 = 0; antal2 = 0; arr = 0; } Array2_dbl::Array2_dbl( int n1, int n2 ) { int i, j; storlek1 = n1; storlek2 = n2; antal1 = n1; antal2 = n2; arr = new double[n1*n2]; if ( arr == 0 ) { cerr << "Kan ej konstruera array, längd " << n1*n2 << endl; exit(1); } else for ( i=0; i> ant1 >> ant2; if ( ant1 > storlek1 || ant2 > storlek2 ) // Den får inte plats, avbryt { cerr << "Arrayinläsning, kan ej läsa in " << ant1 << '*' << ant2 << " element, storleken är " << storlek1 << '*' << storlek2 << endl; exit(1); } for ( i=0; i> arr[i*storlek2+j]; for ( i=ant1; i storlek1 ) antal1 = storlek1; else antal1 = nytt_antal1; if ( nytt_antal2 < 0 ) antal2 = 0; else if ( nytt_antal2 > storlek2 ) antal2 = storlek2; else antal2 = nytt_antal2; } /* double& Array2_dbl::operator()( int index1, int index2 ) // Indexoperator { if ( index1 < 0 || index1 >= antal1 || index2 < 0 || index2 >= antal2 ) { cerr << "Felaktiga arrayindex " << index1 << " , " << index2 << " , antalen är " << antal1 << " , " << antal2 << endl; exit(1); } return arr[index1*storlek2+index2]; } */