Exemplo n.º 1
0
void Interface::start()
{
    programInfo();     // welcome note.

    int numb;

    while(true)
    {
        pickOption();

        cin >> numb;
        if(cin.fail())
        {
            cin.clear();
            cin.ignore(100,'\n');
        }

        //Error message
        if(numb < 1 || numb > 4)

        {
            cout << "The input you entered is not a valid option. Pick again!" << endl;
        }

        switch(numb)
        {
            case 1:
            {
                Person p = getPersoninfo(); //sækja upplýsingar um persónu.
                m_worker.createPerson(p);   //býr til eintak af persónu.
                break;
            }
            case 2:
            {
                vector<Person> list = m_worker.getList(); // Sækja lista.
                printList(list);
                askToSort();

                break;
            }
            case 3:
            {
                m_worker.saveAllData(); // Geymum öll gögn áður en forriti er lokað.
                return;
            }
            case 4:
            {
                string search;

                cout << "Enter search word: ";
                cin >> search;

                vector<Person> searchlist = m_worker.searchScientist(search); //
                printList(searchlist);

            }
       }
     }
}
Exemplo n.º 2
0
void Interface::start()             //Keyrir forritið.
{
    programInfo();     //Opnunarskilaboð til notanda.
    int numb;

    while(true)
    {
        pickOption();
        cin >> numb;
        if(cin.fail())
        {
            cin.clear();
            cin.ignore(100,'\n');
        }
        if(numb < 1 || numb > 4)
        {
            cout << "The input you entered is not a valid option. Pick again!" << endl;     //Villuskilaboð fyrir valmynd.
        }
        switch(numb)
        {
            case 1:
            {
                Person p = getPersoninfo(); //sækja upplýsingar um persónu.
                m_worker.createPerson(p);   //býr til eintak af persónu.
                break;
            }
            case 2:
            {
                vector<Person> list = m_worker.getList(); // Sækja lista.
                printList(list);

                int sos_ans = askSearchOrSort();
                while(sos_ans != 3)
                {
                    if(sos_ans == 1)
                    {
                        int sort_ans = sortMenu();
                        if(sort_ans == 1)
                        {
                            printSorted();
                        }
                        if(sort_ans == 2)
                        {
                            printSortedReverse();
                        }
                        if(sort_ans == 3)
                        {
                            printSortedYear();
                        }
                        if(sort_ans == 4)
                        {
                            printSortedYearReverse();
                        }
                    }


                if(sos_ans == 2)
                {
                    string remove;
                    cout << "Enter name to remove: ";
                    cin >> remove;
                    vector<Person> removelist = m_worker.removeScientist(remove); //
                    printList(removelist);
                }
                if(sos_ans == 3)
                {
                    break;
                }
                sos_ans = askSearchOrSort();
              }
              break;
            }

            case 3:                     // Search list
            {
                string search;
                cout << "Enter search word: ";
                cin >> search;
                vector<Person> searchlist = m_worker.searchScientist(search);
                printList(searchlist);
                break;
            }
            case 4:
            {
                m_worker.saveAllData(); // Geymum öll gögn áður en forriti er lokað.
                return;
            }
       }
     }