Advertisement
MeehoweCK

Untitled

May 3rd, 2021
867
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.55 KB | None | 0 0
  1. #include <iostream>
  2. #include <conio.h>
  3.  
  4. using namespace std;
  5.  
  6. class Student
  7. {
  8.     friend ostream& operator<<(ostream&, const Student&);
  9.     friend istream& operator>>(istream&, Student&);
  10.     string Imie;
  11.     string Nazwisko;
  12. public:
  13.     Student();
  14.     Student(string, string);
  15.     void usun_opis();
  16. };
  17.  
  18. ostream& operator<<(ostream& os, const Student& student)
  19. {
  20.     os << student.Imie << ' ' << student.Nazwisko;
  21.     return os;
  22. }
  23.  
  24. istream& operator>>(istream& is, Student& student)
  25. {
  26.     is >> student.Imie >> student.Nazwisko;
  27.     return is;
  28. }
  29.  
  30. Student::Student() {}
  31. Student::Student(string name, string scnd_name) : Imie(name), Nazwisko(scnd_name) {}
  32.  
  33. void Student::usun_opis()
  34. {
  35.     Imie = "";
  36.     Nazwisko = "";
  37. }
  38.  
  39. int main()
  40. {
  41.     unsigned ilu = 0;
  42.     Student tab[100];
  43.  
  44.     char komenda;
  45.     unsigned nr;
  46.  
  47.     do
  48.     {
  49.         komenda = _getch();
  50.         komenda = toupper(komenda);
  51.         switch(komenda)
  52.         {
  53.         case 'N':
  54.             cout << "Podaj imie i nazwisko studenta: ";
  55.             cin >> tab[ilu];
  56.             ++ilu;
  57.             break;
  58.         case 'W':
  59.             for(unsigned i = 0; i < ilu; ++i)
  60.                 cout << tab[i] << endl;
  61.             break;
  62.         case 'U':
  63.             cout << "Podaj nr studenta, ktorego chcesz usunac: ";
  64.             cin >> nr;
  65.             tab[nr].usun_opis();
  66.             for(unsigned i = nr; i < ilu; ++i)
  67.                 tab[i] = tab[i + 1];
  68.             --ilu;
  69.             tab[ilu].usun_opis();
  70.         }
  71.     } while(komenda != 'Q');
  72.     return 0;
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement