364 Posted Topics
Re: Well, since this is a C++ forum, let's start with some basic OO analysis. What are the objects that your program will be handling? What are their members? What methods should they have? How should they be logically organized into classes? In more detail: Whose responsibility is it to manage … | |
Re: You've got the basic idea of binary search: it's the optimal strategy for the "I'm thinking of a number between 1 and 100, try to figure it out" game. You start with 50, and the other person tells you higher or lower. If he says lower, you guess 25 next, … | |
Re: There's still the possibility of needing a fuzzy-match. There is no guarantee that your browser's renderer displays the source image pixel-by-pixel perfectly each time. If it did, it would be sufficient to do something like: [CODE] int checkImgI = -1, checkImgJ = -1; for (int i = 0; i < … | |
Re: How have you drawn your basic face? With code, on the computer? With charcoal on paper? What does it mean to "merge the template with a real human face"? Once you can more clearly state what your program needs to do, it will be more clear how to start writing … | |
Re: Welcome dkXIII, First of all, when posting code, please put [ CODE ] tags around it. Simply select the code you've pasted into your message, and click the [ CODE ] icon/button at the top of the editor. And read the [URL="http://www.daniweb.com/software-development/cpp/threads/78223"]"Read Me: Read This Before Posting A Question"[/URL] sticky-thread … | |
Re: Following up to mzimmers, ... or your WrongSize() function is mis-named. While it might function completely correctly, it isn't very readable to have WrongSize() return true when the data is the RightSize and false when it's not. In addition, your logic at lines 33-34 is incorrect. You need a different … | |
Re: Please use the [ CODE ] icon-button at the top of the editor to format both your code and your triangles, so we can better see what it is you're doing so far, and what you're trying to accomplish. As far as making 2 triangles at once, think about what … | |
Re: Here's something to start: [CODE] class Object { public: // "normally" these would be private or protected, and accessed or modified through methods, but it's fine for now int int_val; std::string str_val; Object2 some_other_kind_of_obj; public: void print(void); } void Object::print(void) { cout << "int_val = " << int_val << endl; … | |
Re: If you haven't already figured it out, [ICODE]®Item[/ICODE] produces the same pointer (address of the regItem object in [virtual] memory) each time you use it, so you may be filling your list with identical pointers, whose values then will be whatever you most recently assigned into regItem. Instead you should … | |
Re: Why are you looping over the number-of-trains, inside your loop to input Trains structs, at line 65? And without an opening "{" (and closing "}" some time later), the only line that will be looped-over is the prompt for the first intermediate station name. I suspect that in adding the … | |
Re: Hi Stevo, I haven't read the accompanying .doc, but I assume since your create() method initializes all values to zero, then the add_*() methods are intended to add to your stores of raw materials, while your make_pizza() method should take the type of pizza to be made and the number … | |
Re: The definition of the IEEE double-precision format is eight bytes (MSB to LSB): [CODE] seee eeee eeee emmm mmmm mmmm ... mmmm mmmm [/CODE] where s is a sign bit (1 is negative, 0 is positive), e is a 12-bit signed integer exponent (ranging from -2048 to 2047), and m … | |
Re: The best way to really -learn- a programming language is (as thines01 said) to think of something you want to program, and then program it. The exercises at the end of each chapter of a book may seem lame, but they're designed to reinforce the concepts introduced in that chapter. … | |
![]() | Re: Hi TheFearful, Nothing to be afraid of here, except maybe frogboy's sarcasm. :) In the first problem, since you don't actually need to perform any math on the input numbers, they don't need to be integers. You could play the same game, called "happy words" on 4-letter words: "HEAD" is … |
Re: Hi Nimerion, Your original problem was: [QUOTE]The problem is that I don't know how to take the elements and convert them into an integer.[/QUOTE] I assume you have a text-file with a bunch of integers in it. Is the problem that you don't know how to read the strings out … ![]() | |
![]() | Re: First of all, don't do this: [CODE] for (int i = 0; i < num; i++) degreeTable[i]=NULL; [/CODE] You've already allocated degreeTable to be an array of F_HeapNode instances, meaning that degreeTable[i] is a F_HeapNode instance rather than a pointer to something. If you want an array of pointers, then … ![]() |
Re: And in getRecords(), you're passing a [b]pointer[/b] to a struct, so you need to use the -> operator to access its methods, e.g: [CODE] acc->balance = 1000; [/CODE] Or you can pass the struct "by reference", in which case you need to change your parameter declaration (in the prototype and … | |
![]() | Re: At line 11, you assign q->next equal to p->next, but p isn't defined. I suspect that what this function is -supposed- to do is append the len new nodes to the end of the list, so you need to initialize p by stepping through the list, starting at ptr, until … |
Re: Welcome mikkey91! Strings and arrays will both work. Learning how to decide up-front which way to go is something you learn only with plenty of experience. For now, pick whatever you're comfortable with, and figure out how to implement what you need. If you have time, go back and implement … | |
Re: Lol, if it works for ~340,000 values, then it's probably not the algorithm! Likely the problem is that the allocation is failing because you're somehow out of system resources, or (since the algorithm is recursive) your program stack and allocation heap are meeting in the middle. Things to check: + … | |
Re: Without code blocks that start from line 1, it's hard to tell which line of your code has generated the error. That said, I'll take a stab at it. Error #1. I'm not at all sure what it's complaining about. Error #2. If you're specifying: [CODE] #include <someSTLheader> using namespace … | |
Re: Third hit on a google search for your undeclared identifier provides a substantial [URL="http://www.cpp-home.com/tutorials/166_1.htm"]sample code[/URL]. Right at the top of it: [CODE] #define INITGUID //#define D3D_OVERLOADS //might need to "unremark" this line, depending on if you use the overloads #include <windows.h> #include <stdio.h> #include <ddraw.h> #include <d3d.h> [/CODE] The differences … | |
Re: You have to read the desired line out of the file between the time you open the file and the time you start reading student information out of it, maybe around line 57: [CODE] string schoolInfo = inFile.getline(); cout << "Test results from: " << schoolInfo << endl; [/CODE] | |
Re: I LOL'd, frogboy. :) New4lyfe, welcome to DaniWeb, and don't mind the sarcasm. Instead of telling us how lost you are, tell us what you -do- understand. Can you answer the first numbered question? The second? Instead of being overwhelmed (and panicking), try bite-sized pieces. Then when you actually get … | |
Re: Your HEAVYSTORM and POTOFGREED function implementations (at lines 50 and 63, respectively) need to provide argument names for each argument, whether or not you use the args in the function. As far as I can tell at a quick glance, your use of function-pointers is ok as-is. What compile-time or … | |
Re: Probably the line in your code: [CODE] for(int i = 0; i < S[i].ImtiKieki() ; i++) [/CODE] I think you meant for this line to specify "i < n". Happy coding! | |
Re: There's quite a bit of useful sample code at xmlsoft.org, and for your specific needs, the [URL="http://xmlsoft.org/html/libxml-tree.html#xmlNode"]xmlNode struct[/URL] contains field: [CODE] struct _xmlAttr * properties; // properties list [/CODE] which I believe will prove useful to you in extracting the attributes. As far as saving it into a map, that … | |
Re: That's a lot of code to ask us to pore over by hand, rather than doing what was already asked. If you don't know how to use the debugger for your development environment, then start by inserting lines like [ICODE]cout << "Here #1" << endl;[/ICODE] into your main(), and see … | |
Re: I'd suggest replacing your drawBezier() function at line 61 (which should really be called something like computeBezierPoint(), since that's what it does), with a new computeDeCasteljauPoint() function. Note that the de casteljau definition lends itself well to recursion -- given an initial set of N points, and a value t, … | |
Re: To be clear, you have your notations reversed in lines 52 and 75. The variable you're passing at line 52 is [ICODE]InitWord[/ICODE] (an array of 50 characters). The argument you're expecting at line 75 is [ICODE]char InitWord[50][/ICODE]. | |
Re: [QUOTE=ayeshashahid;1675710]can i see the overall code[/QUOTE] If they had posted the overall code, then you'd be able to see it. Since the thread is over 2 years old at this point, I suspect the original poster has moved on. Please do not post into ancient threads. Instead, create a new … | |
Re: As others have already pointed out (and even solved for you): I suspect you need to write your own factorial function. The likelihood is small that [ICODE]x![/ICODE] is implemented as written. And sure enough I don't see a factorial function already implemented in [URL="http://www.cplusplus.com/reference/clibrary/cmath/"]cmath[/URL]. So you'll need to write your … | |
Re: Thanks for posting your homework question. Now what is -your- question? And sorry, I have no working knowledge of your DarkGDK, but there is a set of related threads pointed out on the right-hand-side of the screen here, they may be helpful to you as well. | |
Re: [QUOTE=ret801;1676209]you need to import the correct library /packages is DWORD In the standard library? are you using.....[using namespace std]...... at the top of your code?[/QUOTE] DWORD is a type defined by Windows (so is TCHAR, so is most of the rest of the mess. Joke about Microsoft and lightbulbs omitted.) … | |
Re: [QUOTE=ret801;1676208]I would think you shouldn't declare your variables like you did[ float zero(float);].And why are you declaring them like variables when they are methods? Ima newb programming only a year of experience but I've never seen it done like that.[/QUOTE] Technically, they are functions. "Methods" are functions specifically bound to … | |
Re: At some point in your code, you need to assign a value to TotalCS. [CODE] TotalCS = <something>; [/CODE] So far, all you're doing is inputting values into variables and printing out expressions. Either you've been asleep in your course, or you're just in a panic now. Take a deep … | |
Re: I may be mistaken at any point here, so try one thing at a time and see what (if anything helps). First, at lines 9-12, you can declare your global function-pointers here, but I don't think you can call wglGetProcAddress() (or any other function) in the global scope. I think … | |
Re: Your code in check_num() is fine (other than not maintaining leading zeroes, as Ketsuekiame pointed out). Instead you have a subtle error on line 71. Can you spot it yourself? While it doesn't matter, since you're not changing a, b or c within check_num(), you don't need to recover the … | |
Re: You don't generally "change" the command-line arguments. You either specify them or not, as needed and as dictated by the program. If you're running your program by double-clicking on a desktop icon, you don't have a command-line, so you don't get to specify any arguments. But more modern user-interactions methods, … | |
Re: For starters, for the first value of j, you go all the way through the file, replacing occurrences, but then don't save the file or re-initialize pch. Instead, it may be more efficient (depending on the number of values of j) to read each line from the file, then loop … | |
Re: robdb, First, am I correct in assuming that your program is reading in the whitespace-separated words from one file, and writing out encoded versions of the words one-per-line? If that's the case, first, you're sizing index_t array incorrectly. You don't want an index-entry per word in your file, you want … | |
Re: and for your system()-call example, try something like this: [CODE] string cmd; cout << "What command would you like to run?" << endl; cin >> cmd; cout << "Trying to run: system(\"" << cmd << "\")" << endl; system(cmd.c_str()); [/CODE] | |
Re: In case your compiler is fussy, try changing line 3 to: [CODE] extern "C" { int sum(int, int);//to avoid name mangling } [/CODE] Are your .cpp and .s files both included as dependencies of your executable? | |
Re: Meli123, It sounds like you're panicking! So first of all, don't worry about what seems advanced and what you do and don't understand. Try things that people here have suggested, and see what works and what doesn't. Try to change things, understanding that your program might no longer work, or … | |
Re: stringstream is also useful for handling a line at a time out of a file (or other stream): Untested, so I apologize in advance if it doesn't compile: [CODE] ifstream inf ("someFile.txt"); string line; while (getline(inf, line)) { stringstream ins(line); string word; while (line >> word) { // handle each … | |
Re: You're close with [QUOTE]I know a float variable can only hold 7 digits, ...[/QUOTE]. It can only represent about 7 [b]significant[/b] decimal digits. Meaning that once you exceed 16,777,216 (just tested it here on my own machine), [ICODE]f++[/ICODE] doesn't do what you expect. A simple alternative (iterating over integers as … | |
Re: In your first block of code (reading the logfile), since the date should always be the first thing in a line, you may want to consider looping over [ICODE]getline(logfile, line)[/ICODE] instead of over [ICODE]logfile >> next[/ICODE]. Within the loop, you can create a stringstream for line, and grab the date … | |
Re: The original problem is that with the constructor and destructor source missing from the class prototype, and commented out in the implementation, there was no way for your line 10 to work: [ICODE]Item test;[/ICODE]. In order for the compiler to create a default instance of your class, there must be … | |
Re: Maybe you should consider naming your variables "initial_balance" (if you need to keep track of that for any reason) and "current_balance". Your current_balance is the value that will keep changing every time you do a deposit or withdrawal. You don't need a "static number" to keep track of the number … | |
Re: Welcome Sappy T, I don't mean to sound brutal when you're new here, but: 1) The theme of the forums here on DaniWeb is "you do the work, we help you understand the concepts and spot errors in your code." We don't do your work for you. 2) Please don't … |
The End.