388 Posted Topics

Member Avatar for merse

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.

Member Avatar for merse
0
179
Member Avatar for z_a

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 …

Member Avatar for z_a
0
456
Member Avatar for gbsn3219

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.

Member Avatar for gbsn3219
0
161
Member Avatar for techfish

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 …

Member Avatar for arkoenig
0
827
Member Avatar for BOAH365

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 …

Member Avatar for BOAH365
0
188
Member Avatar for Nathaniel10

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 …

Member Avatar for Nathaniel10
0
111
Member Avatar for fakiha erum

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.

Member Avatar for Nick Evan
0
159
Member Avatar for atoivan

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?

Member Avatar for atoivan
0
89
Member Avatar for jeffpro

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. :-)

Member Avatar for arkoenig
0
111
Member Avatar for hystaspes

It's a tag followed by one or more declarators. A tag, in turn, is the identifier that follows "struct," "class," or "union."

Member Avatar for hystaspes
0
283
Member Avatar for baconswife

How can you print an int variable and get a value that is not an integer?

Member Avatar for arkoenig
0
133
Member Avatar for qvyhnl

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 …

Member Avatar for qvyhnl
0
149
Member Avatar for Miyamoto

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 …

Member Avatar for arkoenig
0
980
Member Avatar for vbx_wx

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.

Member Avatar for arkoenig
0
94
Member Avatar for sairakhalid

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.

Member Avatar for sairakhalid
0
177
Member Avatar for smithag261

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 …

Member Avatar for arkoenig
0
233
Member Avatar for dorien

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 …

Member Avatar for dorien
0
2K
Member Avatar for nickcolb

That's one problem; there's another. When you're testing a new number, how does the variable 'sum' get back to zero?

Member Avatar for griswolf
0
135
Member Avatar for digan

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.

Member Avatar for arkoenig
0
130
Member Avatar for SolidSora

You might start by changing line 38 to say Pizza* large = new Pizza(); large->setType("pan"); large->setSize("large"); delete large;

Member Avatar for SolidSora
0
92
Member Avatar for brycematheson

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 …

Member Avatar for arkoenig
0
98
Member Avatar for phfilly

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, …

Member Avatar for phfilly
0
155
Member Avatar for Lord_Migit

[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 …

Member Avatar for Fbody
0
679
Member Avatar for hag++

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 < …

Member Avatar for hag++
0
362
Member Avatar for sid78669
Member Avatar for arkoenig
0
155
Member Avatar for OneRunner

[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 …

Member Avatar for doolali
0
121
Member Avatar for pandaEater

[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 …

Member Avatar for gashtio
0
381
Member Avatar for burningflower

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 …

Member Avatar for burningflower
0
135
Member Avatar for radmaker3

Python. It's free, widely available, easy to learn, portable across platforms, and has a variety of graphical interfaces available.

Member Avatar for 1seo
0
148
Member Avatar for bakhtawar
Member Avatar for arkoenig
0
50
Member Avatar for ultimatebuster

Why not just do the following? [CODE] import a import b jopen = a.jopen ropen = b.ropen [/CODE]

Member Avatar for ultimatebuster
0
127
Member Avatar for Beancounter5

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(); ?

Member Avatar for arkoenig
0
78
Member Avatar for Bri426

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 …

Member Avatar for mrnutty
0
144
Member Avatar for OneRunner

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 …

Member Avatar for OneRunner
0
175
Member Avatar for Duece_68

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 …

Member Avatar for arkoenig
0
151
Member Avatar for acer5542

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 …

Member Avatar for kalish88
0
461
Member Avatar for hq1

Here's a hint. Start by writing a program that reads a number and prints it out again.

Member Avatar for Fbody
0
461
Member Avatar for Macooper26

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?

Member Avatar for griswolf
0
86
Member Avatar for myk45

Count the number of floating-point additions and floating-point multiplications in both methods. I'll bet you find that they're the same.

Member Avatar for myk45
0
132
Member Avatar for blackrandom

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 …

Member Avatar for VernonDozier
0
101
Member Avatar for vasilevich
Member Avatar for genext.brite

[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] …

Member Avatar for arkoenig
-5
172
Member Avatar for vello

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 …

Member Avatar for arkoenig
0
202
Member Avatar for danalovesc

What do you mean "doesn't let me"? What happens if you change line 5 above to say [code] it=firstMap.begin(); [/code] ?

Member Avatar for danalovesc
0
110
Member Avatar for algo_man

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. …

Member Avatar for arkoenig
0
150
Member Avatar for usustarr

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 …

Member Avatar for usustarr
0
238
Member Avatar for jakesee

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 …

Member Avatar for jakesee
0
161
Member Avatar for alexchen

C++ doesn't really have 2d arrays. Perhaps you can explain in more detail what you want.

Member Avatar for alexchen
0
94
Member Avatar for Stefano Mtangoo

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 …

Member Avatar for LordNemrod
0
102
Member Avatar for BryantFury

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.

Member Avatar for BryantFury
0
121

The End.