//************************************************************************
//
// Name: Huy Nguyen
// Date:  5/16/1999
// Final project: Classes and inheritance
// File name : game.h
// Description: This is the header file for the program, that declare all 
//              the neccessary global variables, library file, and all 
//              data members, and function members in the class game.
//
//************************************************************************

#include <iostream.h>            // for terminal input/output
#include <iomanip.h>             // for input/output manipulation
#include <stdlib.h>              // for exit()

const int len = 20;

// game abstract data type definition class game 


class football 

{ 

private:

  char name[len];                // name of the football team
  int winning;                   // number of winning game
  int lose;                      // number of lose
  double winpercent;             // percents of winning game
  double total;                  // number of game play
  double interceptions;          // number of interceptions in the game
  double touchdowns;             // number of touchdowns in the game
  double per;                    // average the number of touchdowns 
                                 // per game
  double per1;                   // average the number of interceptions 
                                 // per game


public:

  football();                    // constructor of the class game
  void display();                               // display function
  void show_stats(double per, double per1);     // show stats function
  void play_game();                             // play a game function

};


class baseball:public choice
{
private:

  char name3[len];                // name of the baseball team
  int winning1;                   // number of winning game
  int lose1;                      // number of lose
  double winpercent1              // percents of winning game
  double total1;                  // total of baseball games
  double home_runs;               // number of home run
  double rbis;                    // number of rbis
  double per2;                    // average number of home_run
                                  // per game
  double per3;                    // average number of rbis per game
  double errors;                  // percentage of games that have won for 
                                  // the current season.
 

public:
  
  baseball();                     // constructor of the class game
  void display1();                              // display function
  void show_stats1(double error);               // show stats function 
  void play_game1();                            // show play a game function
  
};

--------------C2DC634D0DF092BA0CF2119C
Content-Type: text/plain; charset=us-ascii;
 name="main.cpp"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="main.cpp"

//**********************************************************************
// Name: Huy Nguyen
// SSN:  622-32-4989
// Date:  5/16/1999
// Final project: Classes
// File name : main.cpp
// Description: This is the main funtion for the program, that will 
//              display the menu of the options, and will call the 
//              appropriate function upon the user's choices.
//
//**********************************************************************

#include "game.h"              // include the header file

void main()
{  
    char choice;                // user's choice
    

    while(1)  // Display Menu until the user choose to quit
    {
        // Display menu of choices

        cout << endl;
        cout << "\t********************************************\n";
        cout << "\t*                                          *\n";
        cout << "\t*  1- Play football                        *\n";
        cout << "\t*  2- Play baseball                        *\n";
        cout << "\t*  3- Quit                                 *\n";
        cout << "\t*                                          *\n";
        cout << "\t********************************************\n";

        cout << "\n\tChoice:  "; // prompt users for choice
        cin >> choice;
        cout << endl;

        // Execute user's choice

        switch (choice)
        {
        case '1':
			

            char choice1;         // user's choice

            char name1[len];      // name of the team

		 // prompt user enter the name of the team

		 cout << "\n\tPlease enter the name of the team: ";
			
		 cin.getline(name1, len, '\n');

		 // declare a variable of type football

		 baseball game(name1);

		 // open display, set the data members to some initial values

		 game.display();

		 while(1)  // Display Menu until the user choose to quit

		 // Display menu of choices

		 cout << endl;
		 cout << "\t***************************************\n";
		 cout << "\t*                                     *\n";
		 cout << "\t*  1- Display                         *\n";
		 cout << "\t*  2- Show Stats                      *\n";
		 cout << "\t*  3- Play game                       *\n";
		 cout << "\t*  4- Quit                            *\n";
		 cout << "\t*                                     *\n";
		 cout << "\t***************************************\n";

                 cout << "\n\tChoice: ";     // prompt users for choice
		 cin >> choice1;
		 cout << endl;

		 switch (choice1)
		 {
		 case '1':

                 // call the function display()

		    game.display();
		    break;

		 case '2'

                 // call the function stats()     
				  
		    game.show_stats(double per, double per1);
		    game.display();
		    break;

		 case '3'

                 // call the function play a game

		    game.play_a_game();
		    game.display();
		    break;

                 // if the person want to quit the program
		 // and if they chooce invalid code

                 case '4':
		
                 // quit the program

                 cout << "\n\n\tBye! and have a nice day :-)\n\n";
                 exit(0);

                 default:

                 // if choice is invalid display error message

                 cerr << "\n\t\tINVALID CHOICE!!! :-(\n\n";
                 break;

            	 }             // End switch statement
 
        case '2':

	    char choice3;         // user's choice

            char name3[len];      // name of the team

	    // prompt user enter the name of the team

	    cout << "\n\tPlease enter the name of the team: ";
			
	    cin.getline(name3, len, '\n');

	    // declare a variable of type football

	    baseball game(name3);

	    // open display, set the data members to some initial values

	    game.display1();

	    while(1)  // Display Menu until the user choose to quit

	    // Display menu of choices

	    cout << endl;
	    cout << "\t***************************************\n";
	    cout << "\t*                                     *\n";
	    cout << "\t*  1- Display                         *\n";
	    cout << "\t*  2- Show Stats                      *\n";
	    cout << "\t*  3- Play game                       *\n";
	    cout << "\t*  4- Quit                            *\n";
	    cout << "\t*                                     *\n";
	    cout << "\t***************************************\n";

            cout << "\n\tChoice: ";     // prompt users for choice
	    cin >> choice1;
	    cout << endl;

	    switch (choice1)
	    {
	    case '1':

            // call the function display()

	         game.display1();
	         break;

	    case '2'

            // call the function stats()      
				  
	         game.show_stats1(double error);
		 game.display1();
		 break;

	    case '3'

            // call the function play a game

	         game.play_a_game1();
		 game.display1();
		 break;

            // if the person want to quit the program
	    // and if they chooce invalid code

            case '4':
		
                 // quit the program

                 cout << "\n\n\tBye! and have a nice day :-)\n\n";
                 exit(0);

                 default:

                      // if choice is invalid display error message

                      cerr << "\n\t\tINVALID CHOICE!!! :-(\n\n";
                      break;

              	  }             // End switch statement
 
            // if the person want to quit the program
	    // and if they chooce invalid code
		
	    case '3':

	    // quit the program

	    cout << "\n\tBye! and have a nice day: )\n";
	    exit(0);

	    default:

		// if choice is invalid display error message

	        cerr << "\n\tInvalid Choice!!!:-(\n\n";

	    }

      }                          // End of while(1)

}                                // End main()

//-------------------------------------------------------------------------

--------------C2DC634D0DF092BA0CF2119C
Content-Type: text/plain; charset=us-ascii;
 name="game.cc"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="game.cc"

//
// Name: Huy Nguyen
// SSN:  622-32-4989
// Date:  5/13/1999
// Final project: Classes and inheritance
// File name : game.cc
// Description: This is the function emplementation file, which define
//              all the member functions that of the class game.
//---------------------------------------------------------------------

#include "game.h"              // include the header file    

//-------------------------------------------------------------------
// This is the constructor of the class game. It will dynamically 
// allocate the array of numbers of different name the store owns.
// it also initializes all the data members to zero.

baseball::baseball(char name2[len], char name5[len])
{
  strcpy (name, name2);
  strcpy (name3, name5);

  total = 1;
  winning = 0;
  lose = 0;
  winpercent = 0.00;
  touchdowns = 0;
  interceptions = 0;
  per = 0.00;
  per1 = 0.00;

  total1 = 1;
  winning1 = 0;
  lose1 = 0;
  winpercent1 = 0.00;
  home_runs = 0;
  rbis = 0;
  errors = 0;
}


//-------------------------------------------------------------------
// This function will display all the data members, and update the 
// number of touchdowns and interceptions and stats.

void football::display()
{

  cout << "\n\tName of the football team: " << name;

  cout << "\n\tTotal of football game: " << total;

  cout << "\n\tThe number of touchdowns: " << touchdowns;

  cout << "\n\tThe number of interceptions: " << interceptions;

  cout << "\n\tThe average number of touchdowns per game: ";
  
  cout << setiosflags(ios::fixed | ios::showpoint << setprecision (2)
  
       << per;

  cout << "\n\tThe average number of interceptions per game: ";
  
  cout << setiosflags(ios::fixed | ios::showpoint << setprecision (2)
  
       << per1;

  cout << endl;

}


//-----------------------------------------------------------------------
// This function will calculate the statistic of the football game

void football::show_stats()
{
  per = touchdowns / total;
  per1 = interceptions / total;
  winpercent = winning / total;
  

  cout << "The average number of touchdowns per game is : ";
  cout << setiosflags(ios::fixed | ios::showpoint) << setprecision(2)
       << per;
	   
  cout << "The average number of interceptions per game is: ";
  cout << setiosflags(ios::fixed | ios::showpoint) << setprecision(2)
       << per1;
	   
  cout << "The percent of winning game is: ";
  cout << setiosflags(ios::fixed | ios::showpoint) << setprecision(2)
  cout << winning;

  cout << endl;

}

//-----------------------------------------------------------------------
// This function will update the number of games and either touchdowns
// or interceptions

void game::play_a_game()
{
  int answer;             // user's response
  int answer1;            // user's response
  char answer2;           // user's response
  char answer3;           // user's response
  do{

  //prompt user for the game is touchdowns or interceptions

  cout << "\n\tPlease enter the number of touchdowns in the game: ";
  cin >> answer;

  touchdowns = touchdowns + answer;

  cout << "\n\tPlease enter the number of interceptions in the game: ";
  cin >> answer1;

  interceptions = interceptions + answer1;

  //prompt user if he or she wins the game
  
  cout << "\n\tPlease enter the game is win or lose (w/l): ";
  cin >> answer2;

  //keep track the number of winning 

  if (answer2 == 'w')
  winning++;

  //keep track the number of losing 
   
  if (answer2 == 'l')
  lose++;

  //prompt user if he or she wants to play another game

  cout << "\n\tWould you like to play another game(y/n): ";
  cin >> answer3;

  if (answer3 == 'y')
  total++;

  }while(answer3 != 'n');   // if answer is no stop the loop

}                          // end of the function

//-------------------------------------------------------------------
// This function will display all the data members, and update the 
// number of home run and rbis and stats.

void baseball::display()
{

  cout << "\n\tName of the baseball team: " << name3;

  cout << "\n\tTotal of baseball game: " << total1;

  cout << "\n\tThe number of home run: " << home_runs;

  cout << "\n\tThe number of rbis: " << rbis;

  cout << "\n\tThe average number of home_runs per game: ";
  
  cout << setiosflags(ios::fixed | ios::showpoint << setprecision (2)
  
       << home_runs;

  cout << "\n\tThe average number of rbis per game: ";
  
  cout << setiosflags(ios::fixed | ios::showpoint << setprecision (2)
  
       << rbis;

  cout << "\n\tThe number of error per game: ";

  cout << setiosflags(ios::fixed | ios::showpoint << setprecision (2)

       << errors;

  cout << endl;

}

//-----------------------------------------------------------------------
// This function will calculate the statistic of the baseball game

void baseball::show_stats()
{
  per2 = home_runs / total1;
  per3 = rbis / total1;
  errors = rbis / total1 * 100;
  winpercent1 = winning1 / total1;
  
  cout << "The average number of home runs per game is : ";
  cout << setiosflags(ios::fixed | ios::showpoint) << setprecision(2)
       << per2;
	   
  cout << "The average number of rbis per game is: ";
  cout << setiosflags(ios::fixed | ios::showpoint) << setprecision(2)
       << per3;
	   
  cout << "The percent error per game is: ";
  cout << setiosflags(ios::fixed | ios::showpoint) << setprecision(2)
  cout << errors;
  
  cout << "The percent of winning game is: ";
  cout << setiosflags(ios::fixed | ios::showpoint) << setprecision(2)
       << winpercent1; 

  cout << endl;
}

//-----------------------------------------------------------------------
// This function will update the number of games and either home run or 
// rbis
void baseball::play_a_game1()
{
  int answer4;              // user's response
  int answer5;              // user's response
  char answer6;             // user's response
  char answer7;             // user's response
  
  do{

  //prompt user for the game is touchdowns or interceptions

  cout << "\n\tPlease enter the number of home runs in the game: ";
  cin >> answer4;

  home_runs = home_runs + answer4;

  cout << "\n\tPlease enter the number of rbis in the game: ";
  cin >> answer5;

  rbis = rbis + answer5;

  //prompt user if he or she wins the game
  
  cout << "\n\tPlease enter the game is win or lose (w/l): ";
  cin >> answer6;

  //keep track the number of winning 

  if (answer6 == 'w')
  winning1++;

  //keep track the number of losing 
   
  if (answer6 == 'l')
  lose1++;

  //prompt user if he or she wants to play another game

  cout << "\n\tWould you like to play another game(y/n): ";
  cin >> answer7;

  if (answer7 == 'y')
  total1++;

  }while(answer7 != 'n');   // if answer is no stop the loop

}                          // end of the function     

//--------------------------end of the program-----------------------

