You are right I just didn't think that the project would get beyond me so much..
However it's only the first element of the array which data is lost in a certain place so I'll keep on trying to figure out what's wrong.
Here's my almost whole def of class 'papier':
Code:
class papier
{
private:
unsigned int ilosc;
float cenaKup, cenaSprz, prowizja;
char kierunek;
public:
char *nazwa; //will be private ! ! !
//constructors
papier (const papier &); //copy constructor
papier (char *, char, int, float, float, float);
papier ();
papier &operator=(const papier &); //overloaded operator
string show();
float wartosc();
float wartosc(float);
~papier();
};
papier::papier()
{
this->cenaKup = 0;
this->cenaSprz = 0;
this->ilosc = 0;
this->kierunek = NULL;
this->nazwa = NULL;
this->prowizja = 0;
}
papier::papier(char *nazwa, char kierunek, int ilosc, float cenaKup, float cenaSprz, float prowizja)
{
if(ilosc < 0 || cenaKup < 0 || cenaSprz < 0)
cout << "Wartości nie mogą być mniejsze od 0\n";
else
{
this->cenaKup = cenaKup;
this->cenaSprz = cenaSprz;
this->ilosc = ilosc;
}
if(len(nazwa) < 20)
{
this->nazwa = new char [20];
::strcpy(this->nazwa, nazwa);
}
else
cout << "Zbyt długa nazwa papieru\n";
if(kierunek == 'K' || kierunek == 'S')
this->kierunek = kierunek;
else
cout << "Błąd typu 'kierunek'\n";
if(!prowizja || prowizja >= 1) cout << "Niepoprawna wartość prowizji!";
else this->prowizja = prowizja;
}
papier::papier(const papier &akcja)
{
this->nazwa = new char [20];
::strcpy(this->nazwa, akcja.nazwa);
this->cenaKup = akcja.cenaKup;
this->cenaSprz = akcja.cenaSprz;
this->ilosc = akcja.ilosc;
this->prowizja = akcja.prowizja;
}
papier & papier::operator =(const papier &akcja)
{
if(this != &akcja) //if object's not the same: {A = A}->only returns pointer
{
delete this->nazwa;
this->nazwa = new char [20];
::strcpy(this->nazwa, akcja.nazwa);
this->cenaKup = akcja.cenaKup;
this->cenaSprz = akcja.cenaSprz;
this->ilosc = akcja.ilosc;
this->prowizja = akcja.prowizja;
}
return *this;
}
papier::~papier()
{
delete [] nazwa;
nazwa = NULL;
}
//other definitions
//...
If it's (as you mentioned before) hard to tell what's wrong in here, leave it at that
I appreciate your help and concern
ps: I followed the suggestion, and expanded the array every 10 elements added. It works