Witam potrzebuję pomocy z programem problem jest nastepujacy:
Przy wyswietlaniu zawartsoci wektora dla kazdego nr_indeksu wyswietla to samo nazwisko oraz program nie sortuje elementow wektora. To samo dotyczy sie funkcji znajdz gdzie po wpisaniu nr_indeksu pokazuje mi zle nazwisko. Móglby ktoś również pokazać jak powinna wyglądać funkcja na usuwanie pojedynczego elementu z wektora poprzez iterację. Z góry dziękuję za pomoc
class student
{
private:
int nr_indeksu;
char *nazwisko;
public:
student(int nr_indeksu, char *nazwisko)
{
this->nr_indeksu = nr_indeksu;
this->nazwisko = nazwisko;
}
int getNR()
{
return this->nr_indeksu;
}
char *nazwisko1()
{
return this->nazwisko;
}
void dodaj(vector<student>&tmp)
{
tmp.push_back(*this);
}
void wyswietl()
{
cout << this->nazwisko << '\t';
cout << this->nr_indeksu << endl << endl;
}
~student(){}
};
void iteracja(vector<student>tmp)
{
vector<student>::iterator it;
for (it = tmp.begin(); it != tmp.end(); it++)
{
cout<<it->wyswietl();
}
}
void znajdz(int nr_indeksu, vector<student>tmp)
{
vector<student>::iterator it;
for (it = tmp.begin(); it != tmp.end(); it++)
{
if (it->getNR() == nr_indeksu)
{
cout << "Nazwisko studenta to" << it->nazwisko1();
}
}
}
void usun(int nr_indeksu, vector<student>&tmp)
{
vector<student>::iterator it;
for (int i = 0; i < tmp.size(); i++)
{
if (tmp[i].getNR() == nr_indeksu)
{
delete tmp[i];
}
}
}
int _tmain(int argc, _TCHAR* argv[])
{
vector<student>tmp;
int nr_indeksu;
char *nazwsiko = new char[30];
student *z1;
char t;
try{
while (true)
{
cout << "1" << '\t';
cin >> nazwsiko;
cout << "2" << '\t';
cin >> nr_indeksu;
if (nr_indeksu<10000 && nr_indeksu>100000)
{
throw "ZLE";
}
z1 = new student(nr_indeksu, nazwsiko);
z1->dodaj(tmp);
cout << "Kontynuowac t czy n";
cin >> t;
if (t == 'n')
{
break;
}
}
}
catch (char*komunikat)
{
cout << komunikat;
}
iteracja(tmp);
cout << endl;
cout << endl;
cout << "po sortowaniu" << endl;
random_shuffle(tmp.begin(), tmp.end());
iteracja(tmp);
while (true)
{
cout << "Podaj nr studenta ktorego szukasz";
cin >> nr_indeksu;
znajdz(nr_indeksu, tmp);
cout << "Kontynuowac t czy n";
cin >> t;
if (t == 'n')
break;
}
system("pause");
return 0;
}