--------------- FIDO MESSAGE AREA==> TOPIC: 203 C++ Ref: EFE00005 Date: 11/06/97 From: VIRGIL GARNESS Time: 09:13am \/To: ALEX WALKER (Read 2 times) Subj: WTD Coin algorithm ideas Hi Alex, -> I'm a student studying C++ programming. I've got an assignment -> question where I don't even have an idea how to attack the -> problem. The program is to input a value (like $1. $2. $5..) -> and spit out a table showing all the different cominations of coins -> that could be used to make up that value. So for $0.10 the table -> would look like: -> 10 = 10 -> 10 = 5 + 5 -> 10 = 5 + 1 + 1 + 1 + 1 + 1 -> 10 = 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 <-snip-> -> But this just gave me a table of; -> 10 + 10 + 10... -> 5 + 5 + 5.. -> 1 + 1 + 1 + 1... -> I've looked at Permutations and combinations math wise but this -> method just gives me the number of permutations, not what they are. -> I'm not asking for code, just an idea of how to attack the question. -> Thanks for any ideas. Ah! This looks like one of my homework probs that was to teach us about a process called "Recursion". Where a function calls itself until an answer is reached then outputs the information. This is a great type to use with factorials N!=N*(N-1)! You might try this type such as: #include int Power(int, int); int main() { int number; // Number that is being raised to power int exponent; // Power the number is being raised to cin >> number >> exponent; cout << Power(number, exponent);// <- Here is your recursive call } //****** void Power(/* in */ int x, // Number that is being raised to power /* in */ int n) // Power the number is being raised to // Computes x to the n power by multiplying th x times the result // of computing x to the n-1 power { if(n==0) return 1; else return n* Power(x,n-1); } Personally I hated these problems but I did still manage to muddle through them. Hope it helps. Later..... --- Platinum Xpress/Win/Wildcat5! v2.0 * Origin: Al's Force BBS (2:2501/206) --------------- FIDO MESSAGE AREA==> TOPIC: 203 C++ Ref: EFE00006 Date: 11/06/97 From: RORY STREET Time: 09:37am \/To: CAMERON CLARK (Read 2 times) Subj: Re: Java++ In a message of <29.10.97>, Cameron Clark (1:3811/350) writes: RS>> :) Okay and with Java can this only be run under Unix as done with RS>> GNU CC> C or RS>> can you run it under any OS that takes it? CC> Any machine that has 'java interpreter' software. Unlike C++ CC> (another poor attempt to stay on topic), Java compiles to a CC> standardize 'byte code' [not to proprietary object code like C++ CC> uses]. This byte code can be run on any machine using the CC> interpreter. I've seen unix/solaris, win95/nt interpreters so far. So this interpreter has to be built into the OS? CC> Unlike C++ object files, the .class files (the compiled byte code) CC> is meant to be ran anywhere. I'm not to sure on how portable the CC> actual source code itself is (since MS and Sun compilers have some CC> inconsistancies). But the compiled code works on all interpresters? So no linking is used as in C? Cya! Rory Street --- IOS-Mail 0.91pl9 eta * Origin: >>>> Athena BBS +44-(0)-1959-563-968 (2:440/226@fidonet.org) --------------- FIDO MESSAGE AREA==> TOPIC: 203 C++ Ref: EFE00007 Date: 11/08/97 From: CAMERON CLARK Time: 02:38pm \/To: FERNANDO ARIEL GONT (Read 2 times) Subj: Re: Portability FA> I mean, it's great to have a code that can be executed on several Operative FA> Systems, but I haven't found a program that is portable (or else I aven't FA> realised), so that I don't understand why is it so important for a code o FA> be portable...... To make a c++ program portable, don't use non-portable libraries or assumptions about a specific architecture. There are libraries that are native to DOS only others native to UNIX only - don't use them. Don't use assembly language, direct memory access, or unfortunately assumptions about the size of primitive data types. Even thought a char is a byte on every system I've used, and int may be 2 or 4 bytes, and a long int may be 4 or 8 bytes. --- GEcho 1.00 * Origin: Digital OnLine Magazine! - (409)838-8237 (1:3811/350) --------------- FIDO MESSAGE AREA==> TOPIC: 203 C++ Ref: EFE00008 Date: 11/08/97 From: CAMERON CLARK Time: 02:44pm \/To: FERNANDO ARIEL GONT (Read 2 times) Subj: Re: C/C++ discompiler (or disassembler) FA> Well, a profesor of mine (one I call Guru), asked me if I could get a C (or FA> C++) discompiler (or disassembler)..... If you mean disassembler, there's plenty of them around. Try looking for the NASM program - it's got a disassembler. If you mean discompiler - then your professor is no Guru. The only thing you have to understand about compilers to know that you can't translate machine code to its original code is the following: code -> intermediate code -> optimization -> machine code Most compilers translate highlevel code into tripplets/quadruplets (intermediate code that is machine independant) optimize is and the translates that into machine code. What this means is that the same highlevel statement does not produce the same machine code every time (do to optimization and the programmers choice of intermediate code). --- GEcho 1.00 * Origin: Digital OnLine Magazine! - (409)838-8237 (1:3811/350) --------------- FIDO MESSAGE AREA==> TOPIC: 203 C++ Ref: EFF00000 Date: 11/08/97 From: DOUGLAS FORD Time: 11:57pm \/To: ANYONE; (Read 2 times) Subj: String Hi all! Recently purchased a copy of Visual C+ Ver5.0 In other version I could use the string class eg. --#include --, however this version returns an undeclared identifier error. I can get round the error using char*, but why can't I use string? Both the string and string.h headers are in the include directory (the same directory as other classes that -do- work) and both files look ok (ie I've opened them up and they aren't corrupt of bad) Suggestions anyone?? CU L8r Doug ... A big enough hammer can usually fix anything. --- Via Silver Xpress V4.3P CA-12862 * Origin: Corpus Callosum, Penticton BC (604) 493-9281 (1:354/250) --------------- FIDO MESSAGE AREA==> TOPIC: 203 C++ Ref: EFF00001 Date: 11/03/97 From: DANIEL BORG Time: 12:27am \/To: ALL (Read 2 times) Subj: Is anybody out there? This area is a bit empty don't you think? Any novice or experienced programmers out there who want to talk programming drop us a line. --- FD2.12/RA2.50/FE1.46+/WFWG3.11! * Origin: ONE_TWO_DELTA - MARYBOROUGH, QLD, OZ (2200-0600 DAILY) (3:640/384) --------------- FIDO MESSAGE AREA==> TOPIC: 203 C++ Ref: EFF00002 Date: 11/08/97 From: RICHARD HIRNER Time: 09:57pm \/To: CHRISTOPHER BUTLER (Read 2 times) Subj: address of member func. Hello Christopher! CB>How do I get the address of a member function? CB>For example: CB>class foo CB>{ CB> public: CB> foo(); CB> void interrupt myInt(...) CB>} CB>foo::foo() CB>{ CB> _dos_setvect(0x1C, &myInt); // Here is where I want to get the address o CB> // the member function myInt... CB> // What I've put is obviously incorrect, s CB> // TC says its wrong.. so how /do/ I do t? CB>} for DOS-Borland C++ 3.1 class foo { public: foo(); static void interrupt myInt(...); }; foo::foo() { setvect(0x1C, &myInt); } bye Richard ___ X SLMR 2.1a X BIOS error - press F13 to continue ... --- Maximus/2 3.01 * Origin: Constants aren't (2:310/3) --------------- FIDO MESSAGE AREA==> TOPIC: 203 C++ Ref: EFF00003 Date: 11/09/97 From: JARI LAAKSONEN Time: 08:59pm \/To: ROSE (Read 2 times) Subj: Java >>> Ok, in J++, how exactly do I get a simple program to >>> determine which key has been pressed WITHOUT having to press the >>> enter key each time? >> java.awt.Component.keyDown() (JDK 1.0.2) or >> java.awt.Component.processKeyEvent() (JDK 1.1) > thanks, but can you show me how to use it in source... I'm not that > good at it yet., Those events are of course sent to a component (Window, Frame etc.). If you are looking for getch() equivalent for Java to be used in text mode programs, then I'm sorry, I cannot help. I'm new at this, too :-) However, here's a sample applet: import java.applet.*; import java.awt.*; public class SimpleCard extends Applet { Panel card_stack; CardLayout cl; public void init() { setLayout (new BorderLayout()); card_stack = new Panel(); cl = new CardLayout(); card_stack.setLayout (cl); add ("Center", card_stack); Panel card1 = new Panel(); card1.setLayout (new FlowLayout()); card1.add (new Label ("Card 1")); card1.add (new Button ("One")); card_stack.add ("One", card1); Panel card2 = new Panel(); card2.setLayout (new FlowLayout()); card2.add (new Label ("Card 2")); card2.add (new TextField ("Two", 30)); card_stack.add ("Two", card2); Panel card3 = new Panel(); card3.setLayout (new FlowLayout()); card3.add (new Label ("Card 3")); card3.add (new Checkbox ("Three")); card_stack.add ("Three", card3); Panel button_bar = new Panel(); button_bar.setLayout (new FlowLayout()); button_bar.add (new Button ("First")); button_bar.add (new Button ("Previous")); button_bar.add (new Button ("Next")); button_bar.add (new Button ("Last")); add ("South", button_bar); } public boolean action (Event evt, Object arg) { if ("First".equals (arg)) { cl.first (card_stack); } else if ("Previous".equals (arg)) { cl.previous (card_stack); } else if ("Next".equals (arg)) { cl.next (card_stack); } else if ("Last".equals (arg)) { cl.last (card_stack); } return true; } public boolean keyDown (Event evt, int key) { if (key == 'f') { cl.first (card_stack); } else if (key == Event.LEFT) { cl.previous (card_stack); } else if (key == Event.RIGHT) { cl.next (card_stack); } else if (key == 'l') { cl.last (card_stack); } return true; } } // Albert email: jla@to.icl.fi --- GoldED/2 2.50+ * Origin: Albert's Point/2 in Finland, Europe (2:221/360.20) --------------- FIDO MESSAGE AREA==> TOPIC: 203 C++ Ref: EFF00004 Date: 11/11/97 From: KURT KUZBA Time: 01:31am \/To: BENJAMIN L MCGEE (Read 2 times) Subj: Windows 3.1 Programming BL> Where can I get a good Windows 3.1 Programming text? BL> ?? Teach Yourself Windows 3.1 Programming in 3.1 Seconds ?? BL> Where can I call get a good MFC 2.0 text? BL> ?? Teach Yourself MFC 2.0 in 2.0 Seconds ?? Microsoft Press. Current releases are: Programming Windows 95 by Charles Petzold Programming Windows 95 MFC by Jeff Prosise Older titles covering Win3.1 should also be available. Otherwise, The MFC's are detailed in the Help, and you may be able to puzzle out the hows and whys of it there. > ] Let he among you without sin cast the first... OW! HEY!!.... --- * Origin: *YOPS ]I[* 3.1 GIG * RA/FD/FE RADist * Milwaukee, WI (1:154/750) --------------- FIDO MESSAGE AREA==> TOPIC: 203 C++ Ref: EFF00005 Date: 11/11/97 From: KURT KUZBA Time: 01:31am \/To: DARRELL HNIZDOR (Read 2 times) Subj: thanks DH> Can you tell me if there is a simple way to put DH> a string into a variable other than strcpy? DH> I know this doesn't work: DH> char a[]= "this string"; DH> char b[20]; DH> b=a; Neither b nor a is an Lvalue after initialization, so that won't work. If you want to use fixed length strings, you may use structs, with which simple assignment will work. Since this is C++, however, and not C, you may also create a string class which will allow overloading of the assignment operator. You would still be using the strcpy() or sprintf() to perform the actual transfer of data from one array to the other, but it would be hidden from you at the coding level, only being a concern at the class level. To use structs: #include typedef struct { char S[128]; } MyString; int main(void) { MyString szA = { "A test string" }; MyString szB = { "B test string" }; MyString szTemp; cout << "szA = " << szA.S << '\n' << "szB = " << szB.S << endl; szTemp = szA; szA = szB; szB = szTemp; cout << "szA = " << szA.S << '\n' << "szB = " << szB.S << endl; return 0; } > ] I am Elvis of Borg. Thank you... Thank you very much........ --- * Origin: *YOPS ]I[* 3.1 GIG * RA/FD/FE RADist * Milwaukee, WI (1:154/750)