bugmenot 25 Posting Whiz in Training

stream << rear[counter] << " ";

um... how the hell do you expect this to work?

this is a linked list, not an array; you cannot index it like that; you have to traverse the links

bugmenot 25 Posting Whiz in Training

if you want a dynamic array, which has a finite size that grows and shrinks as you add or remove elements, take a look at std::vector

Suraine commented: Thanks for the suggestion :) +1
bugmenot 25 Posting Whiz in Training

you mean

static myClass *getInstance();
bugmenot 25 Posting Whiz in Training
Candies[0] = {"Violent Crumple", 20.5, 7000};

which I know doesn't work (syntax error) - but why not??

I think this will be possible in the next version of C++

bugmenot 25 Posting Whiz in Training
bugmenot 25 Posting Whiz in Training

how did you decide this is the case?

and how big is your "int"?

bugmenot 25 Posting Whiz in Training

result is set to 10 in the last iteration of the first for loop

and then you assign result (10) to every element of your 2-d array in the other for loops

bugmenot 25 Posting Whiz in Training

Wow that's a badly named function. "increment" doesn't mean "return the thing that's one bigger" (that would be called "successor" or something like that). "increment" usually means "take this variable and change it so that it is one bigger".

bugmenot 25 Posting Whiz in Training

so lets look at line 112:

truckinfo[i].Set(inputhp, inputmileage, inputyear);

The two references that you dereference in that line are "truckinfo" and "truckinfo". "truckinfo" isn't null because you initialized it to a new array before the loop.

As for "truckinfo", no elements of the array have ever been set to anything in your code. "truckinfo" is an array of references, so all the elements are initialized to null by default.

bugmenot 25 Posting Whiz in Training

but that doesn't insert it in the right place

bugmenot 25 Posting Whiz in Training

allocate it dynamically from the heap, which is usually much larger

bugmenot 25 Posting Whiz in Training

it works right for me
3
2
1
-1
-2
-3

bugmenot 25 Posting Whiz in Training

inner classes are nice because they can implicitly access the fields of the enclosing instance, so if your buttons were pointed to by a field, then you can use an inner class to access them

bugmenot 25 Posting Whiz in Training

it doesn't print any errors for me

one of the problems that you have of course is that you only have one "arrtibute" object in the entire program; so the values of the map all point to the same object

bugmenot 25 Posting Whiz in Training

there are numeric_limits<float>::quiet_NaN() and numeric_limits<float>::signaling_NaN()

bugmenot 25 Posting Whiz in Training

yes, although it will be copied, which might be slow

what doesn't work? post your code

bugmenot 25 Posting Whiz in Training

so wordlist::wordcount is a function. you are trying to get a field of it?

bugmenot 25 Posting Whiz in Training

yes, use Iterator if possible

bugmenot 25 Posting Whiz in Training
bugmenot 25 Posting Whiz in Training

call the constructor explicitly to create a new temporary object

problems.push_back(problem(person, value, assistant));
bugmenot 25 Posting Whiz in Training

um.. so for starters, you know that you can only put code in methods? you can't have statements randomly outside methods

bugmenot 25 Posting Whiz in Training

it appears to be an applet. you usually have to embed the applet in an HTML page using applet tags and use a browser to run it

bugmenot 25 Posting Whiz in Training

you should have

int starB=10;

inside the outer while loop

bugmenot 25 Posting Whiz in Training

"cin >> Y" parses a boolean (which i think just parses a number); not a "Y"; are you confused because you have a variable named "Y"?

bugmenot 25 Posting Whiz in Training

next time why don't you tell us why you think it's wrong first

how is "position" used in your method? you seem to just iterate to the end

bugmenot 25 Posting Whiz in Training

do you mean, "it doesn't compile"? there are no classes named Widget, Spork, or Grommet; how do you expect to create new objects of those classes?

bugmenot 25 Posting Whiz in Training

the order that operands are executed is not really defined, so you should really not have operations that have side effects and operations that are affected by those side effects in the same expression

you have the code

(cout << a.f()) << a.f();

in this particular case, they evaluated the right side of the << first, so the second a.f() returns 1, and then later they evaluated the thing in parentheses

but another compiler could do it the other way around, and evaluate the thing in the parenthesis first, and then your output would be "12"

you should separate side effects into different statements if you don't want to run into this kind of stuff

bugmenot 25 Posting Whiz in Training

you cannot dereference a void pointer (what would you get? a void?) what are you trying to accomplish anyway?

bugmenot 25 Posting Whiz in Training

string is in the std namespace

bugmenot 25 Posting Whiz in Training

if you just used pointers

#ifndef LINE_H
#define LINE_H

class Point;

class Line
{
	// Ax+By+C = 0
	double A,B,C;
	Point *p1, *p2;

public:

	Line();

	Line(Point *P1, Point *P2);

	~Line() {}

	double getA() { return A;}
	double getB() {	return B;}
	double getC() {	return C;}
	Point *getP1() {return p1;}
	Point *getP2() {return p2;}
};

#endif
bugmenot 25 Posting Whiz in Training

can you post your entire code?

bugmenot 25 Posting Whiz in Training

thanks...that looks much cleaner, i will change it to that...

but the whole program is just not doing what i need it to do, and i do not know what i am doing wrong...

bugmenot 25 Posting Whiz in Training

hi, i need help please...

i need to write a program to calculate the depreciation of equipment passed its useful life using two different methods...

these are the actual requirements for the program:

"Depreciation"

Program requirements:

1)

write a c++ program to calculate depreciation using the straight-line and sum-of-digits methods.

2)

this program must use at least three functions

3)

depreciation is a decrease in value of some asset over time due to wear and decay. For exampl, suppose that a company purchases a computer system for $200,000 that will serve its needs for a five-year period. After that time, it can be sold for an estimated $50,000. The equipment will have a depreciated by $150,000 during the five-year period.

4)

the input to the program will be the initial cost, the residual value, and the number of years to depreciate, plua a code to indicate whether to use straight-line or sum-of-digits method.

5)

the output of the program will be a series of tables, one for each of the input lines. The program must use an end-of-file loop to get credit.

6)

The program must use file I/O

---------------------------------------------------------------------------

INPUT


200000.0 50000.0 5 S // S means straight-lie method
200000.0 50000.0 5 D // D means sum-of-digits method
15000.0 2500.0 10 S
20000.0 2500.0 8 D

---------------------------------------------------------------------------

OUTPUT

for each depreciation table, …

bugmenot 25 Posting Whiz in Training

So is this the equivalent of the following in C++?

yes. (except that in Java the first object is garbage-collected and in C++ it isn't)

bugmenot 25 Posting Whiz in Training

you should read a basic guide to Java

Java consists only of primitive types and reference types (which are kind of like pointers in C). Reference types point to objects, and are named after the class of objects they point to. Objects are not values in Java; and are always manipulated via references.

bugmenot 25 Posting Whiz in Training

"b" and "c" are references (like the previous poster said, kind of like pointers in C) which may point to objects. objects are not values in java; instead, you always manipulate them through references. you have one reference pointing to one object and another reference pointing to another object; then you assign one reference to another, so now they both point to the same object.

bugmenot 25 Posting Whiz in Training

your master class must explicitly initialize the person class, i think

bugmenot 25 Posting Whiz in Training

right; in fact, every instantiation of the templated may have a separate copy

bugmenot 25 Posting Whiz in Training

um... you have random code outside of a method, in the declaration of class "carinfo"

bugmenot 25 Posting Whiz in Training

what exactly is your question?

why can't the classes be separate and you just put each class in its own file?

also the "main" method should be static

bugmenot 25 Posting Whiz in Training

it's self-explanatory

"searchaddress" is a character, not a string

bugmenot 25 Posting Whiz in Training

your constructor is probably wrong

bugmenot 25 Posting Whiz in Training

instance methods take an extra argument, the pointer to the instance that they are invoked on (the "this" pointer). so i have no idea how you think you are going to try to call an instance method without an instance

bugmenot 25 Posting Whiz in Training

if you really want to know, the members of an array are specified in JLS 10.7

bugmenot 25 Posting Whiz in Training

Enable JavaScript, problem solved.

Wow, thanks for the pointing out the obvious but that's not the problem. Javascript is enabled, was never disabled, and yet Rapidshare still insists that Javascript be turned on. What's your solution for that?

bugmenot 25 Posting Whiz in Training

i think something's actually wrong with your logic. i can't see your code, so I don't know what methods like getIndex(), setChild(), and stuff do; but... your recursion only stops if i == m, where i is obtained from getIndex(). how is getIndex() gotten? that stopping condition only makes sense if, say, the getIndex() value keeps track of the depth of the node in the tree or something

i am guessing that setChild() creates a new TreeNode object and sets its "price" and "index" to its arguments. so for every node, its children will always get indexes from 0 to 29, and each of its children will get indexes from 0 to 29. so it does not have anything to do with the depth

maybe i'm wrong; but it's really hard to tell without your other code

bugmenot 25 Posting Whiz in Training

it's really hard to tell what you are doing without seeing some code

in your "tree", do the nodes have references to their children; if so, then the children are not garbage collected, because they are reachable

what you describe about going into the leaves and returning back up, is simply just called "recursion"; and you don't really need to think about trees at all

bugmenot 25 Posting Whiz in Training

your remove() method doesn't have a closing brace

perhaps this has to do with your two opening braces after the if

bugmenot 25 Posting Whiz in Training

it's not security (there are ways to get access to private fields and methods anyway), it's called abstraction

the idea is that if people can access stuff, then they will write code which will depend on it; then when you want to change the implementation, it will not work anymore. So you should only provide as public an interface that does everything people need to do, which will stay the same, and then force people to use that public interface; then if you change the other private implementation details, it will still work

bugmenot 25 Posting Whiz in Training

isn't it printed out by your program?