364 Posted Topics
Re: That's a lot of code! What platform are you building on? I'd be happy to help dig through it, if I can match your development environment. Also, any particular reason you've implemented most/all of your methods in models.h instead of a separate models.cpp file? Have you tried running in a … | |
Re: c hickam, Please start new threads for cases like this, rather than tacking onto a thread started over 6 years ago, and untouched for almost 18 months. | |
Re: [QUOTE=Cross213;1636712]Your infile >> name[i] >> midterm[i]...etc won't work because you haven't declared a struct.[/QUOTE] Declaring a struct has nothing to do with the problem. Instead, you've declared arrays that can hold 50 names, but only 5 of everything else. Then your Read_Data() function tries to read 10 entries into those … | |
Re: It sounds like your issues are related more to the Arduino interface than to C++ programming. How is the digitalWrite() function supposed to behave? Is it supposed to maintain the state that you specify (LOW or HIGH)? Or is it supposed to trigger a transient switch to that state and … | |
Re: skiboy209, Try consistently indenting your code. It will help you and others more clearly see what is going on. I think your errors involve where you start the nested loop (the second "do {" line), and where you ask if you want to do it again and end the nested … | |
Re: For what it's worth, the solutions here are implementations of a DepthFirstSearch algorithm, which maps well onto recursion: (approximately valid but untested) [CODE] int KeepMoving (int [][DIM] board, int start_x, int start_y) { if (NoPossibleMoves(board, start_x, start_y)) return 0; int max_moves = 0; for (int k=0; k<=7; k++) { int … | |
Re: And if you want the number of elements in the array to be returned, then [CODE] void InputStudents(studType Students[], int maxStudents, int& NrE) ... [/CODE] Note the addition of the '&' after int, meaning that a reference to NrE is what's passed. Also, I've included the size of the array, … | |
Re: Since you marked this thread solved, I imagine that means you figured out you don't need to prepend member names with the classname at, e.g., line 7 of your .cpp file. :) | |
Re: Well, you need to reset i to 0 before line 12. Your code will be easier to read if you create a few simple (and well-named) functions that do specific things like: [CODE] bool isPrime(int num) { bool is_prime = True // loop to determine if num is a prime … | |
![]() | Re: Since the functions and objects defined in .dlls can be used directly in a C++ program simply by linking against them, e.g. [ICODE]g++ myobj.o -o myprog -lole32[/ICODE] (or just adding the OLE library to your VS project), the notation in C++ should be much simpler. I have no actual experience … |
Re: And once your last node's Next pointer points back to Head, you have to maintain and deal with that. As far as dealing with it, your print_circle() routine will never end as currently written (current will never become NULL). As far as maintaining it, you need to address specific cases: … | |
Re: The regulars here may well correct me (which would be awesome, btw), but first to answer your question: the point of linked lists is to make swapping elements efficient -- in particular, to swap any two nodes, you'd just swap the next and prev pointers of the nodes and their … | |
Re: C++ is an extension to C. In addition to iostreams (and fstreams and stringstreams), it provides per-type operator-overloading and inheritable class objects. C code -is- valid C++, and an example as simple as yours doesn't need to be "converted". However, if you're learning C++, might I suggest that you start … | |
Re: We can probably help again, but it would be useful to know what your new problem is. :) As usual include (1) what you're trying to accomplish, (2) the code (or an appropriate portion of it) that you've written so far, (3) what it's doing wrong, and (4) what you've … | |
Re: std::vectors aren't strictly needed, but they do take care of the dynamic memory allocation for you, and tend to do so in a reasonably efficient manner. I'm curious though about what your application is, that it requires several large 2-dimensional arrays, and whether it would be worthwhile or appropriate to … | |
Re: While it doesn't address your problem, you have a typo at line 15 (fillValue should just be a float, not a float*?), and a potential memory leak at line 48 (check whether buffer is non-NULL and if so free up the previously allocated memory before assigning a new chunk). Personally, … | |
Re: [QUOTE=evilguyme;1632173] but then does that mean for the level 2 clips i would have to declare another SDL_Rect in the class? and for the rest of the levels the same?[/QUOTE] I'm not sure. The code you've posted in your Google Doc appears to declare the SDL_Rects as global variables. Which … | |
Re: I took a quick look, and as far as I can tell, your program can't get past line 33 because the only way out of your while loop is via system("exit") (which I didn't even think about until just now, and appears to kill off the CommandPrompt that your program … | |
Re: You should also consider printing something besides the initial "1" if you want to see a list of numbers. If a number's ONLY prime factors are 2, 3, and/or 5, then you should be able to divide evenly by some quantity of each of those factors, and be left with … | |
Re: Does the following work for you? [CODE] int main() { PlaySound("RFD",NULL,SND_FILENAME|SND_LOOP|SND_ASYNC); Sleep(10000); PlaySound(NULL, NULL, 0); return 0; } [/CODE] In the future, please try to find a minimum failing case, or feel free to trim out code that you're sure doesn't contribute to the problem. But thanks for using CODE … | |
Re: It sounds like you're looking for basic systems engineering understanding. This is a C++ programming forum. Various people here can point you in the right direction for certain kinds of programming questions, but it sounds like you're entirely out of your league as far as the requirements of your project, … | |
Re: I'm sure somebody will have a more definitive answer, but the basic problem with allocating small objects from the heap is the amount of overhead necessary to keep track of that object, and the extent to which the available heap memory is fragmented as small objects are allocated and freed … | |
Re: In fact, if you've gotten as far as inheritance in your class, think about what's shared across all shapes: they take a set of tokens, determine whether the tokens are valid (as Vernon started you out with), and they print out some info. As long as the specific info isn't … | |
Re: Adding a function should be sufficient. Since you already have code that can step through a date-string and divide it into pieces, it should be easy for you to write a function that steps through and verifies that the pieces are the correct length and contain valid characters. Or you … | |
Re: This time, you have defined [CODE] SDL_Rect levelOnePlatform [1]; [/CODE] but you're still calling [CODE] levelOne.set_clips(levelOnePlatform, 50); [/CODE] which is probably overwriting all kinds of other memory! | |
Re: Yuck. Not that it helps, but I've seen plenty of examples where warning 4244 is explicitly silenced in the build, rather than correcting the problem. :) Unrelated, your "load" method should probably be declared "static" as a class-method instead of an instance-method. | |
Re: As far as picking random percentage chances, try: [CODE] #include <stdlib.h> [...] double val = double(rand())/RAND_MAX; // get a random number between 0 and 1 if (val < 0.35) { // there's a 35% chance of this being true upgradesuccess = true; } [/CODE] or if you prefer percentages between … | |
Re: Try: [ICODE]g++ game.cpp -o game -Wl,-static -lpdcurses[/ICODE] or [ICODE]g++ game.cpp -o game -static-libgcc -Wl,-static -lpdcurses[/ICODE] (from [url]http://ubuntuforums.org/showthread.php?t=852552[/url] , your mileage may vary, also this requires a libpdcurses.a file which you may have to create by hand ... by extracting the individual .o files out of a .dll and re-archiving into … | |
Re: Hmmm... the whole premise of public-key encrpytion is that keys need to be shared, to some extent. You can still hard-code the keys you need into the sender application and the receiver application (rather than generate and exchange keys at run-time), but putting one key at each end shouldn't be … | |
Re: If it were only that easy! You need code that can determine which computer to talk to (given a URL), open a socket connection to that computer, make a request for the contents of a specific file, read the contents over the socket connection, and write the contents into a … | |
Re: How is this a C++ question, and what does it have to do with Facial Expression Animation? [url]http://lmgtfy.com/?q=asf+file[/url] | |
Re: Correct enough. SDL maintains the queue of events for you, so all you're doing is checking whether there's an event on the queue and if so, retrieving it so you can decide what to do about it. After line 7, consider adding a 'break;' statement so that you don't have … | |
Re: first google result for "outtextxy" says: [CODE] void outtextxy(int x, int y, char *textstring); [/CODE] Note the "*" character, indicating that it expects a C-style string (or Null-character-terminated array of characters) for the text to display, not a single character. Replace your first line above with: [CODE] const char* strings[] … | |
Re: Ok, so what you'll start with is some value x, and you'll write a function that computes ln(1+x) by using the formula above: [CODE] double ln_one_plus_x(double x) { double val; // insert math here return val; } [/CODE] Now you want to use exponents from 1 to 100 inclusive, so … | |
Re: It is also generally considered "a bad thing" to use global variables, as you have declared in lines 16-19. Instead you should pass the ones you need to each function: by reference for "output" values that the function should alter, and by copy (or const reference) for "input" values. Conversely, … | |
Re: Shaky Rox, you've posted into a three-year-old thread, in general if you have a question about an inactive thread, copy any relevant info into a new thread. Meanwhile, you can insert your own "printf()" statements if you wish to echo back what the user typed. | |
Re: And there's no bigger help than inserting printf/cout statements to show you exactly which blocks of code are executing (and the values of variables too). They're easy to insert and easy to remove. If you want to get fancy you can define your own "logging system" so that you can … | |
Re: Why do you have a Queue_head pointer (initialized to and compared against zero instead of NULL) when the comments in your header say there are just the two pointers frontPtr and backPtr? Just use those. Also, if you're going to track Size separately, then you should initialize it in your … | |
Re: I wrote a fairly substantial two-way socket-based communication program over a year ago. If you have a basic client-server model working (server listens for connections on a particular port, client [or multiple clients] opens socket connections to the server's port, issues a command, reads until a response returns, and then … | |
Re: And '+' is defined as the concatenation-operator for the std::string class, so [CODE] string s = "foo"; char c = 'a'; s = c + s; cout << s << endl; [/CODE] would display "afoo" | |
Re: Try the following: [CODE] // return a non-cost reference std::string & access(int row, int column); // returns a const reference, second const indicates that the method // doesn't alter the grid-instance that you're accessing from const std::string & access(int row, int column) const; ... csv_File & grab(int index); const csv_File … | |
Re: Or, search the forum for "calculator" -- there's a recurring homework assignment on that topic, it will get you most of the way to computing the mean, and from there you can take a stab at the standard deviation. | |
Re: Since you also posted the same question on the tutorial site you referenced above, and the author has responded, there's probably little reason to keep this thread open. Please mark it as "solved" when that's the case, and feel free to let us know what the solution was! | |
Re: There's a very suspicious "endl" being output in your center() function. Instead, I think you want to output a certain number of spaces, then the passed-in string, then another certain number of spaces, so that you've filled the width of the column. | |
Re: Heh, the last function looks great. Consider the possibility that (for some reason) you have only one valid button to draw. (Hint: the problem is actually in your Menu constructor, and has been discussed and re-discussed so many times in this forum that there's a sticky topic for it at … | |
Re: First of all, you search for the father, then the mother, then the father again, then the mother again. It will be more efficient to search for the father first, and grab the auxID and the level at the same time; then repeat for the mother. That said, I don't … | |
Re: [QUOTE=warrior4321;1590811]As well, I am wondering when I type in a letter, (for example, the letter h), it returns the number 51276552. Is there a way that I can restrict the user to only input a number? [/QUOTE] In your code, it doesn't "return" a large number, it actually fails (since … | |
Re: You print out some of the values of the next line of the transaction file only if the current transaction number equals the current customer number. Your loop now reads a line out of the masterfile and a line out of the transactionfile, and prints one of "Transaction#..." (and some … | |
Re: I use a really nice free color-grabber utility on Windows, so haven't bothered coding my own. I'd recommend searching for "keyboard focus" ... since you want your program to keep grabbing keyboard events even while other applications are in the foreground. | |
Re: Back to your question, though, you need to implement the Polynomial constructor taking arbitrary coefficients (inserting code in your "main file" before line 17) ... the code in the following variant of the constructor (lines 20-27) is already close. You also need to implement polynomial addition in method operator+(). Finally, … |
The End.