MeehoweCK

Untitled

May 8th, 2021
2,550
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.92 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.         cout << "MENU:\n";
  50.         cout << "\tN - Wprowadz dane studenta,\n";
  51.         cout << "\tW - Wyswietl dane studentow,\n";
  52.         cout << "\tU - Usun wybranego studenta,\n";
  53.         cout << "\tQ - Wyjdz z programu\n";
  54.         do
  55.         {
  56.             komenda = _getch();
  57.             komenda = toupper(komenda);
  58.         } while(komenda != 'N' && komenda != 'W' && komenda != 'U' && komenda != 'Q');
  59.         system("cls");
  60.  
  61.         switch(komenda)
  62.         {
  63.         case 'N':
  64.             cout << "Podaj imie i nazwisko studenta: ";
  65.             cin >> tab[ilu];
  66.             ++ilu;
  67.             break;
  68.         case 'W':
  69.             for(unsigned i = 0; i < ilu; ++i)
  70.                 cout << tab[i] << endl;
  71.             break;
  72.         case 'U':
  73.             cout << "Podaj nr studenta, ktorego chcesz usunac: ";
  74.             cin >> nr;
  75.             tab[nr].usun_opis();
  76.             for(unsigned i = nr; i < ilu; ++i)
  77.                 tab[i] = tab[i + 1];
  78.             --ilu;
  79.             tab[ilu].usun_opis();
  80.         }
  81.     } while(komenda != 'Q');
  82.     return 0;
  83. }
Advertisement
Add Comment
Please, Sign In to add comment