Menu doesn't work

Hi every one Iam stuck with this code since a week.
My program is doing good in showing the output.
but nothing peforn when I
chose any thing from the menue
please help me as you can
thanks


#include <iostream>

using namespace std;

const int MLS = 50;
typedef int element;
const element SENTINEL = -1;

class AList {
private:
element items [MLS];
int size;
void Swap(int pos1, int pos2);
int Read_int();
element Read_element();
public:
void Menu();
void Read();
void Print();
void BubbleSort();
void InsertionSort();
void SelectionSort();
};
int main() {
cout<< "Sort and Search Demo Program, version 1.0\n"
<< "(c) 2012, Ahmed Elbadwi\n\n";

AList B;
B.Menu();
B.Read();
B.Print();
B.BubbleSort();
B.InsertionSort();
B.SelectionSort();
}

void AList::Menu () {
int choice;

/*const int keyboard = 1,
random = 2,
//B.BubbleSort() = 3,
insertion = 4,
selection = 5,
linear = 6,
binary = 7,
quit = 8;*/

cout<< "1: Reset the current list from the keyboard\n"
<< "2: Reset the current list using randomly generated elements\n"
<< "3: Perform Bubble Sort on the current list\n"
<< "4: Perform Insertion Sort on the current list\n"
<< "5: Perform Selection Sort on the current list\n"
<< "6: Perform Linear Search on the current list\n"
<< "7: Perform Binary Search on the current list\n"
<< "8: Quit the Program\n\n"
<< "Choose an action: ";
choice=Read_int();
while ((choice<1)||(choice>8)) {
cout << "invalid menu choice please try again: ";
choice=Read_int();

if (choice==1)

Read();
if (choice==2)

if (choice==3)
BubbleSort();
if (choice==4)
InsertionSort();
if (choice==5)
SelectionSort();



else;
cout<<"wrong";
}
}
int AList::Read_int() {
int val;
cin>> val;
while (!cin.good()) {
cout<< "invalid menu choice please try again: ";
cin.clear();
cin.ignore(80,'\n');
cin>>val; }

return val;
}
void AList::Read() {
element userval=1;
cout<< "Enter elements : ";
while ((userval!=SENTINEL) && (size<MLS)) {
items [size] = userval;
size ++;
}
}
void AList::Print(){
for (int i=0;i<size;i++)
cout<< items[i]<<endl;
}
void AList::BubbleSort() {
for (int i=0; size-1; i++){
for (int j=0; j<size-1-i; j++)
if (items[j]>items[j+1])
Swap (j, j+1);

else
;
}
}
void AList::Swap(int pos1, int pos2) {
element temp;
temp = items[pos2];
items[pos2]=items[pos1];
items[pos1]=temp;
}

element Read_element() {
element userval=5;
cin>> userval;
while ( !cin.good());
cout<< "invalid choice please enter a whole number between 1 and"
<< " 1000: ";
cin.clear();
cin.ignore(80,'\n');
cin>> userval;
return userval;
}

void AList::InsertionSort() {
int j;
bool done;
for (int i=1; i<size; size++)
j=i;
done = false;
while ((j>=1) && (!done))
if (items[j] < items[j-1]) {
Swap (j,j-1);
j--;
}
else
done=true;
}

void AList::SelectionSort() {
int maxpos;
for (int i = size-1; i<0; i--) {
maxpos = 0;
for (int j=1; j<=i; j++)
if (items[j] < items[maxpos])
maxpos = j;
else;
Swap(maxpos, i);
}
}
Last edited on
First, please edit your post so that it uses code tags - the <> button on the right.


You have the functions Read, Read_element, Read_int which seem to be very similar.

Pleas post your compiler output messages, it could be very instructive.
Topic archived. No new replies allowed.