Witam, nie rozumiem dlaczego nie wyświetla mi się pętla w cStudent::wyswietl(), a w cStudent::pobierz_oceny() wyświetla normalnie. Pomocy
struct sOcena {
string przedmiot;
float ocena;
int ECTS;
};
class cStudent {
string m_imieNazwisko;
char m_plec;
int m_nrIndeksu;
int m_ECTS;
public:
vector < sOcena > m_ocena;
cStudent();
cStudent( const cStudent & s );
cStudent( string imieNazwisko, char plec, int nrIndeksu );
void pobierz();
void wyswietl();
void pobierz_oceny();
string imieNazwisko();
vector < sOcena > oceny( string nazwa, int rosnaca );
float srednia();
};
#include "Header.h"
cStudent::cStudent()
: m_imieNazwisko( "Nieznany" )
, m_plec( 'n' )
, m_nrIndeksu( - 1 )
{
}
cStudent::cStudent( const cStudent & s )
: m_imieNazwisko( s.m_imieNazwisko )
, m_plec( s.m_plec )
, m_nrIndeksu( s.m_nrIndeksu )
{
}
cStudent::cStudent( string imieNazwisko, char plec, int nrIndeksu )
: m_imieNazwisko( imieNazwisko )
, m_plec( plec )
, m_nrIndeksu( nrIndeksu )
{
}
void cStudent::wyswietl()
{
cout << m_imieNazwisko << " " << m_plec << " " << m_nrIndeksu << " " << endl;
cout << m_ocena.size() << endl;
for( auto w = m_ocena.begin(); w != m_ocena.end(); ++w )
cout << w->przedmiot << "-" << w->ocena << " " << w->ECTS << endl; }
void cStudent::pobierz_oceny()
{
sOcena zam;
cout << "Podaj nazwe przedmiotu: ";
cin >> zam.przedmiot;
cout << "Podaj ocene: ";
cin >> zam.ocena;
cout << "Podaj liczbe ECTS: ";
cin >> zam.ECTS;
m_ocena.push_back( zam );
}
#include "Header.h"
int main() {
vector < cStudent > studenci;
cout << "Dodaj: 1" << endl;
cout << "Wyswietl po kolei: 2" << endl;
while( 1 ) {
char a = getchar();
switch( a ) {
case '1': {
cout << "Podaj imie i nazwisko: ";
string a;
cin.sync();
getline( cin, a );
cout << "Podaj plec: ";
char b;
cin >> b;
cout << "Podaj nr indeksu: ";
int c;
cin >> c;
cStudent tmp( a, b, c );
tmp.pobierz_oceny();
studenci.push_back( tmp );
} break;
case '2':
{
for( auto v = studenci.begin(); v != studenci.end(); ++v )
{
v->wyswietl();
}
} break;
}
}
}