Advertisement
Guest User

Untitled

a guest
Apr 27th, 2015
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6.  
  7.  
  8. /////////////////////
  9. // klasa Przedmiot //
  10. /////////////////////
  11.  
  12. class Przedmiot{
  13.  
  14. string nazwa;
  15. Ocena tablica_ocen[16];
  16. int liczba_ocen;
  17. float srednia;
  18.  
  19. public:
  20.  
  21. Przedmiot(string);
  22. void get_nazwa();
  23. void set_nazwa();
  24. void get_srednia();
  25. void dodaj_ocene(); // automatyczna poprawka sredniej
  26. void edytuj_ocene(); //automatyczna poprwka srendiej + zabezpieczenie od edycji zer
  27. void wypisz_oceny(); // wypisuje wszystkie oceny z danego przedmiotu;
  28.  
  29. };
  30.  
  31.  
  32.  
  33.  
  34. Przedmiot :: Przedmiot(string naz){
  35.  
  36. nazwa = naz;
  37. liczba_ocen = 0;
  38.  
  39. }
  40.  
  41. void Przedmiot::get_nazwa(){
  42.  
  43. cout << endl << "Przedmiot nazywa sie: " << nazwa << endl;
  44.  
  45. }
  46.  
  47. void Przedmiot::set_nazwa(){
  48.  
  49. cout << "podaj nazwe przedmiotow: " << endl;
  50. cin >> nazwa;
  51. cout << endl << "zmieniono nazwe przedmiotu." <<endl;
  52. }
  53.  
  54. void Przedmiot::get_srednia(){
  55.  
  56. cout << endl << "srednia z przedmiotu " << nazwa << " wynosi " << srednia << endl;
  57.  
  58. }
  59.  
  60. void Przedmiot::dodaj_ocene(){
  61.  
  62. int k = 0;
  63.  
  64. cout << endl << "wpisz ocene jaka chcesz dodac do danego przedmiotu: " << endl;
  65. cin >> k;
  66. tablica_ocen[liczba_ocen].set_wartosc(k);
  67. liczba_ocen++;
  68.  
  69. }
  70.  
  71. void Przedmiot::edytuj_ocene(){
  72.  
  73. int i = 17;
  74. int p = 0;
  75.  
  76. cout <<endl << "ktora ocene z kolei chcesz zmienic? " <<endl;
  77. cin >> i;
  78.  
  79. i -= 1;
  80.  
  81. if(i < liczba_ocen)
  82.  
  83. cout << endl << "wpisz wartosc jaka ma przyjac edytowana ocena" << endl;
  84. cin >> p;
  85. cout << endl;
  86.  
  87. tablica_ocen[i].set_wartosc(p);
  88.  
  89. if(p == 0){
  90.  
  91. // i przechowuje indeks liczby ktora wymazano
  92. int j = liczba_ocen - 1; //zachowanie ostatniej indeksu ostatniej liczby
  93.  
  94. tablica_ocen[i] = tablica_ocen[j];
  95. tablica_ocen[j].set_wartosc(0);
  96.  
  97. liczba_ocen--;
  98.  
  99. }
  100. }
  101.  
  102. void Przedmiot::wypisz_oceny(){
  103.  
  104. int i = 0;
  105. cout << endl;
  106. do{
  107. cout << "[" << tablica_ocen[i] << "] ";
  108.  
  109. i++;
  110. }while (tablica_ocen[i] == 0);
  111. cout << endl;
  112.  
  113. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement