// -------------------------------------------------------------------//
// Name: Huy Nguyen                                                   //
// Date:  6/5/1999                                                    //
// Project: Classes and inheritance                                   //
// File name : game.cpp                                                //
// 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.

football::football(char name2[len])
{
  strcpy (name, name2);
  total = 1;
  winning = 0;
  lose = 0;
  winpercent = 0.00;
  touchdowns = 0;
  interceptions = 0;
  per = 0.00;
  per1 = 0.00;

}


//-------------------------------------------------------------------
// 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(double per, double per1)
{
  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 football::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 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 name5[len])
{
  strcpy (name3, name5);
  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 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-----------------------
