Advertisement
Guest User

Untitled

a guest
Nov 21st, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.60 KB | None | 0 0
  1. #ifndef KOLOKWIUM_H
  2. #define KOLOKWIUM_H
  3.  
  4. #include <iostream>
  5. #include <cstdlib>
  6. #include <cstring>
  7. using namespace std;
  8.  
  9. class Kolokwium
  10. {
  11.     static int liczbaPuntkow;
  12.     char* student;
  13.     float ocena;
  14.  
  15. public:
  16.     Kolokwium(const char* s, float o);
  17.     ~Kolokwium();
  18.     void wypisz() const;
  19.     friend istream& operator>>(istream& , Kolokwium&);
  20.     void zmienNazweStudenta(const char*);
  21. };
  22. #endif // KOLOKWIUM_H
  23.  
  24.  
  25. ///////////////////////////////
  26.  
  27. #include "kolokwium.h"
  28.  
  29. int Kolokwium::liczbaPuntkow = 21;
  30.  
  31. Kolokwium::Kolokwium(const char* s, float o)
  32. {
  33.     student = new char[strlen(s)+1];
  34.     strcpy(student,s);
  35.     ocena = o;
  36.     liczbaPuntkow++;
  37. }
  38.  
  39. Kolokwium::~Kolokwium()
  40. {
  41.     --liczbaPuntkow;
  42.     delete []student;
  43. }
  44. void Kolokwium::wypisz() const
  45. {
  46.     cout <<"Student: " << student << endl
  47.     << "Ocena: " << ocena << endl;
  48. }
  49.  
  50. istream& operator>>(istream& is , Kolokwium& K)
  51. {
  52.     cout <<"Podaj imie studenta: ";
  53.     is >> K.student;
  54.  
  55.     cout <<"Podaj ocene: ";
  56.     is>>K.ocena;
  57.  
  58.     return is;
  59. }
  60.  
  61. void Kolokwium::zmienNazweStudenta(const char* nazwa)
  62. {
  63.     this->student = new char[strlen(nazwa)+1];
  64.     strcpy(student,nazwa);
  65. }
  66.  
  67. void wypisz()
  68. {
  69.     cout << student << ocena<<
  70. }
  71.  
  72. ////////////////////////////////
  73. #include "kolokwium.h"
  74.  
  75. using namespace std;
  76.  
  77. int main()
  78. {
  79.  
  80. //    Kolokwium k1;
  81.     Kolokwium k2("Sylwia",5);
  82.     Kolokwium k3("Krzysiu",4);
  83.  
  84.     k2.wypisz();
  85.     k3.wypisz();
  86.  
  87.     cin >> k2 ;
  88.     k2.wypisz();
  89.  
  90.  
  91.     cout << endl;
  92.  
  93.     k2.zmienNazweStudenta("Karol");
  94.     k2.wypisz();
  95.     return 0;
  96. }
  97. /////
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement