Computer Science 2574
Intro to Data Structures & Soft Eng

Menus.cpp

void ProgramMenu();
void FileMenu();
void ViewMenu2();
void KeyMenu();
void CalculateMenu();

//****************************************************************************
// Function:	 odbmenu
// Purpose:		 To display the odb menu and read in the choice.
// Called By:	 BuildList, main, NotAvail, ProgramMenu, DisplayKeys, Open,
//				 Save, Close, Statistics, ChangeKey, ReGrade, Stop, EditSSN,
//				 EditName, EditForm, EditGroup, EditChair, EditAnswer, EditMemo
// Calls:		 ProgramMenu, FileMenu, Viewmenu2, KeyMenu, CalculateMenu
// Parameters:	 NONE
// Return Value: void
// Authors:		 John W. Boyd III & Cullen J. Morris
// Version:		 1.1     
//****************************************************************************

#include "odb.h"

void odbmenu()
{
	char odbchar;

	cout << endl << "\t(P)rogram, (F)ile, (V)eiw, (K)eys, or (C)alculate" << endl;
	cin >> odbchar;
	while ((odbchar != 'P') && (odbchar != 'F') && (odbchar != 'E') && (odbchar != 'V') &&
		   (odbchar != 'K') && (odbchar != 'C'))
	//makes sure they input the right character
	{
		cout << "\tInvalid response, please re-enter." << endl;
		cin >> odbchar;
	}
	
	switch (odbchar) //determines which letter odbchar is, and calls the correct
	{                //function or exits the switch
		case 'P': ProgramMenu();
				  break;
		case 'F': FileMenu();
				  break;
		case 'V': ViewMenu2();
			      break;
		case 'K': KeyMenu();
			      break;
		case 'C': CalculateMenu();
			      break;
	} //end switch
}


//**************************************************************************
// Function:	 ProgramMenu
// Purpose:		 To display the program menu
// Called By:	 odbmenu
// Calls:		 AboutScreen, HelpScreen, odbmenu
// Parameters:	 NONE
// Return Value: void
// Authors:		 John W. Boyd III & Cullen J. Morris
// Version:		 1.1
//**************************************************************************
#include "screens.h"

void ProgramMenu()
{
	char menuchar;

	cout << "\t(A)bout or (H)elp" << endl;
	cin >> menuchar;

	while (menuchar != 'A' && menuchar != 'H')
		cin >> menuchar;

	clearscreen();

	switch(menuchar)
	{
		case 'A': startscreen();
			      break;
		case 'H': helpscreen();
			      break;
	}//switch

	odbmenu();

}

//**************************************************************************
// Function:	 FileMenu
// Purpose:		 To display the file menu
// Called By:	 odbmenu
// Calls:		 BuildODB, Open, Save, SaveAs, Close, Escape
// Parameters:	 NONE
// Return Value: void
// Authors:		 John W. Boyd III & Cullen J. Morris
// Version:		 1.1		 
//**************************************************************************
#include "buildodb.h"
#include "opencloseview.h"

void FileMenu()
{
	
	ifstream infile;
	
	char menuchar,
		 ODBFileName[NameLength] = "";

	int savenum = 1,
		DisplayNum = 0;

	cout << "\t(D)ecipher, (O)pen, (S)ave, save(A)s, (C)lose, or (Q)uit" << endl;
	cin >> menuchar;

	while (menuchar != 'D' && menuchar != 'O' && menuchar != 'S'
		   && menuchar != 'A' && menuchar != 'C' && menuchar != 'Q')
		   // checks for vaild menuchar
		cin >> menuchar;

	switch(menuchar)
	// calls function depending on menuchar
	{
		case 'D': BuildODB();
			      break;
		case 'O': Open();
			      break;
		case 'S': Save();
			      break;
		case 'A': SaveAs();
			      break;
		case 'C': Close(infile);//have to do something about passing the 
			      break;  //output file stream variable to it so it
		                  //knows what file to close
		case 'Q': Escape();
	}

}

//**************************************************************************
// Function:	 EditMenu
// Purpose:		 To display the edit menu and call the selected function
// Called By:	 viewmenu
// Calls:		 EditSSN, EditForm, EditName, EditGroup, EditChair, SameScreen
//				 clearscreen, viewmenu,EditAnswer, EditMemo
// Parameters:	 int DisplayNum - determines what student info is displayed
// Return Value: void
// Authors:		 John W. Boyd III & Cullen J. Morris
// Version:		 1.1     
//**************************************************************************
#include "BuildList.h"
#include "displayoptns.h"

void EditMenu(int DisplayNum)
{
	
	char menuchar,
		 tmpchar;

	cout << "\t(S)SN, (N)ame, (F)orm, (G)roup, (C)hair#, (A)nswer, or ";
	cout << "(M)emo" << endl;
	cin >> menuchar;

	while (menuchar != 'S' && menuchar != 'N' && menuchar != 'F'
		   && menuchar != 'G' && menuchar != 'C' && menuchar != 'A'
		   && menuchar != 'M')
	// checks for valid menuchar
		cin >> menuchar;

	clearscreen();
	
	if (DisplayNum == ResultNum)
	// checks to see if user can edit fields
	{
		switch(menuchar)
		// calls functions for editing
		{
			case 'S': EditSSN();
				      break;
			case 'N': EditName();
				      break;
			case 'F': EditForm();
				      break;
			case 'G': EditGroup();
		   		      break;
			case 'C': EditChair();//have to do something about passing the 
				      break;  //output file stream variable to it so it
							    //knows what file to close
			default : SameScreen(DisplayNum);
					  cout << " Invalid operation.  Press enter to continue." << endl;
					  scanf("%c",&tmpchar); //read in a character from the keyboard
					  while(tmpchar != '\n') //make sure the character is the newline
					  {
						  scanf("%c",&tmpchar);
					  }
					  clearscreen();
					  SameScreen(DisplayNum);
					  viewmenu(DisplayNum);
					  break;

		}
	}
	else 
	{
		switch (menuchar)
		// calls functions for editing
		{
			case 'A': EditAnswer();
				      break;
			case 'M': EditMemo();
				      break;
		    default : SameScreen(DisplayNum);
					  cout << " Invalid operation.  Press enter to continue." << endl;
					  scanf("%c",&tmpchar); //read in a character from the keyboard
					  while(tmpchar != '\n') //make sure the character is the newline
					  {
						  scanf("%c",&tmpchar);
					  }
					  clearscreen();
					  SameScreen(DisplayNum);
					  viewmenu(DisplayNum);
					  break;
		}
	}
}


//****************************************************************************
// Function:	 ViewMenu2
// Purpose:		 to inform the user what they can view and dispaly it for them
// Called By:	 odbmenu 
// Calls:		 DisplayResults, DisplayAnswer, DisplayKeys, Statistics
// Parameters:	 NONE
// Return Value: void
// Authors:		 John W. Boyd III & Cullen J. Morris
// Version:		 1.1
//****************************************************************************
#include "BuildList.h"

void ViewMenu2()
{
	
	char menuchar;
	int showstat = 1;

	cout << "\t(R)esults, (A)nswers, (K)eys, or ";
	cout << "(S)tatistcs" << endl;
	cin >> menuchar;

	while (menuchar != 'R' && menuchar != 'A' && menuchar != 'K'
		   && menuchar != 'S')
	// checks for valid input char
		cin >> menuchar;

	switch(menuchar)
	// calls appropriate display functions
	{
		case 'R': DisplayResults();
			      break;
		case 'A': DisplayAnswer();
			      break;
		case 'K': DisplayKeys();
			      break;
		case 'S': Statistics(showstat);
			      break;
	}
}

//**************************************************************************
// Function:	 KeyMenu
// Purpose:		 To display the key menu and call the selected function
// Called By:	 odbmenu
// Calls:		 NotAvail, ChangeKey
// Parameters:	 NONE
// Return Value: void
// Authors:		 John W. Boyd III & Cullen J. Morris
//**************************************************************************
#include "BuildList.h"

void KeyMenu()
{
	char menuchar;

	cout << "\t(A)lternative, (C)hange, or (P)artial" << endl;
	cin >> menuchar;

	while (menuchar != 'A' && menuchar != 'C' && menuchar != 'P')
		// checks for vaild input
		cin >> menuchar;

	switch(menuchar)
	// calls appropriated display function
	{
		case 'A': NotAvail();
			      break;
		case 'C': ChangeKey();
			      break;
		case 'P': NotAvail();
			      break;
	}//switch
	
}


//**************************************************************************
// Function:	 CalculateMenu
// Purpose:		 Displays a menu of calculate options
// Called By:	 odbmenu
// Calls:		 Regrade, NotAvail, Statistics
// Parameters:	 NONE
// Return Value: void
// Authors:		 John W. Boyd III & Cullen J. Morris
// Version:		 1.1
//**************************************************************************
void CalculateMenu()
{
	char menuchar;

	int showstat = 0;

	cout << "\t(C)hoices, (G)rades, (H)istogram, or (S)tatistics" << endl;
	cin >> menuchar;

	while (menuchar != 'C' && menuchar != 'G' && menuchar != 'H' && menuchar != 'S')
		// checks for valid menuchar
		cin >> menuchar;

	switch(menuchar)
	// calls approriate function
	{
		case 'G': ReGrade();
			      break;
		case 'C': NotAvail();
			      break;
		case 'H': NotAvail();
			      break;
		case 'S': Statistics(showstat);
				  break;
	}//switch
}


//**************************************************************************
// Function:	 NotAvail
// Purpose:		 Displays a message saying that the selected option is not available
// Called By:	 CalculateMenu, KeyMenu	
// Calls:		 clearscreen, odbmenu
// Parameters:	 NONE
// Return Value: void
// Authors:		 John W. Boyd III & Cullen J. Morris
// Version:		 1.1
//**************************************************************************

void NotAvail()
{
	char tmpchar;
	
	clearscreen();

	cout << endl << "This option is not available in the shareware version of DOG." << endl;
	cout << endl << "Press enter to continue." << endl;

	scanf("%c",&tmpchar); //read in a character from the keyboard
	while(tmpchar != '\n') //make sure the character is the newline
	{
		scanf("%c",&tmpchar);
	}

	clearscreen();

	odbmenu();
}