Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- struct Student{
- int nr_indexu;
- string imie;
- string nazwisko;
- void wypisz()const {
- cout << nr_indexu << " " << imie << " " << nazwisko <<endl;
- }
- };
- class BazaStudentow{
- private:
- vector<Student> bazaStudentow;
- public:
- Student wczytaj(){
- Student s1;
- cout << "Podaj nr indexu:";
- cin >> s1.nr_indexu;
- cout << "Podaj imie: ";
- cin >> s1.imie;
- cout << "Podaj nazwisko";
- cin >> s1.nazwisko;
- return s1;
- }
- void dodaj(){
- Student s1 = wczytaj();
- bazaStudentow.push_back(s1);
- }
- void drukuj(){
- for (const Student& s : bazaStudentow) {
- s.wypisz();
- }
- }
- const Student* znajdz(int nr_indexu){
- for (const Student& s : bazaStudentow) {
- if( nr_indexu == s.nr_indexu){
- return &s;
- }
- }
- return nullptr;
- }
- const Student* usun(int nr_indexu){
- for (int i=0; i<bazaStudentow.size(); i++) {
- if( nr_indexu == bazaStudentow[i].nr_indexu){
- const Student s = bazaStudentow[i];
- bazaStudentow.erase(bazaStudentow.begin() + i);
- return &s;
- }
- }
- return nullptr;
- }
- };
- main()
- {
- BazaStudentow b;
- b.dodaj();
- b.dodaj();
- b.drukuj();
- const Student* wsk = b.znajdz(123123);
- if(wsk != nullptr){
- cout<<" Znaleziono " <<endl;
- wsk->wypisz();
- }
- const Student* wsk2;
- wsk2 = b.usun(123123);
- if(wsk2 != nullptr){
- cout<<" Usunieto " <<endl;
- wsk2->wypisz();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement