TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: JERRY COFFIN
from: KURT KUZBA
date: 1997-09-04 05:17:00
subject: MATHPLAY.CPP kk3.0 1/3

JC>   However, I've been keeping an eye on the versions you've
JC>   posted here. If you come up with any more, I'd certainly
JC>   appreciate your posting them as well.
   I hope you never regret typing that last part. :)
   This is highly Borland specific, as far as screen control
   is concerned.
/*   MATHPLAY.CPP   PUBLIC DOMAIN   version kk3.0   1/3   */
/*   Adapted from original code by Frank Massingill       */
#include 
#include 
#include 
#include 
class Mathcalc {
public:
   void virtual Calc() = 0;
   void Display(void);
   void First(void);
   void Second(void);
   void Guess(void);
   void Result(void);
   void Play(void);
protected:
   void Right(void)
   {
      pszAnswer = (iAnswer == iGuess)
      ?   "Right! The answer is"
      :   "The correct answer is";
   }
 
   char *pszTutor, *pszFirst, *pszSecond, *pszGuess, *pszAnswer;
   int iFirst, iSecond, iGuess, iAnswer;
};
class Addition : public Mathcalc {
public:
   Addition(void);
   void Calc(void) { iAnswer = iFirst + iSecond; }
};
class Subtraction : public Mathcalc {
public:
   Subtraction(void);
   void Calc(void) { iAnswer = iFirst - iSecond; }
};
class Multiplication : public Mathcalc {
public:
   Multiplication(void);
   void Calc(void) { iAnswer = iFirst * iSecond; }
};
class Division : public Mathcalc {
public:
   Division(void);
   void Calc(void) { iAnswer = iFirst / (iSecond ? iSecond : 1); }
};
void Mathcalc::Display(void)
{
   textattr(2);
   window(1, 1, 80, 25);
   clrscr();
   window(10, 4, 70, 14);
   cputs(pszTutor);
   textattr(0x2f);
   window(10, 15, 70, 23);
   clrscr();
}
void Mathcalc::First(void)
{
   textattr(0x1f);
   window(12, 16, 68, 22);
   clrscr();
   window(13, 17, 67, 21);
   gotoxy(1, 1);
   cprintf("%25s : ", pszFirst);
   cin >> iFirst;
}
void Mathcalc::Second(void)
{
   gotoxy(1, 2);
   cprintf("%25s : ", pszSecond);
   cin >> iSecond;
}
void Mathcalc::Guess(void)
{
   gotoxy(1, 3);
   cprintf("%25s : ", pszGuess);
   cin >> iGuess;
   Calc();
   Right();
}
void Mathcalc::Result(void)
{
   gotoxy(1, 4);
   cprintf("%25s : %d", pszAnswer, iAnswer);
}
/*   end   MATHPLAY.CPP   1/3   */
> ] When this message is over, you will awake feeling refreshed.
---
---------------
* Origin: *YOPS ]I[* 3.1 GIG * RA/FD/FE RADist * Milwaukee, WI (1:154/750)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.