Panel użytkownika
Nazwa użytkownika:
Hasło:
Nie masz jeszcze konta?

wyszukiwanie na liscie wg danych

Ostatnio zmodyfikowano 2017-01-17 13:14
Autor Wiadomość
mikewazowski
Temat założony przez niniejszego użytkownika
wyszukiwanie na liscie wg danych
» 2017-01-17 13:14:20
funkcja wyszukiwania po nazwisku działa jak trzeba do momentu jeśli na liście między 2 osobami o tym samym nazwisku znajduje się osoba o innym nazwisku, nie mam pomysłów jak to naprawić

C/C++
#include <iostream>
#include <string>
#include <cstdlib>
#include <cstdio>
using namespace std;
struct Dane
{
        string imie;
        string nazwisko;
        string dataur;
        string ulica;
        string miasto;
        string inne;
        int id;
};
struct Student
{
        Dane dane;
        Student * next;
        Student * prev;
        static int num_of_students;
};
int Student::num_of_students = 0;

Student * stworzelement()
{
        Student * element;
        string imie;
        string nazwisko;
        string dataur;
        string ulica;
        string miasto;
        string inne;
        int id = ++Student::num_of_students;
       
        cout << "ID: " << id << endl;
        cout << "podaj imie: ";
        cin >> imie;
        cout << "podaj nazwisko: ";
        cin >> nazwisko;
        cout << "podaj date urodzenia: ";
        cin.sync();
        getline( cin, dataur );
        cout << "podaj ulice i numer domu: ";
        cin.sync();
        getline( cin, ulica );
        cout << "podaj miasto: ";
        cin.sync();
        getline( cin, miasto );
        cout << "podaj inne dane: ";
        cin.sync();
        getline( cin, inne );
       
        element = new Student();
        element->next = NULL;
        element->prev = NULL;
        element->dane.id = id;
        element->dane.imie = imie;
        element->dane.nazwisko = nazwisko;
        element->dane.dataur = dataur;
        element->dane.ulica = ulica;
        element->dane.miasto = miasto;
        element->dane.inne = inne;
       
        return element;
}
int dodajkoniec( Student ** head )
{
        Student * pom;
        if( * head == NULL )
        {
               
                Student * tmp = stworzelement();
                * head = tmp;
                cout << "***dodano do bazy***" << endl;
            }
       
        else
        {
                Student * tmp = stworzelement();
                pom = * head;
               
                while( pom->next != NULL )
                {
                        pom = pom->next;
                       
                    }
                tmp->prev = pom;
                pom->next = tmp;
                cout << "***dodano do bazy***" << endl;
            }
       
}

Student * wyszukaj_element( Student * head, string nazwisko ) //szuka po nazwisku
{
        Student * pom;
        pom = head;
        while( pom != NULL &&( pom->dane.nazwisko ).compare( nazwisko ) != 0 )
                   pom = pom->next;
   
       
        return pom;
}


void wyszukaj( Student ** head ) //szuka po nazwisku ALE 1 OSOBE
{
    A:
    int co;
    Student * tmp;
    Student * pom;
    Student * element;
    element = * head;
    string nazwisko;
    cout << "podaj nazwisko: ";
    cin >> nazwisko;
    tmp = wyszukaj_element( * head, nazwisko );
    if( tmp == NULL )
    {
        cout << endl << "na liscie nie ma osoby o tym nazwisku" << endl;
        B:
        cout << endl << "co chcesz zrobic?";
        cout << endl << "1 --> wroc do menu glownego" << endl << "2 --> kontynuuj szukanie" << endl;
        cout << "twoj wybor: ";
        cin >> co;
        system( "cls" );
        if( co == 2 )
        { cin.clear();
            cin.sync();
            goto A;
        }
        else
        {
            cin.clear();
            cin.sync();
            system( "cls" );
        }
       
    }
    else
    {
        do
        {
            cout << endl << "Imie: " << tmp->dane.imie << endl;
            cout << "Nazwisko: " << tmp->dane.nazwisko << endl;
            cout << "ID: " << tmp->dane.id << endl;
            cout << "Data urodzenia: " << tmp->dane.dataur << endl;
            cout << "Ulica i numer domu: " << tmp->dane.ulica << endl;
            cout << "Miasto: " << tmp->dane.miasto << endl;
            cout << "Inne: " << tmp->dane.inne << endl;
            element = element->next;
            tmp = tmp->next;
            if( tmp == NULL ) break;
           
        } while( element != 0 );
       
    }
}
] / cpp ]
P-156535
« 1 »
  Strona 1 z 1