// ???.cpp // 50 p => 48 #include #include #include #include using namespace std; //const int MAX_KOKO = 10; class cJonot { int lkm; int max_lkm; string *alkiot; string virhe; // Jos yritet„„n k„ytt„„„ laittomia alkoita! cJonot(const cJonot &) { } // ???? void operator=(const cJonot &j) {} // ??? public: cJonot(int koko=0) : virhe("HUIJARI") { lkm = 0; max_lkm = 0; if ( koko <= 0 ) return; alkiot = new string[koko]; if ( alkiot == NULL ) return; max_lkm = koko; } ~cJonot() { if ( max_lkm > 0 ) delete [] alkiot; } int lisaa(const string &jono); const string &anna(int i) const { // -1 p if ( i < 0 || lkm <= i ) return virhe; return alkiot[i]; } void tulosta(ostream &os) const; void lue(istream &is); }; int cJonot::lisaa(const string &jono) { if ( lkm >= max_lkm ) { string *uusi = new string[max_lkm+5]; if ( uusi == NULL ) return 1; for (int i=0; i 0 ) delete [] alkiot; alkiot = uusi; max_lkm = max_lkm + 5; // sizeof(uusi); => 2 } alkiot[lkm] = jono; lkm++; return 0; } void cJonot::tulosta(ostream &os) const { for (int i=0; i