388 Posted Topics
Re: Every random-access iterator is a bidirectional iterator. | |
![]() | Re: Before you learn about functions, I suggest you learn about how to write a loop and how to change the value of a variable. |
Re: You haven't posted all of your code, so it's hard to know what all your problems are. However, the code that you posted for charStack::push ahd charStack::pop is broken. To see this, try creating a charStack object, pushing a few characters onto it, and then popping them one at a … | |
Re: I see nothing obviously wrong with the code you've shown. However: 1) You should be aware that writing a parameter of the form[icode]string foo[][/icode]means exactly the same as if you had written it as[icode]string *foo[/icode]-- that is, the parameter is just a pointer. 2) If you don't have a declaration … | |
Re: On line 10 you say that you have a function named askGuess that takes no arguments and returns a char. On line 55 you define a function named askGuess that takes a string argument and returns a char. Because these functions have different argument types, the compiler assumes that they … | |
Re: The problem is that there's a template in the standard library named plus, so your program is conflicting with that definition. Change the name to something else. | |
Re: [QUOTE=invisal;1485461]There is no any square root algorithm that guarantee a 100% accurate result. For example: Let's say what is 100% accurate result of square root of 2? [/QUOTE] The IEEE floating-point specification requires the square root operation to return the representable number that is the correctly rounded value of the … | |
Re: Why aren't you using a vector? | |
Re: I'm sorry to say that both answers are wrong. Example (a) uses the overloaded constructor that matches the argument, which in this case has type const char*. The string type is actually an instantiation of the basic_string template, so that string is equivalent to basic_string<char>; but putting that detail aside, … | |
Re: [URL="http://www.daniweb.com/forums/thread573.html"]Yes[/URL]. | |
Re: It's hard to answer your question without knowing what GetHeight does. | |
Re: There isn't a set of published answers for [I]Accelerated C++[/I] because Barbara's and my teaching experience is that if students have the answers already available, they don't try to solve the problems for themselves. Typically, if you don't know for sure whether your answer is right, it probably means you … | |
Re: @narue: In line 11 of your example, shouldn't value%2 be value%indices? | |
Re: if (sex=='m' || sex == 'M') { /* ... */ } Note the use of == rather than = and the use of ||. | |
Re: You haven't actually said what you want it to do, so it's hard to say whether it's ok. Copying a vector copies its elements. However, if those elements are pointers, copying a pointer doesn't copy the object that the pointer points to. This is true whether or not the pointer … | |
Re: Don't use a for statement. The trouble with for statements is that they push you in the direction of iterating over a single range of values, and the problem you're trying to solve involves iterating over two ranges of values at once. What you want to do is have two … | |
Re: It's easy to arrange for numbers not to repeat in any row. It's also easy to arrange for numbers not to repeat in any column. However, at least at first thought, it is quite difficult to arrange for both conditions to hold at the same time, with the numbers still … | |
Re: When you say "Both lines work on their own if the other is removed from the code, and both functions used are not making any of the problems themselves," I am skeptical. Usually, if a program crashes when doing A and B, and it seems to work when doing A … | |
Re: Memory-mapped IO is not part of standard C++, which means that your instructor must be expecting you to use some locally defined facilities for the purpose. Your first job is to find out what those facilities are. While you're doing that, I have three other suggestions: 1) Most of your … | |
Re: [URL="http://www.daniweb.com/forums/thread78223.html"]This[/URL] will tell you what to do. | |
Re: Read a file that contains text, in the form of words separated by whitespace (spaces, tabs, or newlines). 1) Print the longest and shortest words. 2) Print each word, together with how many times it occurs. 3) Print every word that occurs only once. | |
Re: [CODE]for (int i = 0; i < 1; ++i) { for (int j = 0; j < 1; ++j) { cout<<"_ _ _ 1" << endl; cout<<"_ _ 2 2" << endl; cout<<"_ 3 3 3" << endl; cout<<"4 4 4 4" << endl; } } [/CODE] | |
Re: In your program, nums is just a pointer to the first element of array1. If your assignment includes a requirement to allocate a new array, why not start by doing that and then figuring out what to do with it? | |
Re: There are 4 salespeople and 5 products. Let's number the salespeople 0 through 3 and the products 0 through 4. Then the problem is asking you to create a 4 by 5 array, where each row represents a different salesperson and each column represents a different product. So, for example, … | |
Re: Complexity is a word used to describe an attribute of the process by which you understand a C++ program. This process is called complex because it has a real part and an imaginary part. | |
Re: Your array has 20 columns. When you use puts to read a string, it puts a null character ('\0') at the end of its input. So if your input is 19 characters or longer, the input (including the null character) runs off the end of the row of the array … | |
Re: The difference between [icode]int main()[/icode] and [icode]void main()[/icode] is that the first one is allowed in C++ and the second isn't. You're going to say "But my compiler accepts it!" And I'm going to reply "So? Compilers often accept code that's not valid. This fact doesn't make the code valid." | |
Re: No; you don't need to implement BigNum. You can use someone else's implementation instead. | |
Re: The last time you asked for someone else to do your homework for you, I directed your attention [URL="http://www.daniweb.com/forums/thread78223.html"]here[/URL]. I do not think you actually read it, because if you did, you would not be asking again for someone to do your homework for you. So please, do us all … | |
Re: The declaration [code] Complex c[a]; [/code] isn't valid C++, though some compilers will accept it. Those that do will presumably take it to mean a request to define an array with "a" elements. Those elements will have indices ranging from 0 through a-1. When you subsequently execute [code] c[a].setComplex(temp1, temp2); … | |
Re: You only look at the first character of each word. | |
Re: @jkoske: You know what the question is. It's "I've done a little bit of my homework; will you do the rest for me?" The answer is (or should be) no. | |
Re: Not that I can think of. Use a vector instead. | |
Re: You never change the value of your variable "current," so your program can never terminate. | |
Re: If by "best" you mean the closest to 12 without being greater than 12, then what you have just described is a version of the [URL="http://en.wikipedia.org/wiki/Knapsack_problem"]knapsack problem[/URL], which is known to be hard to solve efficiently. | |
Re: Since when is 4 prime? Isn't that what you're claiming in line 20 of your code? Also, if you care about execution time, one easy way to speed things up is to observe that you don't have to divide a candidate by every prime; just by the ones that are … | |
Re: Use code tags. Without them, all your indentation goes away, which makes your code very hard to read. If your book really contained the line delete [] x,a,b,c,beta,gamma,r; then I suggest you stop using that book, because the author doesn't know C++ very well. Ditto for the overall design of … | |
Re: It looks to me like you have an extra "if" and an extra pair of { } in line 30. That is, lines 29-30 should read else if (discriminant==0) | |
Re: Your statement int Size = sizeof Array / sizeof Array[0]; will not work if Array is a formal parameter, because in that case, Array is simply a pointer and sizeof Array is the size of a pointer. If you want to use an array parameter to represent an array, you … | |
Re: Who knows? You certainly have not pasted all the relevant code, because you haven't told us what the value of the variable "i" is or what the noBucket function does. I will say that your use of "i" makes me suspicious, because it's not a variable in your class. By … | |
Re: If you are going to use the accumulate function to add floating-point numbers together, the third argument has to be 0.0, not 0 | |
Re: If you know how to do most of it, how about doing the part you know how to do, posting the code, and asking for advice on how to do the rest? | |
Re: I'm going to turn the question around: You can have a pointer to int, or a pointer to double, or a pointer to a class object, or a pointer to a function, or a pointer to an object of any of a bunch of other types I've left out. What … | |
Re: [QUOTE=PMorphy;1465111]It's probably better to read and write the entire object. f.read( ( char* )aClassObject, sizeof( aClass ) ); f.write( ( char* )aClassObject, sizeof( aClass ) ); [/QUOTE] Don't even think about it. This technique will not work if the object in question contains any members of type string, or vector, … | |
Re: When you call getTile, you get a newly created value of type Tile. Your statement project._p->it->getTile(x, y).CPosX = panel2->Location.X;project._p->it->getTile(x, y).CPosX = panel2->Location.X; calls getTile to obtain such an object, then changes the CPosX member of that object, and finally throws the object away. Fortunately, C++ doesn't let you do that; … | |
Re: You have not specified the problem fully enough to make it possible to think about how to solve it. For example, first you say that the program should randomly generate 25 numbers, and then you say that "almost 15 or 16 numbers" (whatever that means) should be zero. It is … | |
Re: Where's the definition for SListIterator? | |
Re: You can also define a map<string,int> that you can use to look up a string, obtain a corresponding integer, and use that integer in a switch. Depending on how you write your code, that strategy may well run faster, and be easier to maintain, than using a series of if-then-else … |
The End.