Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <iomanip>
- using namespace std;
- struct Pozycja {
- string typ;
- string tytul;
- string autor;
- int rok_wydania;
- int liczba_stron;
- int numer;
- Pozycja *next;
- };
- Pozycja *aktualny, *glowa, *ogon;
- Pozycja *nowa_lista() {
- aktualny=NULL;
- glowa=NULL;
- char odp='t';
- string typ, tytul, autor;
- int rok_wydania, liczba_stron, nr, numer;
- while (odp=='t' || odp=='T') {
- cout << "Wprowadz informacje o pozycji: \n";
- cout << "Podaj typ pozycji (artykul - 1/ksiazka - 2/inne - 3): \n";
- cin >> nr;
- while (nr==0 || nr>3){
- cout << "Podaj liczbe 1, 2 lub 3. \n";
- cin >> nr;
- }
- if (nr==1)
- typ="artykul";
- if (nr==2)
- typ="ksiazka";
- if (nr==3)
- typ="inne";
- std::cin.ignore();
- cout << "Podaj tytul: \n";
- getline(cin, tytul);
- cout << "Podaj autora: \n";
- getline(cin, autor);
- cout << "Podaj rok wydania: \n";
- cin >> rok_wydania;
- cout << "Podaj liczbe stron: \n";
- cin >> liczba_stron;
- cout << "Podaj mumer ISBN: \n";
- cin >> numer;
- ogon=aktualny;
- aktualny=new Pozycja;
- aktualny->numer=numer;
- aktualny->typ=typ;
- aktualny->tytul=tytul;
- aktualny->autor=autor;
- aktualny->rok_wydania=rok_wydania;
- aktualny->liczba_stron=liczba_stron;
- aktualny->next=NULL;
- if (ogon==NULL)
- glowa=aktualny;
- else
- ogon->next=aktualny;
- cout << "\n" << "Aby dodac kolejna pozycje wprowadz \"t\" lub \"T\". W przeciwnym razie wprowadz cokolwiek. \n";
- cin >> odp;
- cout << endl << endl;
- std::cin.ignore();
- }
- return glowa;
- }
- void wyswietl(Pozycja *adres) {
- while (adres!=NULL){
- cout << "Nr ISBN: \t" << adres->numer << "\n";
- cout << "Typ: \t" << adres->typ << "\n";
- cout << "Tytul: \t" << adres->tytul << "\n";
- cout << "Autor: \t" << adres->autor << "\n";
- cout << "Rok wydania: \t" << adres->rok_wydania << "\n";
- cout << "Liczba stron: \t" << adres->liczba_stron << endl << endl;
- adres=adres->next;
- }
- }
- Pozycja *dodaj_element (Pozycja *adres) {
- Pozycja *pom;
- char odp='t';
- string typ, tytul, autor;
- int rok_wydania, liczba_stron, nr, numer;
- while (odp=='t' || odp=='T'){
- cout << "Wprowadz informacje o pozycji: \n";
- cout << "Podaj typ pozycji (artykul - 1/ksiazka - 2/inne - 3): \n";
- cin >> nr;
- while (nr==0 || nr>3){
- cout << "Podaj liczbe 1, 2 lub 3. \n";
- cin >> nr;
- }
- if (nr==1)
- typ="artykul";
- if (nr==2)
- typ="ksiazka";
- if (nr==3)
- typ="inne";
- std::cin.ignore();
- cout << "Podaj tytul: \n";
- getline(cin, tytul);
- cout << "Podaj autora: \n";
- getline(cin, autor);
- cout << "Podaj rok wydania: \n";
- cin >> rok_wydania;
- cout << "Podaj liczbe stron: \n";
- cin >> liczba_stron;
- cout << "Podaj mumer ISBN: \n";
- cin >> numer;
- pom=new Pozycja;
- pom->numer=numer;
- pom->typ=typ;
- pom->tytul=tytul;
- pom->autor=autor;
- pom->rok_wydania=rok_wydania;
- pom->liczba_stron=liczba_stron;
- if (adres==NULL){
- adres=pom;
- }
- else{
- Pozycja *pom1 = adres;
- while (pom1->next!=NULL){
- pom1 = pom1->next;
- }
- pom1->next=pom;
- pom->next=NULL;
- }
- cout << "\n" << "Aby dodac kolejna pozycje wprowadz \"t\" lub \"T\". W przeciwnym razie wprowadz cokolwiek. \n";
- cin >> odp;
- cout << endl << endl;
- std::cin.ignore();
- }
- return adres;
- }
- Pozycja *usun_element (Pozycja *adres) {
- Pozycja *pom=adres;
- int nr;
- cout << "Podaj numer ISBN pozycji do usuniecia: \n";
- cin >> nr;
- if(pom==NULL)
- return 0;
- else{
- if (pom->numer==nr){
- Pozycja *pom1=pom;
- pom=pom->next;
- delete pom1;
- }
- else{
- while(pom->next!=NULL){
- if (pom->next->numer==nr){
- Pozycja *pom1=pom->next;
- pom->next=pom->next->next;
- delete pom1;
- }
- else{
- }
- }
- }
- }
- return pom;
- }
- void usuwanie_listy (Pozycja *&adres) {
- Pozycja *pom;
- while (adres!=NULL){
- pom=adres;
- adres=adres->next;
- }
- delete pom;
- }
- int main()
- {
- Pozycja *glowa;
- glowa=nowa_lista();
- wyswietl(glowa);
- glowa=usun_element(glowa);
- glowa=dodaj_element(glowa);
- wyswietl(glowa);
- usuwanie_listy(glowa);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment