I don't know how to declare the funtions before it reach the int main?
#include <iostream>
#include <cstdlib>
#include <fstream>
using namespace std;
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
void closeFile()
{
input.close();
}
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
void PressAnyKeyToContinue(void)
{
system("pause"); //pauses the system until you press a key
system("cls"); //clears the screen
}
//-----------------------------------------------------------------------------
// Display A basic report Header
//-----------------------------------------------------------------------------
void DisplayHeader(void)
{
cout << "Name\tCP1\tMath\tEnglish" <<endl;
cout << "---------------------------------------------" <<endl;
}
//-----------------------------------------------------------------------------
// Example view the contents of a file
//-----------------------------------------------------------------------------
void ViewAllInformation()
{
int m1,m2,m3;
string name;
openFile(); // must open the file before use
DisplayHeader();
while (!input.eof()) // stop if End Of File is reached
{
input >> name >> m1 >> m2 >> m3; // reads a line from the file
if (!input.fail()) // checks if the last line is read
{
cout << name << "\t"<< m1 << "\t"<< m2 << "\t"
<< m3<< endl;
}
}
closeFile(); // must close the file
cout << endl << endl; // create 2 empty lines after display
}
//------------------------------------------------------------------------------
// A menu item 2 sample module showing how to implement menu items
// as functions
//------------------------------------------------------------------------------
void TestOption(void)
{
cout << "Display a submenu or display Information"
<< endl<< endl;
}
//-----------------------------------------------------------------------------
// A function that displays a menu and returns the option selected as an integer
// number
//-----------------------------------------------------------------------------
int MainMenu (void)
{
int choice=0;
bool gotInput = false;
cout << "=====================================" << endl;
cout << " Main Menu" << endl;
cout << "=====================================" << endl;
cout << "1. View all information" << endl;
cout << "2. Statistics By Subject " << endl;
cout << "3. Overall Statistics" << endl;
cout << "4. Exit" << endl;
cout << "=====================================" << endl;
do { //Do not modify this loop
cout << "Please input your choice:"; //and accept it as it is.
if(!(cin >> choice)) //loop to make sure
{ //that only valid options
cin.clear(); //are entered.
cin.ignore(10000,'\n');
gotInput = true;
}
if (choice >= 1 && choice<=9) gotInput = true;
} while(!gotInput);
return choice; //return the selected choice
}
//-----------------------------------------------------------------------------
// The main function where execution starts
//-----------------------------------------------------------------------------
int main()
{
int choice;
bool flag = false;
int m1,m2,m3;
string name;
//
//This loop will interpret the menu selection
// and executes the correct module (function).
//It will terminate if the selection is 4
//
do{
choice = MainMenu(); //get the choice
system("cls");
if (choice == 1) ViewAllInformation();
else if (choice == 2) TestOption();
else if (choice == 3) TestOption();
else if (choice == 4) flag = true;
else cout << "use only number shown in the menu" << endl;
if(!flag) PressAnyKeyToContinue();
}while (!flag);
int English
{
int choice=0;
bool gotInput = false;
bool flag = false;
cout << "=====================================" << endl;
cout << "Statistis of CPI" << endl;
cout << "=====================================" << endl;
cout << "1. Overall" << endl;
cout << "2. Display list of students based on grade " << endl;
cout << "3. Exit" << endl;
cout << "=====================================" << endl;
do { //Do not modify this loop
cout << "Please input your choice:"; //and accept it as it is.
if(!(cin >> choice)) //loop to make sure
{ //that only valid options
cin.clear(); //are entered.
cin.ignore(10000,'\n');
gotInput = true;
}
if (choice >= 1 && choice<=9) gotInput = true;
} while(!gotInput);
return choice; //return the selected choice
do{
choice = ViewInformation(); //get the choice
system("cls");
if (choice == 1) ();
else if (choice == 2) ();
else if (choice == 3) flag = true;
else cout << "use only number shown in the menu" << endl;
if(!flag) PressAnyKeyToContinue();
}while (!flag);
}
int Math
{
int choice=0;
bool gotInput = false;
bool flag = false;
cout << "=====================================" << endl;
cout << "Statistis of CPI" << endl;
cout << "=====================================" << endl;
cout << "1. Overall" << endl;
cout << "2. Display list of students based on grade " << endl;
cout << "3. Exit" << endl;
cout << "=====================================" << endl;
do { //Do not modify this loop
cout << "Please input your choice:"; //and accept it as it is.
if(!(cin >> choice)) //loop to make sure
{ //that only valid options
cin.clear(); //are entered.
cin.ignore(10000,'\n');
gotInput = true;
}
if (choice >= 1 && choice<=9) gotInput = true;
} while(!gotInput);
return choice; //return the selected choice
do{
choice = ViewInformation(); //get the choice
system("cls");
if (choice == 1) ();
else if (choice == 2) ();
else if (choice == 3) flag = true;
else cout << "use only number shown in the menu" << endl;
if(!flag) PressAnyKeyToContinue();
}while (!flag);
}
int CPI
{
int choice=0;
bool gotInput = false;
bool flag = false;
cout << "=====================================" << endl;
cout << "Statistis of CPI" << endl;
cout << "=====================================" << endl;
cout << "1. Overall" << endl;
cout << "2. Display list of students based on grade " << endl;
cout << "3. Exit" << endl;
cout << "=====================================" << endl;
do { //Do not modify this loop
cout << "Please input your choice:"; //and accept it as it is.
if(!(cin >> choice)) //loop to make sure
{ //that only valid options
cin.clear(); //are entered.
cin.ignore(10000,'\n');
gotInput = true;
}
if (choice >= 1 && choice<=9) gotInput = true;
} while(!gotInput);
return choice; //return the selected choice
do{
choice = ViewInformation(); //get the choice
system("cls");
if (choice == 1) ();
else if (choice == 2) ();
else if (choice == 3) flag = true;
else cout << "use only number shown in the menu" << endl;
if(!flag) PressAnyKeyToContinue();
}while (!flag);
}
int MenuSubject
{
int choice=0;
bool gotInput = false;
bool flag = false;
cout << "=====================================" << endl;
cout << " Statistic By Menu Subject" << endl;
cout << "=====================================" << endl;
cout << "1. CPI" << endl;
cout << "2. Mathematics " << endl;
cout << "3. English" << endl;
cout << "4. Exit" << endl;
cout << "=====================================" << endl;
do { //Do not modify this loop
cout << "Please input your choice:"; //and accept it as it is.
if(!(cin >> choice)) //loop to make sure
{ //that only valid options
cin.clear(); //are entered.
cin.ignore(10000,'\n');
gotInput = true;
}
if (choice >= 1 && choice<=9) gotInput = true;
} while(!gotInput);
return choice; //return the selected choice
do{
choice = ViewInformation(); //get the choice
system("cls");
if (choice == 1) CPI();
else if (choice == 2) Math ();
else if (choice == 3) English();
else if (choice == 4) flag = true;
else cout << "use only number shown in the menu" << endl;
if(!flag) PressAnyKeyToContinue();
}while (!flag);
}
int ViewInformation
{
int choice=0;
bool gotInput = false;
bool flag = false;
cout << "=====================================" << endl;
cout << " View Information" << endl;
cout << "=====================================" << endl;
cout << "1. View all information" << endl;
cout << "2. Statistics By Subject " << endl;
cout << "3. Overall Statistics" << endl;
cout << "4. Exit" << endl;
cout << "=====================================" << endl;
do { //Do not modify this loop
cout << "Please input your choice:"; //and accept it as it is.
if(!(cin >> choice)) //loop to make sure
{ //that only valid options
cin.clear(); //are entered.
cin.ignore(10000,'\n');
gotInput = true;
}
if (choice >= 1 && choice<=9) gotInput = true;
} while(!gotInput);
return choice; //return the selected choice
do{
choice = ViewInformation(); //get the choice
system("cls");
if (choice == 1) ViewAllInformation();
else if (choice == 2) MenuSubject();
else if (choice == 3)();
else if (choice == 4) flag = true;
else cout << "use only number shown in the menu" << endl;
if(!flag) PressAnyKeyToContinue();
}while (!flag);
}
return 0;
}