You are required to declare a one dimensional data structure called Marks that will store six (7) student’s grades. The grade is a whole number within the range 0 to 100 inclusive.
Write a menu structure to facilitate the following features. Each of the below features must be executed in its own function.
• Enter/Input each students mark.
• Display all the students’ marks entered in the class.
• Search for any entered mark and return the index location.
• Determine the class average.
• Determine which student gained the highest mark in the class and the location (index) of that mark.
• Determine which student gained the lowest mark in the class and the location (index) of that mark.
this is an assignment i have for school. I did it but its not particularly right can someone plz help?
oh sorry and no i don't expect you to read my mind i'm need to the site and it was an over site on my behalf. it does what the question asks for but i'm having trouble with the menu. and the validation to quit. The menu works just i have to select the number in an order frm 1-6. therefore if i chose option 1 then lets say i choose option 4 it doesnt work
the question specifically states "Structure". Now I dunno the specific terms that you guys are using over there but I do know that Microsoft, Cprogramming, learncpp, all think that a structure is a struct.
So are you sure you should be using an array and not a struct?
thanks nathan2222 will try that and will post if everyting goes well. to answer fox yea we were told to use an array and a struct thanks for looking out
well the menu functions works now but i'm still the same problem when selecting the options in that i have to select it in numerical order for the code to execute. if i choose the code for that will execute and if i choose option 3 it just keeps displaying the menu until the code terminates.
#include <iostream>
#include <conio.h>
#include <stdlib.h>
#include <windows.h>
usingnamespace std;
int choice=0;
void showMenu( int )
{
cout << "Please choose a Number" << endl << endl
<< "1. To Enter and dispaly Student's Grade" << endl
<< "2. To search for a praticular grade" << endl
<< "3. To determine Average" << endl
<< "4. To view Students Higest Grade" << endl
<< "5. To Lowest Grade"<< endl
<< "6. To Quit" << endl << endl
<<"Enter selection: ";
cin >> choice;
system("Pause");
system("CLS");
}
/*// Functions
void showWelcome();
int studentMark( );
int ArrarySearch();
int classAverage();
int highestMark();
int lowestMark();*/
int main()
{
int Marks[7]; //index of Marks
int Grade=0; //marks
int n; //counter for Marks
int flag=0;
int indexSearch=0;
float avg=0;
float sum=0;
int highest=0;
int lowest=0;
cout << "*******************Welcome to The Grade Book !!!*******************"<<endl<<endl;
system("Pause");
system("CLS");
// Menu Function
showMenu(choice);
if(choice == 1)
{
for (n=0; n<7; n++)
{
cout << "Please enter student's mark ";
cin >> Grade;
Marks[n] = Grade; //enters grades into index
system("CLS");
}
for (n=0; n<7; n++)
{
cout << "The sutdent's marks are... " << Marks[n] << endl;
cout << endl;
}
}
showMenu(choice);
//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
if ( choice == 2)
{
cout << "Enter the student's grade you wish to search for... ";
cin >> indexSearch;
for (n=0; n<7; n++)
{
if (Marks[n] == indexSearch)
{
flag=1;
break;
}
}
if (flag)
{
cout << "The student's grade entered is a Index " << n << endl;
}
else
{
cout <<"Sorry I could not find your number in this array..." << endl;
}
}
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
showMenu(choice);
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
if ( choice == 3)
{
for (n=0; n<7; n++)
{
sum += Marks[n];
avg = sum/7;
}
cout << "The avearge is... " << avg << endl;
}
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
showMenu(choice);
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
if ( choice == 4)
{
highest = Marks[0];
for (n=0; n<7; n++)
{
if (Marks[n]>highest)
highest = Marks[n];
}
for (n=0; n<7; n++)
{
if (highest == Marks[n])
{
flag=1;
break;
}
}
}
cout << "The highest mark is... " << highest << endl;
if (flag)
{
cout << "The highest mark is in index " << n << endl;
}
//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
showMenu(choice);
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
if ( choice ==5)
{
lowest = Marks[0];
for (n=0; n<7; n++)
{
if (Marks[n]<lowest)
lowest = Marks[n];
}
for (n=0; n<7; n++)
{
if (lowest == Marks[n])
{
flag=1;
break;
}
}
cout << "The lowest mark is... " << lowest << endl;
if (flag)
{
cout << "The lowest mark is in index " << n << endl;
}
}
if ( choice < 1 || choice > 6)
{
cout <<" Invalid request Please check menu and try again"<<endl<<endl;
showMenu(choice);
}
if ( choice == 6)
{
cout<<" Thank you for using the Grade book........ Good bye."<< endl;
exit(0);
system("PAUSE");
}
return 0;
}
//#includes
//function declarations
void showWelcome();
int studentMark( );
int ArrarySearch();
int classAverage();
int highestMark();
int lowestMark();
int main() {
}
//function definitions
void showMenu( int )
{
cout << "Please choose a Number" << endl << endl
<< "1. To Enter and dispaly Student's Grade" << endl
<< "2. To search for a praticular grade" << endl
<< "3. To determine Average" << endl
<< "4. To view Students Higest Grade" << endl
<< "5. To Lowest Grade"<< endl
<< "6. To Quit" << endl << endl
<<"Enter selection: ";
cin >> choice;
system("Pause");
system("CLS");
}
//more function definitions
The code you have for each selection (lines 70 - 88, lines 96 - 123 etc) should go into their own functions
Your showmenu function has a return type of void, you need to have it return the users selection so that information is available for the rest of the program. You have choice as a global variable (a bad idea), it is initialised to 0, and it will always 0, so the menu would be redisplayed 6 times until you get to line 212 which gives the warning followed straight after by the menu again, then the program ends !
You also need a while loop instead of repeatedly calling the menu function. Search on this forum for TheIdeasMan bool controlled while loop