TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: FRANK MASINGILL
from: JERRY COFFIN
date: 1997-08-23 09:29:00
subject: MATHPLAY.CPP 09:29:2808/23/97

On (22 Aug 97) Frank Masingill wrote to All...
 FM> int menu()
 FM> {
 FM>    c=30;
 FM>    clrscr();
 FM>    gotoxy(c,10);
 FM>    textcolor(14);
 FM>    cputs("Would you like to practice a little ");
[ more similar stuff elided ]
While this works perfectly fine the way it is, you might consider
separating the data from the code.  This way you can make changes in the
wording, placement and colors of your menus without having to recompile
your entire program.  For instance, you could create a routine that
reads a menu in from a text file, and displays it.
/* file format */
num_entries
label, x, y, color
label, x, y, color  /* repeated a total of num_entries times */
so the menu above would be:
6
Would you like to practice a little , 30, 10, 14
1. Addition?, 35, 11, 9
2. Subtraction?, 35, 12, 10
3. Multiplication?, 35, 13, 13
4. Division?, 35, 14, 11
5. Quit?, 35, 15, 11
and the routine would be something like this:
#include 
#include 
class line {
// code to handle one line of a menu.
// is able to read a line from a text file, and
// display the line at its place on the screen.
//
    char label_[256];
    unsigned int x_, y_, color_;
public:
    istream &read(istream &stream) {
        char ignore;
        stream.getline(label_, 256);    // discard leading junk.
        stream.getline(label_, 256, ',');
        stream >> x_ >> ignore >> y_ >> ignore >> color_;
        return stream;
    }
    void show() {
        textcolor(color_);
        gotoxy(x_, y_);
        cputs(label_);
    }
};
istream &operator>>(istream &stream, line &data) {
    return data.read(stream);
}
class menu {
    line *lines;
    unsigned num_lines;
public:
    menu() : lines(0), num_lines(0) {}
    istream &read(istream &stream) {
        stream >> num_lines;
        lines = new line[num_lines];
        for (int i=0; i * Origin: Point Pointedly Pointless (1:128/166.5)

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™.