--------------- FIDO MESSAGE AREA==> TOPIC: 203 C++ Ref: ECS00003 Date: 08/13/97 From: THOMAS MAEDER Time: 05:18pm \/To: BENJAMIN L MCGEE (Read 3 times) Subj: couple of ?'s BM> class manifest { BM> public: BM> manifest(); BM> manifest(const char *filename); Better declare the 2nd constructor "explicit" to avoid silent conversions. BM> private: BM> char* select(char *filename, int len); This method could as well return bool, which would make its return value clearer. BM> manifest::manifest(const char* manfile){ BM> filename = new char[FILENAME_MAX]; BM> strncpy(filename, manfile, FILENAME_MAX - 1); This will cause you problems: strncpy will not zero-terminate filename if manfile has FILENAME_MAX - 1 characters. I'd suggest to use a string class instead of your char *. BM> How do I handle errors in opening the ifstream? Depends on what class manifest is responsible for. Options include: - do it the way the fstream classes do - throw an exception (which will make it difficult to free the memory referenced by filename if you don't change filename's type to string) BM> Is it a good idea perhaps, to just allocate space for filename withi BM> the constructor and then handle everything else in a manifest::init( BM> member? That would seem redundant to me but perhaps overloading BM> constructors is already redundant. You could just use the 2nd constructor with a default argument if you prefer: manifest(const char *filename = 0); and manifest::manifest(const char* manfile){ filename = new char[FILENAME_MAX]; if (manfile) { strncpy(filename, manfile, FILENAME_MAX - 1); *filename[FILENAME_MAX-1] = 0; } else while (!select(filename, FILENAME_MAX - 1)); mstreamp = new ifstream(filename); } Thomas --- MM 1.0 #0113 I don't care WHO you are! Get those reindeer off my roof! * Origin: McMeier & Son BBS (2:301/138) --------------- FIDO MESSAGE AREA==> TOPIC: 203 C++ Ref: ECS00004 Date: 08/13/97 From: THOMAS MAEDER Time: 05:15pm \/To: CAMERON CLARK (Read 3 times) Subj: fstream identifying m CC> The only thing I've found is in the bas class IOS. CC> Look at "Public Data Members", "open_mode". open_mode is an enumeration type, not a member variable/function. Gruss Thomas --- MM 1.0 #0113 I'm weird but around here it's hardly noticeable * Origin: McMeier & Son BBS (2:301/138) --------------- FIDO MESSAGE AREA==> TOPIC: 203 C++ Ref: ECS00005 Date: 08/13/97 From: THOMAS MAEDER Time: 05:16pm \/To: JERRY COFFIN (Read 3 times) Subj: fstream identifying mode JC> voidopen(constchar*name, intmode) : JC> mode_(mode) JC> { JC> fstream::open(name, mode); JC> } The member/base initialization list syntax can only be used in constructors. JC> int mode() { JC> return mode_; JC> } Better declare this method const. Gruss Thomas --- MM 1.0 #0113 If you call me insane again, I'll eat your other eye. * Origin: McMeier & Son BBS (2:301/138) --------------- FIDO MESSAGE AREA==> TOPIC: 203 C++ Ref: ECS00006 Date: 08/18/97 From: PETER LESCHEV Time: 06:58pm \/To: JERRY VINOKUROV (Read 3 times) Subj: Programming -=> Quoting Jerry Vinokurov to Javier Kohen <=- Hi! Here we go again! JV> Thanx a lot... but what is this GAMEDEV thing? I asked my sysop about JV> it and he doesnt know what it is... You should read GAMEDEV. If your system doesn't get it, pester your sysop! It's on the Zone 1 backbone so it's only pennies. [yes, that is a canned reply] AND Try the GAMEDEV Archive for all your game programming needs. Shop till you drop at: FTP: ftp://intranet.ca/usr/synapsis/gamedev/gamedev_archive/ OR request a copy via email: EMAIL: peter.leschev@senalink.com.au SUBJECT: I want GDA! OR F'Req: GAMEDEV from 1:153/255 [yes, this is a canned reply] CYA! Peter Leschev GameDev Archive Maintainer W!zard - Coder EMAIL: peter.leschev@senalink.com.au HTTP: web.senalink.com.au/homepage/leschev/index.htm ... I cna ytpe 300 wrods pre mniuet! --- FMail/Win32 1.22+ * Origin: Lateline BBS: Nocturnal Paradise. +61-2-9579-6564 (3:712/841) --------------- FIDO MESSAGE AREA==> TOPIC: 203 C++ Ref: ECS00007 Date: 08/22/97 From: FRANK MASINGILL Time: 02:59pm \/To: ALL (Read 3 times) Subj: MATHPLAY.CPP I probably shouldn't do this but by posting this amateurish code some of the beginners some of my fellow hobbyists who are also trying to learn something might be encouraged or see something to criticize or make the basis for discussion. There are possibly bugs in it of which I'm still unaware as it's an ongoing sort of first real project for me. Kurt Kuzba was gracious enough to let me know about cprint and get me out of a bog so I could continue and I thank him enormously for that. This is compiled with a Borland, version 3 compiler. Look at it carefully because I have no idea about such things as portability yet. I wrote it to interest the kids next door in elementary math and in the computer which they generously take over when they're here!! Any and all comments truly welcome - no matter how harsh: So here it is, for good or ill: #include #include #include #include #include // for exit statement #define YES 1 #define NO 0 int num1, num2, guess, ans, i, c, proceed=YES; addCalc(); minusCalc(); multCalc(); divCalc(); int menu(); main() { menu(); return 0; } int menu() { c=30; clrscr(); gotoxy(c,10); textcolor(14); cputs("Would you like to practice a little "); c=35; gotoxy(c,11); textcolor(9); cputs("1. Addition?"); gotoxy(c,12); textcolor(10); cputs("2. Subtraction?"); gotoxy(c,13); textcolor(13); cputs("3. Multiplicaton?"); gotoxy(c,14); textcolor(11); cputs("4.Division?"); gotoxy(c,15); textcolor(11); cputs("5. Quit?"); do { gotoxy(c,17); textcolor(15); cputs("Enter your choice: "); scanf("%d", &i); switch(i) { case 1: addCalc(); clrscr(); menu(); break; case 2: minusCalc(); clrscr(); menu(); break; case 3: multCalc(); clrscr(); menu(); break; case 4: divCalc(); clrscr(); menu(); break; case 5: clrscr(); gotoxy(c,12); textcolor(11); cputs("Thanks for playing!"); exit(0); } // end switch statement }while (i < '1' || i > 5); return i; } addCalc() { clrscr(); c=20; gotoxy(c, 10); textcolor(2); cputs("ADDITION PROBLEM:"); gotoxy(c, 12); cputs("Type in the first number (Addend)? "); cin >> num1; gotoxy(c, 13); cputs("Type in the second number (Addend)? "); cin >> num2; ans = num1 + num2; gotoxy(c, 14); cputs("What do you think is the answer (called the SUM)? "); cin >> guess; gotoxy(c, 15); cprintf("The answer is "); textcolor(14); cprintf("%d", ans); textcolor(2); gotoxy(c, 16); cprintf("You guessed %s", (ans == guess) ? "right!" : "wrong."); cout << endl; gotoxy(c, 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(9); gotoxy(c,22); cprintf("Press any key"); getch(); return 0; } minusCalc() { clrscr(); c=20; gotoxy(c, 10); textcolor(2); cputs("SUBTRACTION PROBLEM:"); gotoxy(c, 12); cputs("Type in the Minuend (number to subract FROM: "); cin >> num1; gotoxy(c, 13); cputs("Now, type in the Subtrahend (number to subract: "); cin >> num2; ans = num1 - num2; gotoxy(c, 14); cputs("What do you think is the answer (REMAINDER)? "); cin >> guess; gotoxy(c, 15); cprintf("The answer is "); textcolor(14); cprintf("%d", ans); textcolor(2); gotoxy(c, 16); cprintf("You guessed %s", (ans == guess) ? "right!" : "wrong."); cout << endl; gotoxy(c, 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(9); gotoxy(c,22); cprintf("Press any key"); getch(); return 0; } multCalc() { clrscr(); c=20; gotoxy(c, 10); textcolor(2); cputs("MULTIPLICATION PROBLEM:"); gotoxy(c, 12); cputs("Type in the number to be multiplied (MULTIPLICAND): "); cin >> num1; gotoxy(c, 13); cputs("Type in the number to multiply it by (MULTIPLIER): "); cin >> num2; ans = num1 * num2; gotoxy(c, 14); cputs("What do you think is the answer (PRODUCT)? "); cin >> guess; gotoxy(c, 15); cprintf("The answer is "); textcolor(14); cprintf("%d", ans); textcolor(2); gotoxy(c, 16); cprintf("You guessed %s", (ans == guess) ? "right!" : "wrong."); cout << endl; gotoxy(c, 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(9); gotoxy(c,22); cprintf("Press any key"); getch(); return 0; } divCalc() { clrscr(); c=20; gotoxy(c, 10); textcolor(2); cputs("DIVISION PROBLEM:"); gotoxy(c, 12); cputs("Type in the number to be divided (DIVIDEND): "); cin >> num1; gotoxy(c, 13); cputs("Type in the number to divide it by (DIVISOR): "); cin >> num2; ans = num1 / num2; gotoxy(c, 14); cputs("What do you think is the answer (QUOTIENT): "); cin >> guess; gotoxy(c, 15); cprintf("The answer is "); textcolor(14); cprintf("%d", ans); textcolor(2); gotoxy(c, 16); cprintf("You guessed %s", (ans == guess) ? "right!" : "wrong."); cout << endl; gotoxy(c, 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(9); gotoxy(c,22); cprintf("Press any key"); getch(); return 0; } ------------------------------------END HERE------------------------ Again, thanks, Kurt for your generous help and code examples. 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: ECS00008 Date: 08/22/97 From: MATTHEW DUHART Time: 12:40pm \/To: JAVIER KOHEN (Read 3 times) Subj: A password program I mad -> On 09-Aug-97, MATTHEW DUHART wrote to RAJESH DHAWAN about A password -> program I mad. -> -> MD> Lafore's Object-Oriented Programming in Turbo C++. This program i -> MD> actually useless because you have to enter a number, and no matte -> MD> what, the program exits instead of if you're right then continue, -> -> Actually, you can exit with errorlevels, ie: -> -> int main(void) { -> [..] -> -> if (password.right()) { -> return 0; -> } else { -> return 1; -> } -> } -> -> MD> anything else. But I've made a new line in the program where if -> MD> you enter the wrong password, the computer repeats a line. It run -> MD> this line: aq:goto aq; . So therefore, the computer locks up. -> -> With the modification above you may want to give the user say, 3 -> tries, and if (s)he fails, then lock up the computer. -> -> Javier Kohen [The_Crusher] http://jkohen.base.org -> ... EchoMail (ek-o-mael) n. A tagline distribution system -> -!- CrusherTag 0.3.2. -> --- Terminate 5.00 UnReg -> * Origin: The King of The Ring (4:900/748.3) Okay, thanks, I'll have to try that pretty soon. --- GOMail v2.0 [94-0605] * Origin: The Buzzard's Roost, Pueblo, CO (719) 564-8235 (1:307/8) --------------- FIDO MESSAGE AREA==> TOPIC: 203 C++ Ref: ECS00009 Date: 08/22/97 From: MATTHEW DUHART Time: 12:41pm \/To: JAVIER KOHEN (Read 3 times) Subj: A password program I made -> On 07-Aug-97, MATTHEW DUHART wrote to ALL about A password program I -> made. -> MD> It won't really effect it, though. Write me on this BBS and I'll -> MD> give you the (free) password program. I'll attach it to a messag -> MD> to you. And if you want, I'll give you the source code for C++ fo -> MD> free, also. Bye -> -> Matthew... -> -> You aren't posting to a local BBS message area, you're posting to -> Fidonet C++ programming Int'l echo. If you don't mind, you can share -> your code with us. That will help you in your way through C++ -> learning. -> Javier Kohen [The_Crusher] http://jkohen.base.org -> ... If at first you don't succeed, destroy all evidence that you -> tried -!- CrusherTag 0.3.2. -> --- Terminate 5.00 UnReg -> * Origin: The King of The Ring (4:900/748.3) Whoops, sorry. --- GOMail v2.0 [94-0605] * Origin: The Buzzard's Roost, Pueblo, CO (719) 564-8235 (1:307/8) --------------- FIDO MESSAGE AREA==> TOPIC: 203 C++ Ref: ECS00010 Date: 08/22/97 From: MATTHEW DUHART Time: 12:38pm \/To: JAVIER KOHEN (Read 3 times) Subj: Problem with initgraph -> On 05-Aug-97, MATTHEW DUHART wrote to ALL about Problem with -> initgraph. -> MD> other people check it over, and compiled it. I always get 1 -> MD> warning and 5 errors. The errors always have to do with stuff -> MD> like initgraph, setcolor, lineto, moveto, etc. I also try runnin -> -> Have you included graphics.lib in your project??? -> -> Javier Kohen [The_Crusher] http://jkohen.base.org -> ... Use the fork luke! Ma Skywalker -> -!- CrusherTag 0.3.2. -> --- Terminate 5.00 UnReg -> * Origin: The King of The Ring (4:900/748.3) Yes. And just last night, I had the program working. Except it wan't working correctly. Slow since this is a 386 computer, but other than that, when it showed the buttons, they were off line in 3-D and when you push the button, it was also off line in 3-D. It would only show a few keys. If you want to see the program, I'll show it to you in a message. --- GOMail v2.0 [94-0605] * Origin: The Buzzard's Roost, Pueblo, CO (719) 564-8235 (1:307/8) --------------- FIDO MESSAGE AREA==> TOPIC: 203 C++ Ref: ECS00011 Date: 08/22/97 From: JERRY COFFIN Time: 07:09pm \/To: HERBERT BUSHONG (Read 3 times) Subj: files On (20 Aug 97) Herbert Bushong wrote to Jerry Coffin... HB> but *I've* never been able to make heads or tails of the allowed HB> values for the protmode parameter (I was going to ask that same HB> question, except I was going to ask the values). Okay, lets take a look at the values: filebuf::sh_compat This is the default, left over from before DOS supported networks or sharing. Nothing else can open the file at the same time at all. filebuf::sh_none This is basically the same as sh_compat except that you're being explicit that nobody else can share the file. filebuf::sh_read This means others can read, but not write the file. filebuf::sh_write This means others can write the file. You can use a bitwise or on sh_read and sh_write to allow others to either read or write the file. Actually making file sharing work is something else again: that's enough to fill many large volumes (in fact, quite a few large volumes HAVE been written about it.) At the risk of oversimplifying things too much to be useful, I'll summarize file sharing very succintly: While you're modifying something in a shared file, you generally have to ensure against anybody else seeing some data between starting and finishing the modification. You typically use exclusive access for things like sorting a file, where you're going to rearrange everything. You typically use read sharing for a file that's basically static, and everybody just looks at it, but nobody normally changes it at all. You typically allow others to read and write when you have something like a shared database. When you allow others to read and write a file, you normally have to use record level locking instead of file locking. This allows you to ensure that nobody else is looking at a section of a file while its being modified. That's more or less the nutshell version of file and record locking. It's basically a gross oversimplification of what's really necessary, and ignores LOTS of important points, but at least might be enough to give an idea of where to start looking if you need to work with shared files. (I.e. it's certainly not enough to do the job, but it might be enough to give an idea of the direction to look for the data you will need to do the job...) Later, Jerry. ... The Universe is a figment of its own imagination. --- PPoint 1.90 * Origin: Point Pointedly Pointless (1:128/166.5)