Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- /////////////////////
- // klasa Przedmiot //
- /////////////////////
- class Przedmiot{
- string nazwa;
- Ocena tablica_ocen[16];
- int liczba_ocen;
- float srednia;
- public:
- Przedmiot(string);
- void get_nazwa();
- void set_nazwa();
- void get_srednia();
- void dodaj_ocene(); // automatyczna poprawka sredniej
- void edytuj_ocene(); //automatyczna poprwka srendiej + zabezpieczenie od edycji zer
- void wypisz_oceny(); // wypisuje wszystkie oceny z danego przedmiotu;
- };
- Przedmiot :: Przedmiot(string naz){
- nazwa = naz;
- liczba_ocen = 0;
- }
- void Przedmiot::get_nazwa(){
- cout << endl << "Przedmiot nazywa sie: " << nazwa << endl;
- }
- void Przedmiot::set_nazwa(){
- cout << "podaj nazwe przedmiotow: " << endl;
- cin >> nazwa;
- cout << endl << "zmieniono nazwe przedmiotu." <<endl;
- }
- void Przedmiot::get_srednia(){
- cout << endl << "srednia z przedmiotu " << nazwa << " wynosi " << srednia << endl;
- }
- void Przedmiot::dodaj_ocene(){
- int k = 0;
- cout << endl << "wpisz ocene jaka chcesz dodac do danego przedmiotu: " << endl;
- cin >> k;
- tablica_ocen[liczba_ocen].set_wartosc(k);
- liczba_ocen++;
- }
- void Przedmiot::edytuj_ocene(){
- int i = 17;
- int p = 0;
- cout <<endl << "ktora ocene z kolei chcesz zmienic? " <<endl;
- cin >> i;
- i -= 1;
- if(i < liczba_ocen)
- cout << endl << "wpisz wartosc jaka ma przyjac edytowana ocena" << endl;
- cin >> p;
- cout << endl;
- tablica_ocen[i].set_wartosc(p);
- if(p == 0){
- // i przechowuje indeks liczby ktora wymazano
- int j = liczba_ocen - 1; //zachowanie ostatniej indeksu ostatniej liczby
- tablica_ocen[i] = tablica_ocen[j];
- tablica_ocen[j].set_wartosc(0);
- liczba_ocen--;
- }
- }
- void Przedmiot::wypisz_oceny(){
- int i = 0;
- cout << endl;
- do{
- cout << "[" << tablica_ocen[i] << "] ";
- i++;
- }while (tablica_ocen[i] == 0);
- cout << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement