I am currently working on an assignment for uni and have completed the majority of the coding myself, however the last few functions I have created aren't working the way I need them to. The questions for the functions I need help with are:
When menu option 5. is selected, the program will allow you to delete one instance of the mark you want to delete, unless the mark doesn't exist.
When menu option 6. is selected, the program will first read a mark from the user, and then search the available list of marks to see how many occurrences of this mark there are. It will then report this number of occurrences.
When menu option 7. is selected, the program will go through all the distinctive marks in the list, and find out how many occurences there are for each of the distinctive marks. For instance, if the current list of marks contains.
I will only post my code for the run menu function, and the functions that are not working as I want them to, unless anyone thinks that it may be another function that I have not coded properly.
Code:
int main()
{
runMenu(); //runs the entire menu.
return 0;
}
void runMenu()
{
double mean = 0;
int option;
int totalRec = 0;
double allMarks[totalRec];
string word, msg = "Menu v1.0 13/05/2011\tMatthew Verwey-Cuthbert\t\t17232874";
do
{
clrscr();
displayMenu(msg);
cin.clear();
if(!(cin >> option))
{
if(!cin.eof())
{
cin.clear();
cin >> word;
}
continue;
}
switch(option)
{
case 1:
addMark(allMarks, totalRec);
msg = '0' + option;
msg += " was last selected";
break;
case 2:
displayMarks(allMarks, totalRec);
msg = '0' + option;
msg += " was last selected";
break;
case 3:
findMean(allMarks, totalRec, mean);
msg = '0' + option;
msg += " was last selected";
break;
case 4:
standardDev(allMarks, totalRec, mean);
msg = '0' + option;
msg += " was last selected";
break;
case 5:
delMark(allMarks, totalRec);
msg = '0' + option;
msg += " was last selected";
break;
case 6:
oneMarkOccur(allMarks, totalRec);
msg = '0' + option;
msg += " was last selected";
break;
case 7:
allMarksOccur(allMarks, totalRec);
msg = '0' + option;
msg += " was last selected";
break;
default:
msg = '0' + option;
msg += " was last selected";
break;
}
}
while (option);
}
bool findMark(double allMarks[], int totalRec) //fix function
{
double mark;
bool found = false;
int first, last, middle;
cout << "Mark to delete->";
cin >> mark;
first = 0;
last = totalRec-1;
while((first <= last) && !found)
{
middle = (first + last) / 2;
if(allMarks[middle] == mark)
found = true;
else if(mark > allMarks[middle])
first = middle + 1;
else
last = middle - 1;
}
if(found) return middle;
else return false;
pause();
}
bool delMark(double allMarks[], int &totalRec) //fix function
{
int middle = findMark(allMarks, totalRec);
if(middle > 0)
{
cout << "\nThe mark " << allMarks[middle] << " has been removed." << endl;
for(int i = middle; i < totalRec; i++)
{
allMarks[i] = allMarks[i + 1];
}
totalRec--;
}
else
{
cout << "\n**THE MARK YOU HAVE ENTERED WAS NOT FOUND**" << endl;
}
pause();
}
bool oneMarkOccur(double allMarks[], int totalRec) //fix function
{
double mark = 0;
int count = 0;
cout << "Enter the mark to search for -> ";
cin >> mark;
for(int i = 0; i < totalRec; i++)
{
allMarks[i];
if(allMarks[i] = mark)
count++;
}
cout << "\nMARK\tOCCURENCE\n"
<< "----\t---------\n"
<< mark << "\t" << count << endl;
pause();
}
bool allMarksOccur(double allMarks[], int totalRec)
{
double temp;
int count = 0;
cout << "\nMARK\tOCCURENCE\n"
<< "----\t----------" << endl;
for(int i = 0; i < totalRec; i++)
{
temp = allMarks[i];
for(int j = 0; j < totalRec; j++)
{
if(allMarks[j] = temp)
count++;
cout << temp << "\t" << count << endl;
}
}
pause();
}

