388 Posted Topics
Re: Given a number x, you want to find epsilon with the following two properties: 1) x + epsilon != x 2) If 0 <= y < epsilon, x + y == x. It should not be terribly hard to find the value of epsilon by binary search. | |
Re: I am sorry to say that this entire long message is based on a fundamental misconception. The name of an array is [i]not[/i] a pointer. Its type is an array type, not a pointer type. Array types and pointer types are different from each other. You can see this difference … | |
Re: If you don't see why the program doesn't work, I suggest that you go through the program a line at a time and explain to us what each line does and why you are confident that it is correct. | |
Re: Lines 35 and 36 are wrong. I think you think that they allocate an array with [i]numCourses[/i] elements and copy the contents of the array to which [i]courseList[/i] points into that array. They don't; what they do is put in [i]this->courseList[/i] a pointer to a newly allocated array, then throw … | |
Re: From a compilation viewpoint, I see nothing that should prevent this code from linking. I do see a missing # in line 1, which I assume you removed inadvertently, and a type error in line 75; but when those errors are corrected, the program compiles and links over here. I … | |
Re: Yes it is possible to have an array as a class member. However, in all arrays in C++, the number of elements must be a compile-time constant. In the code you cited, you tried to define an array with i elements, where i is a variable that changes at run … | |
Re: That is because myk45 gave you pseudocode instead of C++. If you do not know how to translate what myk45 wrote into C++, then you are probably in serious trouble, and you should consider dropping the course. | |
Re: Apparently someone has already done part of your homework for you. This list doesn't usually do people's homework for them. Why not ask the person who did the first part to do the rest of it? | |
Re: Yes: Look on line 148 of the file c:\program files\microsoft visual studio .net 2003\vc7\atlmfc\include\atlcomcli.h, and there you will find a variable named p, probably a pointer, that is zero when it shouldn't be. Now figure out how that variable got that way and fix it. :-) | |
Re: It's a tag followed by one or more declarators. A tag, in turn, is the identifier that follows "struct," "class," or "union." | |
Re: How can you print an int variable and get a value that is not an integer? | |
Re: Your definition of class Car is definitely wrong. The Car constructor does not initialize driver or owner, but the set_driver and set_owner functions assume that driver or owner (respectively) have been initialized. I am guessing that line 5 of Car should be driver = p; and line 8 should be … | |
Re: In general, saying that an algorithm runs in O(f(n)) time means that there exists a constant k such that if you make n large enough, the run time for input of length n will never exceed k*f(n). The time units in which f(n) are expressed doesn't matter, as you can … | |
Re: Yes -- the first one is well-formed C++ (if X is a type and x isn't already defined in the same scope) and the second isn't. | |
Re: Your statement [code]temptr->next = temptr;[/code] should probably be [code]temptr = temptr->next;[/code] There may be other problems, but this is a good place to start. That said, I would like to suggest that you learn how to use code tags properly. | |
Re: If n is a non-negative integer: The last digit of n is n%10. If n < 10, the first digit of n is n. If n >= 10, the first digit of n is the first digit of n/10. This is all you need to know in order to solve … | |
Re: I think it would be a good idea to define the problem precisely. Are you looking for every sequence that repeats? Including sequences of a single element? Must the repetitions be consecutive, or can other elements separate them? Can the repetition overlap the original? Are you looking for every sequence … | |
Re: That's one problem; there's another. When you're testing a new number, how does the variable 'sum' get back to zero? | |
Re: Line 23: double values[quantity]; is not permitted in standard C++ unless quantity is known at compile time. Your compiler may permit it as an extension; but if you want to rely on that extension, you should be aware that what you're writing is not really a C++ program. | |
Re: You might start by changing line 38 to say Pizza* large = new Pizza(); large->setType("pan"); large->setSize("large"); delete large; | |
Re: I'm going to disagree with both gerard4143 and NathanOliver here. You can pass an array by reference as follows: 1) Change line 14 to the following: [CODE] int readFile(int sum, int &count, int (&grades) [10]) [/CODE] In case you're wondering what I changed, I moved one parenthesis. 2) Change line … | |
Re: Here's the first place I'd look. In line 3, you define a pointer variable named Selected, but you don't initialize it. In lines 9 and 13, you test two different conditions and, depending on the results of those tests, initialize Selected or don't. So if both of those tests fail, … | |
Re: [QUOTE=Intrade;1370750]As in-- [url]http://www.cplusplus.com/reference/stl/vector/vector/[/url] -- nowhere in his code did I see construction of a vector [U]with[/U] allocated space to set the size param. Nowhere for that particular vector was a push_back called. [/QUOTE] It's called on line 16 of the original code. Anyway... I agree with stuXYZ's comment that there … | |
Re: gerard4143 is mistaken -- the semicolon is correct in this context. However, I can see three potential problems and I can't tell from the code you've posted whether they're relevant: 1) What types do j and k have? If they are unsigned, then j-1 and k-1 will never be < … | |
Re: Your poll does not allow me to select more than one alternative. I would like to select #3 and #4 but I can't. | |
Re: [QUOTE=tkud;1365681]If at all u want to use the ASCII equivalent of a letter, it should be like this: [CODE]atoi('89');[/CODE][/QUOTE] No, it shouldn't. [icode]'89'[/icode] does not have a well-defined meaning in standard C++, so if your compiler accepts it, it's a local extension. If you want the character that is equivalent … | |
Re: [QUOTE=csurfer;1352618]==> (2 power (n-1)) - 1 And thats your complexity or Big-Oh.Hope you understand...Cannot put it in any better way :)[/QUOTE] Actually, you can -- because O(2^(n-1)-1) is the same as O(2^n). To see this, realize that when you're talking about big-O notation, adding or subtracting a constant, or multiplying … | |
Re: One of the biggest problems with submitting homework online is that of determining whether the homework being submitted was actually done by the student--or, perhaps, was instead the result of the student going online and trying to talk someone else into doing the student's homework instead. Which is what you … | |
Re: Python. It's free, widely available, easy to learn, portable across platforms, and has a variety of graphical interfaces available. | |
Re: plz at least try to do your own homework before asking for help | |
Re: Why not just do the following? [CODE] import a import b jopen = a.jopen ropen = b.ropen [/CODE] | |
Re: I don't see anything wrong with what you've written, provided that j is in fact an object of the appropriate reverse iterator type. However, I wonder why you're not just writing bunnyList.last()->printSummary(); ? | |
Re: LetterGrade is a function. That means that if you want to use it, you have to give it an argument. So, for example, in line 31, where you wrote [CODE] cout << LetterGrade << endl; [/CODE] you should have written [CODE] cout << LetterGrade(test1) << endl; [/CODE] Also, I note … | |
Re: Yes, it's easy. Probably the easiest way to do it (it's not the fastest, but will probably be more than fast enough for most practical purposes) is to use a map: [CODE] std::map<char, char> key; key['I'] = 'E'; key['F'] = 'V'; // and so on [/CODE] and then you can … | |
Re: Actually, it's rather remarkable that the code you posted should work at all. You may have thought that you wrote [CODE]#define SQUARED(x) (x * x)[/CODE] but what you actually wrote is [CODE]#define SQUARED(x) {x * x}[/CODE] so that your statement [CODE]int i = SQUARED(3 + 2);[/CODE] should expand to [CODE]int … | |
Re: Yes you can solve this just with AND OR XOR NOT. Moreover, because NOT(a) is XOR(A,A), you don't need NOT. Similar reasoning will show you tnat you don't need AND or OR, either, so long as you have XOR. If, on the other and, you don't have XOR, then you … | |
Re: Here's a hint. Start by writing a program that reads a number and prints it out again. | |
Re: When you installed Python, the installation should have included a program called "Idle," which is a straightforward development environment for Python. Have you tried using that? | |
Re: Count the number of floating-point additions and floating-point multiplications in both methods. I'll bet you find that they're the same. | |
Re: Four simple rules, which are slightly harder to combine in practice than their simplicity suggests. 1) When you call a function, you effectively initialize each parameter from the corresponding argument. 2) There is no such thing as a two-dimensional array; what looks like a two-dimensional array is really an array … | |
| |
Re: [QUOTE=drkybelk;1344872]NOTE: if you have more than one (pre-)post-increments in one statement, then the behaviour is undefined, that means the following line will result in different outputs on different compilers or even wors on different runs of the same program. VERY BAD. [code] m=i++ && j++ && k++ || l++; [/code][/QUOTE] … | |
Re: Line 10 defines a variable named "a". Line 45 also defines a variable named "a". Which one do you expect your "find" function to use in line 31, and why? Also, while we're at it, lines 44-45 and 59 are not legal in standard C++: The size of an array … | |
Re: What do you mean "doesn't let me"? What happens if you change line 5 above to say [code] it=firstMap.begin(); [/code] ? | |
Re: The problem is vaguely specified, so I am going to try to do some guessing at how to specify it more precisely. This guessing is based on the assumption that the problem actually has a solution--in other words, that there exists an algorithm capable of solving it in O(1) time. … | |
Re: You define badDriveList in one function and expect to be able to use it in another. That won't work, period. As you've written your code, badDriveList is a local variable in TestSystem::Drive, and will be destroyed as soon as TestSystem::Drive exits. What you probably need to do is to make … | |
Re: Here is what I think is a simpler version of the question you are asking. [code] struct Foo { int x, y; }; Foo bar[2]; void f() { int* p = &bar[0].x; // ... } [/CODE] I believe you are asking where there is any portable of incrementing [icode]p[/icode] so … | |
Re: C++ doesn't really have 2d arrays. Perhaps you can explain in more detail what you want. | |
Re: The reason that C++ has both the struct and class keywords is that Bjarne Stroustrup believes that important concepts should have names. Consider: If C++ were to have only one of struct or class, it would have to keep struct and ditch class, because otherwise even the sipmlest C programs … | |
Re: If you can't solve the problem, try solving a simpler one first. For example, try writing a function that takes two integers as its arguments and returns their sum as its result. Then try making the function return a long integer. |
The End.