- Strength to Increase Rep
- +10
- Strength to Decrease Rep
- -2
- Upvotes Received
- 211
- Posts with Upvotes
- 151
- Upvoting Members
- 73
- Downvotes Received
- 10
- Posts with Downvotes
- 9
- Downvoting Members
- 9
Mostly retired computer scientist after 26 years at Bell Labs and its offshoots. Founding member of C++ standards committee. Project editor for the 1998 and 2003 versions of the C++ standard. Author of "C Traps and Pitfalls" and coauthor of…
- Interests
- Most of my energy these days goes into music and photography.
- PC Specs
- Core 2 Extreme Q6850 (quad core), 3 GHz/3.25 GB RAM; Windows XP SP3.
388 Posted Topics
Re: [QUOTE=JoBe;188512]Ok, thanks for the additional info :!: I think I could do this by putting an if statement in it, for example when the while loop is at N°3 it should enter 0 into the vector, this way the amount of vectors is correct, but the total amount isn't.[/QUOTE] The … | |
Re: How about explaining what you expect the statement to do? It looks like nonsense to me. | |
Re: [QUOTE=Ancient Dragon;1501019]Nice info, but 4 years too late.[/QUOTE] And wrong, too, for at least two reasons that come to mind immediately. | |
Re: Thank-you Andrew Koenig and Barbara Moo..I appreciated yours words of wisdom. You're welcome. | |
Re: If there's no upper bound on n, then you need a data structure that can grow without bound. If you can't use arrays or pointers, then you must find some other data structure that grows without bound. If you're not allowed to use any such data structure, then the only … | |
Re: And now that it's in the C++ forum, I can point out that the title of this thread talks about printing the reverse of a number, but the program computes the sum of its (decimal) digits. Which is right? | |
Re: Is there a reason that you are insisting on an AVL tree rather than just a data structure that will use an order relation to store values in a way that will keep equals together? Because if you just need the latter, you should be able to get std::set (or … | |
Re: [code]ofstream f(filename, ios_base::out | ios_base::app);[/code] iosbase::app means that you want to append to the file. | |
Re: Not every C++ implementation is capable of supporting an integer as large as 600851475143. So if you want to use a C++ implementation that doesn't support integers that large, you have a few choices: 1) Figure out how to represent such large integers for yourself. 2) Find an extended-precision integer … | |
Re: What do lines 20-22 do? They don't seem to correspond to any part of the problem specification. In particular, they seem to say that A(0,1) is equal to A(1,1). I see no justification for that claim. | |
Re: [QUOTE=Ancient Dragon;1572886]The republicans had no say in passage of Obamacare. The Democrats controlled both houses of congress at that time. So I don't know how you can possibly blaim the republicans for anything.[/QUOTE] That's easy: the same way that the original poster can talk (apparently with a straight face) about … | |
Re: Also: Why are you writing `DataType *Ptr = new DataType();` instead of simply writing `DataType Obj;` ? | |
Re: To Silvercats: Everything in Accelerated C++ is as valid now as it was in 2000. It is true that it doesn't cover the C++11 stuff, but it is possible to learn that stuff later. | |
Re: I think that you probably have something like this in mind: def print_reverse(s): for i in range(len(s)-1, -1, -1): print(s[i]) | |
Re: I doubt you're going to find anyone to help you with this code because your description of what it's supposed to do is so unclear. To begin, (x^2+x)/(x^2+x^3) isn't a polynomial; so your claim that your program finds the integral of a polynomial is not correct. Therefore, we don't actually … | |
Re: The paragraph you cite is an example of explaining how to avoid a bad programming technique by using a second bad programming technique. Here's why I say that. A reference is an alternative name for an object. For example, if I write [code]int i; int& j = i;[/code] then I … | |
Re: I would think that if you replace the type std::pair<std::string, unsigned long> in lines 7 and 23 by std::pair<const std::string, unsigned long>, it ought to work. At least I can't think immediately of any reason it shouldn't. | |
Re: This code doesn't work: [code] std::list<bullet> bullet_list; std::list<bullet>::iterator iter; bool alive = false; for (iter = bullet_list.begin(); iter != bullet_list.end(); ++iter) { bool isalive = iter->alive; if (isalive == true) { alive = iter->move(); // move is a function inside the struct "bullet" } if (alive == false) { int … | |
Re: There are four conditions that must be met for checkmate to occur: 1) The king is in check. 2) There is no move that the king can make that takes it out of check. 3) It is not possible to capture the attacking piece. 4) It is not possible to … | |
Re: I don't even need to ask how your program is supposed to work because it can't -- there is no way for recursivecandy to return that does not involve a recursive call, so there is no way for it ever to return a meaningful value. | |
Re: [QUOTE=mzimmers;1691543]Everything you say makes sense. I just found it odd that an algorithm that needs to be told the start and the end of the data (like sort) would expect the end to be beyond the final valid element. But, your position is supported by the results of the program, … | |
Re: I don't understand the assignment. Deleting an element from a doubly linked list is not inherently an iterative operation, which means that there is no obvious way to transform it into a recursive operation. | |
Re: What would you do with variable-length arrays that you can't do better with C++ vectors? | |
Re: I think this question would be better asked in the C forum, as the program you posted has no significant C++ content. | |
Re: Remove the call to srand from the choose_number function. As a general rule, you should call srand only once in your entire program. | |
Re: Xoring the bits of an integer is equivalent to computing its parity. There are ways of doing so that might be faster than your original example, but you'd have to measure to see whether it's really faster in practice. The way that comes to mind is this: Divide the integer … | |
Re: Isn't that the subject matter of your course? | |
Re: Here are some questions for you to answer? 1) Do you know how to print the first line of the required output? 2) Do you know how to print the second line? 3) If I give you a number n, do you know how to print the nth line? | |
Re: [QUOTE]Throughout history, poverty is the normal condition of man. Advances which permit this norm to be exceeded — here and there, now and then — are the work of an extremely small minority, frequently despised, often condemned, and almost always opposed by all right-thinking people. Whenever this tiny minority is … | |
Re: The problem is that the OP doesn't know how to solve this particular problem, and wants someone else to do it instead. | |
Re: Depending on the input of the user in what way? | |
Re: I hate to sound smug, but this is not a difficult problem. In effect, you have a string of 0's and 1's that you want to treat as a binary number, and you want to add 1 to it repeatedly. Adding 1 to a binary number is easy: Take all … | |
Re: What happens if you include <string> before you include Profiles.h? If that doesn't solve the problem, can you tell us which line(s) the compiler reports as erroneous? | |
Re: Use the [I]next_permutation[/I] algorithm that's part of the C++ standard library. | |
Re: The results are undefined, which means that a program that does so is permitted to do anything at all. | |
Re: If you can figure out what the code means, then I suggest you take an example that someone else has written that uses inheritance and try to rewrite it into a program that behaves the same way but does not use inheritance. | |
Re: Please post your entire program, using code tags, and tell us what is happening that you don't expect. | |
Re: Both of your examples are wrong: A function must never return a reference to a local variable. Whatever output such a program produces is the result of coincidence and cannot be trusted. | |
Re: The reason is that DictionaryList (defined on line 7) and dictionaryList (used on line 11) are different types. | |
Re: What happens if you change ... << setprecision(2) << ... to ... << fixed << setprecision(2) << ... ? | |
Re: You say: "The problem asks to create a program with the complexity O(n) and i wonder if the program i made is a O(n) complexity." A program with complexity O(n) that does what? | |
Re: [QUOTE=Vinod Supnekar;1580467]Now if i use [CODE] #include <stdio.h> main() { int c; while ((c=getchar()!=EOF)//get the sinle char putchar(c);//prnt it on cmd } [/CODE] [/QUOTE] then your program will not compile because of the unbalanced parentheses in line 5. | |
Re: IIRC, if a function that is declared to return a value falls off the end without doing so, the C89 standard permits this state of affairs so long as the caller does not try to use the value that the function failed to return. In other words: [CODE] int foo() … | |
| |
Re: If allocating and initializing dynamic memory is a significant part of your program's overall execution time, you may want to reconsider your design. My reason for saying this is that if initialization is significant, it suggests that you're not doing much else with the memory aside from initializing it. In … | |
Re: You say "2 different objects share the same memory location if their content are identical." The thing is: If they share the same memory location, they are not different objects. | |
Re: What is VARIANT? | |
Re: It is hard to know whether a change to your program will make it faster until you understand where it is spending its time now. For example, if the program is slow because the operating system's file system is taking too long to open and close all those files, adding … | |
Re: What you've written is really a C program. I suggest that you either rewrite it in C++ or ask your question in the C forum. Also, please use code tags. |
The End.