Example #1
0
void UI::sortMenu()
{
    char choice;
    cout << endl;
    cout << "Print by: " << endl;
    cout << "(U) Unordered" << endl
         << "(A) Alphabetic order" << endl
         << "(R) Reverse alphabetic order" << endl
         << "(B) Year of Birth" << endl
         << "(D) Year of Death" << endl
         << "(M) Return to Menu" << endl
         << "(Q) Quit program " << endl;
    cout << "Select a letter: ";
    cin >> choice;

    switch(choice) {
        case 'u':
        case 'U':   print();
                    break;
        case 'a':
        case 'A':   cout << endl << "--- Printing by alphabetical order --- " << endl;
                    core.sortAlpabetFront();
                    print();
                    break;
        case 'r':
        case 'R':   cout << endl << "--- Printing by reverse alphabetical order --- " << endl;
                    core.sortAlpabetBack();
                    print();
                    break;
        case 'b':
        case 'B':   cout << endl << "--- Printing by year of Birth --- " << endl;
                    core.sortByBirthYear();
                    print();
                    break;
        case 'd':
        case 'D':   cout << endl << "--- Printing by year of Death --- " << endl;
                    core.sortByDeathYear();
                    print();
                    break;
        case 'M':
        case 'm':   return;
                    break;

        case 'q':
        case 'Q':   exit(1);
                    break;
        default:    errorInput();
                    sortMenu();
                       break;
    }
    sortMenu();
}
Example #2
0
int mainMenu(){
	char* command = (char*) malloc (2*sizeof(char));
	printf ("%s",menu);
	scanf("%s",command);
	if (strcmp(command,"x") == 0) {
		free (command);
		return 0;
	}
	if (strcmp(command,"1") == 0) {
		addMenu();
	}
	if (strcmp(command,"2") == 0){
		updateProductPriceMenu();
	}
	if (strcmp(command,"3") == 0) {
		updateProductQuantityMenu();
	}
	if (strcmp(command,"4") == 0) {
		removeProductMenu();
	}
	if (strcmp(command,"5") == 0) {
		filterMenu();
	}
	if (strcmp(command,"6") == 0) {
		sortMenu();
	}
	if (strcmp(command,"7") == 0) {
		viewAll();
	}
	free (command);
	return 1;
}
Example #3
0
void UI::menu(char ans)
{
    switch(ans) {
        case 'a':
        case 'A':   addIndividual();
                    break;
        case 's':
        case 'S':   searchMenu();
                    break;
        case 'p':
        case 'P':   sortMenu();
                    break;
        case 'r':
        case 'R':   remove();
                    break;
        case 'l':
        case 'L':   cout << "The current size of this list is: " << core.getSizeOfList() << endl;
                    break;
        case 'q':
        case 'Q':   cout << endl;
                    exit(1);
                    break;
        default:    cout << "Incorrect input, please try again!" << endl;
                    break;
    }
}
Example #4
0
void askUser()
{
	char choice;
	int x;
	int loop;
	
	system("cls");
	printf("---MAIN MENU---\n");
	printf("\n[1]-ENTER STRING\n[2]-DISPLAY\n[3]-SORT\n\n");
	choice=getch();

	switch(choice)
	{
		case '1':
			printf("How many number(s)?");
			scanf("%d",&loop);
			
			for(x=0;x<loop;x++)
				askStr();
				
			getch();
			askUser();
			break;
		case '2':
			displayMenu();
			getch();
			askUser();
			break;
		case '3':
			sortMenu();
			getch();
			askUser();
			break;
		default:
			getch();
			break;	
	}	
}
PerformanceRecordWidget::PerformanceRecordWidget(QWidget* parent)
    : QWidget(parent)
    , resetIcon_()
    , splitter_(new QSplitter(Qt::Vertical))
    , resetSettings_(false)
{
    setWhatsThis(whatsThisInfo);

    QPushButton* sortButton = new QPushButton(this);
    sortButton->setIcon(QIcon(":/voreenve/icons/configure.png"));
    sortButton->setGeometry(0,0,32,32);
    sortButton->setFlat(true);
    sortButton->setToolTip(tr("Sort performance records"));

    edit_ = new LineEditResetWidget(this);
    edit_->setToolTip(tr("Filter performance records"));

    QVBoxLayout* mainLayout = new QVBoxLayout(this);
    QHBoxLayout* filterSortLayout = new QHBoxLayout();

    useAverageTime_ = new QAction("Calculate Average Time", this);
    useLastTime_ = new QAction("Use Last Time Record", this);
    useAverageTime_->setCheckable(true);
    useLastTime_->setCheckable(true);

    sortByTotalProcessTime_ = new QAction("Sort by Total Process Time", this);
    sortByBeforeProcessTime_ = new QAction("Sort by Before Process Time", this);
    sortByProcessTime_ = new QAction("Sort by Process Time", this);
    sortByAfterProcessTime_ = new QAction("Sort by After Process Time", this);

    sortByTotalProcessTime_->setCheckable(true);
    sortByBeforeProcessTime_->setCheckable(true);
    sortByProcessTime_->setCheckable(true);
    sortByAfterProcessTime_->setCheckable(true);

    showTotalProcessTime_ = new QAction("Show Total Process Time On Top", this);
    showBeforeProcessTime_ = new QAction("Show Before Process Time On Top", this);
    showProcessTime_ = new QAction("Show Process Time On Top", this);
    showAfterProcessTime_ = new QAction("Show After Process Time On Top", this);
    
    showTotalProcessTime_->setCheckable(true);
    showBeforeProcessTime_->setCheckable(true);
    showProcessTime_->setCheckable(true);
    showAfterProcessTime_->setCheckable(true);

    clearTreeWhenRecordsUpdate_ = new QAction("Clear Records on Update", this);
    clearTreeWhenRecordsUpdate_->setCheckable(true);

    resetPerformanceRecords_ = new QAction("Clear All Performance Records", this);

    loadSettings();

    connect(edit_, SIGNAL(textChanged(const QString&)), tree_, SLOT(filter(const QString&)));
    connect(sortButton, SIGNAL(clicked()), this, SLOT(sortMenu()));
    connect(this, SIGNAL(sort(int)), tree_, SLOT(sort(int)));
    connect(this, SIGNAL(show(int)), tree_, SLOT(show(int)));
    connect(this, SIGNAL(averageTime(bool)), tree_, SLOT(averageTime(bool)));
    connect(this, SIGNAL(clearRecords()), tree_, SLOT(clearRecords()));

    filterSortLayout->addWidget(edit_);
    filterSortLayout->addWidget(sortButton);
    splitter_->addWidget(tree_);
    QList<int> widgetSpacing;
    widgetSpacing << 500 << 100;
    splitter_->setSizes(widgetSpacing);
    mainLayout->addLayout(filterSortLayout);
    mainLayout->addWidget(splitter_);
}
Example #6
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;
            }
       }
     }
Example #7
0
void sortMenu()
{
	char choice;
	
	system('cls');
	printf("[1]-INSERTION SORT\n[2]-SELECTION SORT\n[3]-BUBBLE SORT\n[4]-BUCKET SORT\n[5]-HEAP SORT\n[6]-QUICK SORT\n[7]-RADIX SORT\n[8]-COMB SORT\n[9]-MERGE SORT\n[0]-SHELL SORT\n");
	printf("Press any key in order to return to MAIN MENU...");
	choice=getche();
	
	switch(choice)
	{
		case '1':		//insertion
			sortInsert();
			getch();
			sortMenu();
			break;
		case '2':		//selection
			getch();
			sortMenu();
			break;
		case '3':		//bubble
			//bubbleSort(parameter1);
			getch();
			sortMenu();	
			break;
		case '4':		//bucket
			getch();
			sortMenu();
			break;
		case '5':		//heap
			getch();
			sortMenu();
			break;
		case '6':		//quick
			//QuickSortList(parameter1,parameter2);
			getch();
			sortMenu();
			break;
		case '7':		//radix
			getch();
			sortMenu();
			break;
		case '8':		//comb
			getch();
			sortMenu();
			break;
		case '9':		//merge
			//mergesort(parameter1)
			getch();
			sortMenu();
			break;
		case '0':		//shell
			getch();
			sortMenu();
			break;
		default:
			getch();
			askUser();
			break;
	}
}
// sorts the list by either first or surname ascendin
// I created my own bubble sort from scratch to do this (the pencil and paper method was essential for this piece of code ;) )
void sort(){
	// sort by fName, lName, phone
	struct contact *curr, *next, *temp;
	int choice, swap;

	// first in the list
	curr = listHead->next;
	next = curr->next;

	do{
		choice = sortMenu();
		switch(choice){
			case 1:	// fName
				// below is my custom made bubble sort
				do{
					curr = listHead->next;
					next = curr->next;
					swap = 0;
					
					while(next->next != NULL){ // while next != tail
						if(curr->fName[0] > next->fName[0]){
							curr->prev->next = next;	// before current ->
							curr->next = next->next;	// currents->
							next->prev = curr->prev;	// nexts<-
							curr->prev = next;			// currents<-
							
							next->next->prev = curr;	// after nexts <-

							next->next = curr;			// nexts->

							swap++;

							next = curr->next;			// next is now after current
														
						} // if
						else{
							curr = curr->next;
							next = curr->next;
						}
					}
					next->prev = curr; // next is now tail so we need to set tails previous to current (which is the last contact in the list)
					// used to test how many swaps is done on each iteration
					//printf("Swaps: %d\n", swap);
				}while(swap != 0);

				break;

			case 2:	// sName
				// below is my custom made bubble sort
				do{
					curr = listHead->next;
					next = curr->next;
					swap = 0;
					
					while(next->next != NULL){ // while next != tail
						if(curr->sName[0] > next->sName[0]){
							curr->prev->next = next;	// before current ->
							curr->next = next->next;	// currents->
							next->prev = curr->prev;	// nexts<-
							curr->prev = next;			// currents<-
							
							next->next->prev = curr;	// after nexts <-

							next->next = curr;			// nexts->

							swap++;

							next = curr->next;			// next is now after current
														
						} // if
						else{
							curr = curr->next;
							next = curr->next;
						}
					}
					next->prev = curr; // next is now tail so we need to set tails previous to current (which is the last contact in the list)
					// used to test how many swaps is done on each iteration
					// printf("Swaps: %d\n", swap);
				}while(swap != 0);

				break;

			default:
				printf("Not a valid number, re-enter.\n");
				break;
		} // switch
	}while(choice < 1 || choice > 2);

	printf("Sort complete!\n");
}