TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: FRANK MASINGILL
from: KURT KUZBA
date: 1997-08-29 13:35:00
subject: Mathplay.Cpp

FM>   The OOP program examples one sees in the books I have
FM>   (and I have a few) seem to avoid not only placing color
FM>   in the programs and menus but even avoid discussing it.
   That is because your basic C++ is a lot like your basic C.
   You don't have any idea what type of output devices you have,
   and may not assume a color output. cout does not support any
   color or cursor control, just as printf() does not.
   When you get into something like a Windows environment, or
   even with compilers specifically designed for a minimum
   system configuration which includes color video, such as
   Borland or Turbo C++, then you find your color controls.
   A standard implementation of such features is neither
   desirable nor practical, hence their absence.
   an interesting C++ wrapper may be implemented, however.
void Colorout(char *pszS, int yH=0, int xV=0, intiF=0, int iB=0)
{
   static int iForeColor = 3, iBackColor = 1,
              yValue = 1, xValue = 1;
   iForeColor = iF ? iF : iForeColor;
   iBackColor = iB ? iB : iBackColor;
   yValue = yH ? yH : yValue;
   xValue = xV ? xV : xValue;
   gotoxy(yValue, xValue);
   textattr(((iBackColor - 1) << 4) + iForeColor - 1);
   cprintf(pszS);
}
   Now you can use a simple call for all your output, though
   your text must already be formatted, as with sprintf().
   You will find this necessary in Windows programming also.
   the following code:
textcolor(11);
textbackground(1);
gotoxy(30, 12);
cputs("Thank you for playing!\n\r");
   now is reduced to:
Colorout("Thank you for playing!\n\r\n\r", 30, 12, 11+1, 1+1);
   I can see that the +1 on the colors makes no sense, until you
   consider that you may now set your colors once, and from then
   on, if you do not need to set them, you could simply use:
Colorout("Thank you for playing!\n\r\n\r", 30, 12);
   You could, similary, use the default cursor location:
Colorout("Thank you for playing!\n\r\n\r");
   Or you could change the color but not the location:
Colorout("Thank you for playing!\n\r\n\r", 0, 0, 11+1, 1+1);
   Or you could use embedded color control sequences with
   putch(), assuming a Borland compiler, and only have your
   location given as optional arguments. How much you increase
   your modularity and the reusability of code modules is
   pretty much a balance between reasonable and ridiculous.
   You could make the entire program from reusable modules, but
   they are somewhat specialized, so it would be ridiculous.
   Such things as output and input, however, are of general use
   and making them modular is quite reasonable since they appear
   in so many places in your code. Grouping code with the data
   it uses is a prime commandment of Object Orientation, so the
   use of global variables for variables not used by ALL the
   code is one of the cardinal sins of modular programming.
   Whew!! I think I need to take a nap now. :)
> ] Antimatter containment field failing. Dump standard .LIBs...
---
---------------
* 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™.