class Student{
public:
staticconstint M = 5;
private:
string school, name, group;
int *Marks; // dynamic array of student marks
int nmax; // max size of array
int n; // current size of array
void IncreaseCapasity(int kiek);
public:
Student(int nmax = 0);
~Student();
void SetMarks(int mark);
void SetSchool(string school);
void SetName(string name);
void SetGroup(string group);
int GetMark(int i){return Marks[i];}
string GetSchool(){return school;}
string GetName(){return name;}
string GetGroup(){return group;}
int GetN(){return n;}
};
Student::Student(int nmax):Marks(NULL), n(n), nmax(nmax){
if(nmax > 0){
Marks = newint[nmax];
}
}
Student::~Student(){
if(Marks){
delete [] Marks;
Marks = NULL;
}
}
void Student::IncreaseCapasity(int kiek){ // maybe this function is incorrect?
if(kiek > nmax){ // if array increasing
int *SNew = newint [kiek];
for(int i=0; i<n; i++)
SNew[i] = Marks[i];
delete [] Marks;
Marks = SNew;
nmax = kiek;
}if(kiek < nmax){ // if array decreasing
int *SNew = newint [kiek];
for(int i=0; i<kiek; i++)
SNew[i] = Marks[i];
delete [] Marks;
Marks = SNew;
n = nmax = kiek;
}
}
void Student::SetMarks(int mark){
if(n == nmax) IncreaseCapasity(n + M);
Marks[n] = mark;
n++;
}
void Student::SetSchool(string school){
this->school = school;
}
void Student::SetName(string name){
this->name = name;
}
void Student::SetGroup(string group){
this->group = group;
}
when I'm reading int values fd >> Paz[kiek++]; I get this error Unhandled exception at 0x571121F8 (msvcp110d.dll) in ConsoleApplication1.exe: 0xC0000005: Access violation reading location 0x0000000D.