Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // main.cpp
- // students
- //
- // Created by Chojnacky Karol on 15.05.2018.
- // Copyright © 2018 Chojnacky Karol. All rights reserved.
- //
- #include <fstream>
- #include <iostream>
- using namespace std;
- string imie,nazwisko;
- fstream plik;
- int nr_albumu; //tworzymy liste
- struct student {
- string imie;
- string nazwisko;
- int nr_albumu;
- student *next;
- student();
- };
- student::student(){
- next = 0;
- }
- struct lista {
- student *first;
- void dodaj_studenta(string imie, string nazwisko, int nr_albumu);
- void usun_studenta(int nr);
- void wyswietl_studenta();
- void wyswietl_liste();
- lista();
- };
- lista::lista(){
- first = 0;
- }
- lista *baza = new lista;
- void lista::dodaj_studenta(string imie, string nazwisko, int nr_albumu) {
- student *nowa = new student; // tworzy nowy element listy
- // wypełniamy naszymi danymi
- nowa->imie = imie;
- nowa->nazwisko = nazwisko;
- nowa->nr_albumu = nr_albumu;
- if (first==0) // sprawdzamy czy to pierwszy element listy
- {
- // jeżeli tak to nowy element jest teraz początkiem listy
- first = nowa;
- }
- else
- {
- // w przeciwnym wypadku wędrujemy na koniec listy
- student *temp = first;
- while (temp->next)
- {
- // znajdujemy wskaźnik na ostatni element
- temp = temp->next;
- }
- temp->next = nowa; // ostatni element wskazuje na nasz nowy
- nowa->next = 0; // ostatni nie wskazuje na nic
- }
- }
- void lista::wyswietl_studenta() {
- // wskaznik na pierszy element listy
- student *temp = first;
- // przewijamy wskazniki na nastepne elementy
- while (temp)
- {
- cout << "imie: " << temp->imie << " nazwisko: " << temp->nazwisko << endl;
- temp=temp->next;
- }
- }
- //~/Biurko/Studia/STUDIA - OWN/SII OWN/Programowanie/1 zajęcia/students/students
- void zapis(){
- plik.open("plik.txt", ios::out | ios::app);
- if(plik.good() == true)
- {
- plik << baza->first->nr_albumu << "\n";
- plik << baza->first->imie << "\n";
- plik << baza->first->nazwisko << "\n";
- plik.close();
- }
- return;
- }
- void dodawanie(){
- //lista *root =
- cout << "DODAWANIE STUDENTA" << endl;
- cout << "Podaj imie studenta: "; cin >> imie;
- cout << "Podaj nazwisko studenta: "; cin >> nazwisko;
- cout << "Podaj numer albumu: "; cin >> nr_albumu;
- baza->dodaj_studenta(imie, nazwisko, nr_albumu);
- return zapis();
- }
- void lista::wyswietl_liste()
- {
- // wskaznik na pierszy element listy
- student *temp = first;
- // przewijamy wskazniki na nastepne elementy
- while (temp)
- {
- cout << "imie: " << temp->imie << " nazwisko: " << temp->nazwisko << " nr_albumu: " << temp->nr_albumu << endl;
- temp=temp->next;
- }
- }
- void szukaj(){
- cout << baza->first->imie << ", " << baza->first->nazwisko << ", " << baza->first->nr_albumu << endl;
- return;
- }
- void menu(){
- int wybor;
- cout << "BAZA STUDENTÓW\n1. Dodaj studenta\n2. Szukaj student\n3. Edytuj dane studenta\n4. Usuń studenta z bazy\n5. Wyswietl całą bazę\n6. Zamknij program\n=> "; cin >> wybor;
- switch(wybor){
- case 1:
- dodawanie();
- return menu();
- break;
- case 2:
- szukaj();
- return menu();
- break;
- case 3:
- break;
- case 4:
- break;
- case 5:
- baza->wyswietl_liste();
- return menu();
- break;
- case 6:
- return;
- break;
- default:
- return ;
- break;
- }
- }
- int main(int argc, const char * argv[]) {
- menu();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment