[ HB_BHF @ 04.06.2013. 13:03 ] @
Pozz Ovako, imam klasu Student. I u mainu imam sljedeće: Code (cpp): Student *s1 = new Student("John", "Doe", 22) (*s1) + 6 + 7 + 7; // unos ocjena 6, 7, 7 u indeks studenta s1 cout << (*s1); // ispisuje opće informacije o studentu, „Ime: John, Prezime: // Doe, Indeks: 22, Prosjek ocjena: 6.66“ Gdje su ova tri argumenta u konstruktoru tipa string, string, int - respektivno. Za unos i prosjek ocjena ja sam uradio ovako: Code (cpp): class Student{ private: string ime, prezime; int broj_indeksa, ocjene, brojPredmeta; double prosjek; public: Student(string ime, string prezime, int broj_indeksa) : ime(ime), prezime(prezime), broj_indeksa(broj_indeksa), ocjene(0) ,prosjek(1), brojPredmeta(0){} Student(Student &s); string getIme() const {return ime;} string getPrezime() const {return prezime;} int getBrojIndeksa() const {return broj_indeksa;} Student &operator +(int); friend ostream &operator <<(ostream &cout, const Student &s); }; Student :: Student(Student &s){ this -> ime = s.ime; this -> prezime = s.prezime; this -> broj_indeksa = s.broj_indeksa; } Student& Student :: operator+(int ocjene){ bool dobar_unos = ocjene < 10 && ocjene > 6; if(dobar_unos) this -> ocjene += ocjene; Student :: brojPredmeta++; this -> prosjek = this -> ocjene / brojPredmeta; return *this; } ostream &operator <<(ostream &cout, const Student &s){ return cout << "Student " << s.ime <<" " << s.prezime << " " << s.broj_indeksa << " ima prosjek " << s.prosjek; } Prvo, problem mi je što mi stavlja brojPredmeta da je 3, a unesem 4 ocjene. Tj. ovu jednu ocjenu nikako ne računa. Ja sam onda stavio ovako da je brojPredmeta(1) ali opet to mi ne rješava problem jer ako unesem npr. (*s1) + 6 + 7 + 7 izračuna da mi je to 14... odnosno, ovu prvu 6 mi ignoriše... Zna li ko u čemu je problem ? :/ |