--------------- FIDO MESSAGE AREA==> TOPIC: 203 C++ Ref: ECT00007 Date: 08/22/97 From: JERRY COFFIN Time: 11:39pm \/To: THOMAS MAEDER (Read 3 times) Subj: fstream identifying mode On (13 Aug 97) Thomas Maeder wrote to Jerry Coffin... TM> The member/base initialization list syntax can only be used in TM> constructors. Oops - quite right. JC> int mode() { JC> return mode_; JC> } TM> Better declare this method const. Twouldn't hurt, but then again, I'm not sure I've ever seen a const stream, so I doubt it makes any real difference. If you did somehow have a const stream, about ALL you'd be able to do with it would be get its mode, and perhaps flags and such. You obviously wouldn't be able to read/write it, and a stream you can't read or write seems awfully close to useless at first glance. Later, Jerry. ... The Universe is a figment of its own imagination. --- PPoint 1.90 * Origin: Point Pointedly Pointless (1:128/166.5) --------------- FIDO MESSAGE AREA==> TOPIC: 203 C++ Ref: ECT00008 Date: 08/23/97 From: JERRY COFFIN Time: 09:29am \/To: FRANK MASINGILL (Read 3 times) Subj: 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 int main() { ifstream input("menu.dat"); menu m; m.read(input); m.show(); return 0; } #endif Since this is getting kind of long, I'll got into comments on the rest in the next message... Later, Jerry. ... The Universe is a figment of its own imagination. --- PPoint 1.90 * Origin: Point Pointedly Pointless (1:128/166.5) --------------- FIDO MESSAGE AREA==> TOPIC: 203 C++ Ref: ECT00009 Date: 08/23/97 From: JERRY COFFIN Time: 09:31am \/To: FRANK MASINGILL (Read 3 times) Subj: MATHPLAY.CPP 09:31:5508/23/97 On (22 Aug 97) Frank Masingill wrote to All... FM> do FM> { FM> gotoxy(c,17); FM> textcolor(15); FM> cputs("Enter your choice: "); FM> scanf("%d", &i); FM> switch(i) FM> { FM> case 1: addCalc(); clrscr(); menu(); break; FM> case 2: minusCalc(); clrscr(); menu(); break; FM> case 3: multCalc(); clrscr(); menu(); break; FM> case 4: divCalc(); clrscr(); menu(); break; FM> case 5: FM> clrscr(); FM> gotoxy(c,12); FM> textcolor(11); FM> cputs("Thanks for playing!"); FM> exit(0); FM> } // end switch statement FM> }while (i < '1' || i > 5); FM> return i; FM> } Okay, here we've got a more serious problem: we're calling menu() again every time we do something. What we need is to repeat the menu without calling it again, something like this: do { gotoxy(c, 17); textcolor(15); cputs("Enter your choice: "); scanf("%d", &i); switch (i) { case 1: addCalc(); break; case 2: minusCalc(); break; case 3: multCalc(); break; case 4: divCalc(); break; case 5: clrscr(); gotoxy(c, 12); textcolor(11); cputs("Thanks for playing!"); break; } while ( i != 5 ); this repeatedly waits for you to enter a key until you push '5'. However, you can make it a bit nicer for the user by using getch() instead of scanf() to read the character. This way, they only have to push one digit, and not the enter key: do { // ... cputs("Enter your choice: "); ch = getch(); switch(ch) { case '1': addCalc(); break; case '2': minusCalc(); break; // ... } // ... } while (ch != '5'); That's all I'm going to go into for now. There's a lot more along this line that _could_ be gone into, but I'll let you work at figuring this out before I try to go into anything more complex. Later, Jerry. ... The Universe is a figment of its own imagination. --- PPoint 1.90 * Origin: Point Pointedly Pointless (1:128/166.5) --------------- FIDO MESSAGE AREA==> TOPIC: 203 C++ Ref: ECT00010 Date: 08/23/97 From: LARRY RINK Time: 08:34am \/To: LESLIE SATENSTEIN (Read 3 times) Subj: Apl LS> Again, contact me at LS> leslie@contact.net Can't. I don't use the internet. Can I not Netmail you at 1:167/133 ?? -Larry --- Maximus 3.01 * Origin: THE GOAT'S PEN 414/820-9092 Sussex, Wi. U.S.A. (1:154/500) --------------- FIDO MESSAGE AREA==> TOPIC: 203 C++ Ref: ECT00011 Date: 08/23/97 From: FRANK MASINGILL Time: 10:28pm \/To: CLIFF RHODES (Read 3 times) Subj: MATHPLAY.CPP Cliff, here is the program after I made the changes you suggested. I do hope to develop it into a full-fledged C++ with some object-oriented features and I'm studying all of the examples I can find in my books and disks. I started this as a project for the kids next door to play with when we keep them and wanted to get it to the point where they could play with it. I am, as you suggested, looking at the four math routines. In addition to making the changes you told me about I also changed the color scheme so that, e.g., if the kid calls the Multiplication part it will come up in exactly the colors of the line chose in the menu. I hope to dress that up in time as well. Thanks to you it's in good shape for them to play with now and I can begin seeing how some class might be put in it. As you saw, I also had a message from Jerry Coffin with some suggestions along that line. So here it is as you and Kurt Kuzba steered me. In time I'll certainly take out that mixture of C and C++. I have been interested in preserving the color. Also, I know I'll eventually put the prototypes, etc., in a header file. MATHPLAY.CPP: #include #include #include #include #include // for exit statement int num1, num2, guess, ans ; addCalc(); minusCalc(); multCalc(); divCalc(); void promptc(int x, int y, int color , const char *p); int menu(); main() { int col; while (menu()) ; clrscr(); gotoxy(col,12); textcolor(11); cputs("Thanks for playing"); return 0; } int menu() { int i, col ; col=30; clrscr(); promptc(col, 10, 14, "Would you like to practice a little"); col=35; promptc(col, 12, 14, "1. Addition?"); promptc(col, 13, 10, "2. Subtraction?"); promptc(col, 14, 13, "3. Multiplication?"); promptc(col, 15, 11, "4. Division?"); promptc(col, 16, 12, "5. or just Quit?"); do { gotoxy(col,20); textcolor(15); cputs("Enter your choice: "); scanf("%d", &i); switch(i) { case 1: addCalc(); break; case 2: minusCalc(); break; case 3: multCalc(); break; case 4: divCalc(); break; case 5: break; } }while (i < 1 || i > 5); return (i == 5) ? 0 : 1; } addCalc() { clrscr(); int col=20; gotoxy(col, 10); textcolor(14); cputs("ADDITION PROBLEM:"); gotoxy(col, 12); cputs("Type in the first number (Addend)? "); cin >> num1; gotoxy(col, 13); cputs("Type in the second number (Addend)? "); cin >> num2; ans = num1 + num2; gotoxy(col, 14); cputs("What do you think is the answer (called the SUM)? "); cin >> guess; gotoxy(col, 15); cprintf("The answer is "); textcolor(15); cprintf("%d", ans); textcolor(2); gotoxy(col, 16); cprintf("You guessed %s", (ans == guess) ? "right!" : "wrong."); cout << endl; gotoxy(col, 18); cprintf("Would you like to try another (Y/N)? "); do { guess = (0 == (guess = getch())) ? -getch() : guess; guess = toupper(guess); } while(guess != 'Y' && guess != 'N'); textcolor(14); gotoxy(col,22); cprintf("Press any key"); getch(); return 0; } minusCalc() { clrscr(); int col=20; gotoxy(col, 10); textcolor(10); cputs("SUBTRACTION PROBLEM:"); gotoxy(col, 12); cputs("Type in the Minuend (number to subract FROM: "); cin >> num1; gotoxy(col, 13); cputs("Now, type in the Subtrahend (number to subract: "); cin >> num2; ans = num1 - num2; gotoxy(col, 14); cputs("What do you think is the answer (REMAINDER)? "); cin >> guess; gotoxy(col, 15); cprintf("The answer is "); textcolor(15); cprintf("%d", ans); textcolor(10); gotoxy(col, 16); cprintf("You guessed %s", (ans == guess) ? "right!" : "wrong."); cout << endl; gotoxy(col, 18); cprintf("Would you like to try another (Y/N)? "); do { guess = (0 == (guess = getch())) ? -getch() : guess; guess = toupper(guess); } while(guess != 'Y' && guess != 'N'); textcolor(10); gotoxy(col,22); cprintf("Press any key"); getch(); return 0; } multCalc() { clrscr(); int col=20; gotoxy(col, 10); textcolor(13); cputs("MULTIPLICATION PROBLEM:"); gotoxy(col, 12); cputs("Type in the number to be multiplied (MULTIPLICAND): "); cin >> num1; gotoxy(col, 13); cputs("Type in the number to multiply it by (MULTIPLIER): "); cin >> num2; ans = num1 * num2; gotoxy(col, 14); cputs("What do you think is the answer (PRODUCT)? "); cin >> guess; gotoxy(col, 15); cprintf("The answer is "); textcolor(15); cprintf("%d", ans); textcolor(13); gotoxy(col, 16); cprintf("You guessed %s", (ans == guess) ? "right!" : "wrong."); cout << endl; gotoxy(col, 18); cprintf("Would you like to try another (Y/N)? "); do { guess = (0 == (guess = getch())) ? -getch() : guess; guess = toupper(guess); } while(guess != 'Y' && guess != 'N'); textcolor(13); gotoxy(col,22); cprintf("Press any key"); getch(); return 0; } divCalc() { clrscr(); int col=20; gotoxy(col, 10); textcolor(11); cputs("DIVISION PROBLEM:"); gotoxy(col, 12); cputs("Type in the number to be divided (DIVIDEND): "); cin >> num1; gotoxy(col, 13); cputs("Type in the number to divide it by (DIVISOR): "); cin >> num2; ans = num1 / num2; gotoxy(col,14); cputs("What do you think is the answer (QUOTIENT): "); cin >> guess; gotoxy(col, 15); cprintf("The answer is "); textcolor(15); cprintf("%d", ans); textcolor(11); gotoxy(col, 16); cprintf("You guessed %s", (ans == guess) ? "right!" : "wrong."); cout << endl; gotoxy(col, 18); cprintf("Would you like to try another (Y/N)? "); do { guess = (0 == (guess = getch())) ? -getch() : guess; guess = toupper(guess); } while(guess != 'Y' && guess != 'N'); textcolor(11); gotoxy(col,22); cprintf("Press any key"); getch(); return 0; } void promptc(int x, int y, int color, const char *p) { gotoxy(x,y); textcolor(color); cputs(p); } --------------------------------END CODE---------------------------- Sincerely, Frank --- PPoint 2.03 * Origin: Maybe in 5,000 years - frankmas@juno.com (1:396/45.12) --------------- FIDO MESSAGE AREA==> TOPIC: 203 C++ Ref: ECT00012 Date: 08/22/97 From: PAUL ELLIOTT Time: 09:03pm \/To: ALL (Read 3 times) Subj: Hudson Hi All, Does anyone know of any code on how to access the hudson message base? I've looked around for Hudson librarys all week and I haven't found a thing. :( Nearest i've got is the Jam API and i'm not getting very far with it. Does anyone have any code that uses it that they wouldn't mind sharing? Thanks.. Paul. >> Synergy Morph/32 [v0.13x beta] Registered to: Paul Elliott --- Synergy PostOffice/32 * Origin: Arhhhhh! I C! (2:2502/27) --------------- FIDO MESSAGE AREA==> TOPIC: 203 C++ Ref: ECT00013 Date: 08/24/97 From: KEVIN YOCHUM Time: 03:17am \/To: JEFF PATTEN (Read 3 times) Subj: Mpython So sayeth the Book of Patten, "Mpython." JJ> They are the knights that say neep! not nee. KK> class Knights_who_say_NEEK JP> The line after the demand for a shrubbery is "... But it must be JP> NEAT!!" None of those not-a-words make any sense in this context; JP> NEAT does. ;-) It's not supposed to make sense - it's Monty after all! I'll have to agree with the person who said "nee", although I'd spell it "Ni". I call it the way I've heard it. ;) -=Kevin=- Fidonet: 1:363/309 TAGnet : 21:320/0 JAMNet : 75:82/1 MirageNet: 90:802/0 SinNet : 18:28/1 Internet: kyochum@worldramp.net Internet: kevin.yochum%309@satlink.oau.org --- Blue Wave/386 v2.20 * Origin: Forethought BBS -=- Orlando, FL -=- 407-679-6561 (1:363/309) --------------- FIDO MESSAGE AREA==> TOPIC: 203 C++ Ref: ECT00014 Date: 08/23/97 From: BOB STOUT Time: 12:49pm \/To: LESLIE SATENSTEIN (Read 3 times) Subj: Zortech compiler.... On , Leslie Satenstein (1:167/133@fidonet) wrote: > I have lost contact with Walter Bright. Can you update me on his > whereabouts? Leslie... The last time I corresponded with him, he was still at Symantec, only working on their Java compiler rather than the C++ compiler. Judging by what I've seen, I suspect that the C++ compiler is considered by the Symantec PTB as a dead-end product. This is, of course, something I wouldn't expect Walter to either confirm or deny as long as it's still in the catalogue. --- QM v1.00 * Origin: MicroFirm : Down to the C in chips (1:106/2000.6) --------------- FIDO MESSAGE AREA==> TOPIC: 203 C++ Ref: ECT00015 Date: 08/23/97 From: JERRY COFFIN Time: 10:04am \/To: DARIN MCBRIDE (Read 3 times) Subj: volatile objects? On (22 Aug 97) Darin Mcbride wrote to Thomas Maeder... [ ... ] DM> I'd post it, but the hand-coded queue uses OS/2 mutex's. Mind you, if DM> I posted the entire class hiearchy, anyone who wanted to convert the DM> one mutex class to Win32 could, and the rest of the class would work DM> just fine. :-) A semaphore, in this class hiearchy, needs to: DM> Create (publically, based on a semaphore name - not used by my DM> queues) DM> Create (privately, without a semaphore name) DM> Claim (optionally with a timeout to wait for the semaphore to DM> become available) DM> Release DM> Close DM> Tell if the current thread has it claimed (note that the same DM> object can be used by multiple threads in the same process) DM> Tell if the semaphore name (in the public create) is valid DM> If this is possible in Win32, I can post what I have for OS/2... :-) As you doubtless expect, Win32's mutexes are similar enough to OS/2's that all this should be pretty trivial to port. In fact, I did something like this a long time ago, with both OS/2 and Win32 variants: // event.h // #ifdef _OS2_ #define INCL_DOSSEMAPHORES #include #define OS2(x) (x) #else #define OS2(x) #include typedef HANDLE HEV; #endif class Event { HEV *events; // Probably not really needed for OS/2, as SemRecords // is pretty much the same thing... unsigned how_many; OS2(HMUX hMux;) OS2(SEMRECORD *SemRecords;) public: Event(unsigned number); void post(unsigned number); void WaitAll(void); ~Event(); }; // event.cpp // #include "event.h" #ifdef _OS2_ #define OS2(x) x HEV CreateAnEvent(unsigned i) { HEV hEv = NULLHANDLE; char SemName[32]; (SemRecords + i)->hsemCur = NULL; (SemRecords + i)->ulUser = i; sprintf(SemName, "\\SEM32\\MT%d", i); DosCreateEventSem(SemName, &hEv, 0L, FALSE); (SemRecords + i)->hsemCur = (void *)hEv; return hEv; } void Event::WaitAll() { //Wait for the muxwait sem to post on all unsigned long ulUser; DosWaitMuxWaitSem(hMux, SEM_INDEFINITE_WAIT, &ulUser); DosCloseMuxWaitSem(hMux); } void Event::post(unsigned number) { HEV hEv = NULLHANDLE; char SemName[32]; sprintf(SemName, "\\SEM32\\MT%d", number); DosOpenEventSem(SemName, &hEv); DosPostEventSem(hEv); DosCloseEventSem(hEv); } #else #define OS2(x) HEV CreateAnEvent(unsigned i) { return CreateEvent(NULL, FALSE, FALSE, NULL); } void Event::WaitAll() { WaitForMultipleObjects(how_many, events, TRUE, INFINITE); } void Event::post(unsigned number ) { SetEvent(events[number]); } #endif Event::Event(unsigned number) { how_many = number ; events = new HEV[number]; OS2(SemRecords = new SEMRECORD[NumThreads];) for ( unsigned i=0; i