jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Do you have numbers in your setNumerator and setDenominator (1 and 2) functions? If so go one step futher and make sure they are still there. Put a cout statement with the values and maybe a nice message like "I'm in setNumerator and num = " then display num. Do this for all those methods and work your way out. There is no other way to do it (aside from stepping through on a debugger).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You should call srand() only once and in main() before you call the methods that use rand(). What problems are you having with the output? Can you determine (using cout statements) where the data are getting lost?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

char * is a C style string (versus a std::string in C++), also a pointer to char (related to them being considered arrays of char). C strings must be null terminated (that is end in the character '\0') and they are immutable (you can't change a character while leaving the string intact).

The header file (#include <cstring>) has the functions strcpy and strcmp among others, almost all of which take char * as the types of their parameters. See this for a reference.

Also, please use the code tags:

[code]

//code goes here

[/code]

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

For templates the declaration and implementation must be kept in the same header file (see http://www.parashift.com/c++-faq-lite/templates.html#faq-35.12) only a few compilers can handle the export keyword to make this possible and I don't believe VC++ is one of them.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

that would work with no compiler errors?

Only one way to find out. Yes, it should. It's the same thing you did with TicTacToe within its own class (which you should still look into btw).

so in that sense thats how you use the pointer with class to reference to the functions?

With a pointer to a class, yes, that's how you would access its methods.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster


in TicTacToe, you would do this:

Player myPlayer = new Player();
myPlayer.PlayerTurn();

If you are going to do it that way it would be Player * myPlayer = new Player(); myPlayer->PlayerTurn();

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Out of curiosity, why do you create another tic-tac-toe object within the tic-tac-toe class?

To call the methods of the other class just instantiate it:

MyOtherClass myinstance;
myinstance.methodNeeded();

(since you don't need pointers in this case you can put that on hold for a while)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

e.g. 3.4 to 3

Math.Ceiling(ValueToRoundup)

Except calling Math.Ceiling() on 3.4 will give you 4.0 not 3.0.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

textBox1->Lines = gcnew array<String^> {"Success"}; is the command that you need. Buried in the MSDN entry for Lines I found the following:

Note:

By default, the collection of lines is a [B]read-only[/B] (my emphasis added) copy of the lines in the TextBox. To get a writable collection of lines, use code similar to the following: textBox1.Lines = new string[] { "abcd" };
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Once you have a new Fibonacci number use another small loop to go from the previous Fib number until the current one. Record/output those values that you find.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Your do/while repeats until you hit a 5 to exit like restrictment said. Isn't that what you want? If not what behavior do you want?
Your inner while OTOH repeats the prompting when your input is outside of your range.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

LOL I was going to make a joke about that but I was secretly hoping those posts would be deleted... :-O

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Where on earth did int mainMenuSelection(int); come from? Looks like a function prototype to me.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I didn't even see those two lines. Yes, you're right. srand() is called once. rand() is used subsequently. If you don't use the % operator to cap it off it's going to give you some big numbers (% is modulus meaning the remainder left after division).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

What error are you getting (also using namespace std; should be outside of main at the top under your #includes)?

(Post 1500) - Ignore this just a counter

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster
#include <cstdlib> // for rand and srand
#include <ctime> //for time()

int main()
{
      srand((unsigned)time(0));
      
//rest of your code etc.

srand is the function, time(0) gets the current system time (in terms of an integer type called time_t) and the (unsigned) casts that time_t to an unsigned integer that srand prefers.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

What is the problem you are experiencing with the code. That's what Zcool is trying to get you to express. "It doesn't work" is not enough for anyone to go on. What do you expect from it and how is it breaking?

If you don't know that go back and debug or put some couts in your program at strategic places. At least give us something to go on.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

that solution wouldn't extend very well at all.

I couldn't agree more. He/she had said "this array" which I took to mean this was it for the array and the elements.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Congrats on making a decent effort on what we had talked about in the other thread.
However:

array monster [level 1 , 100 health];

damage ++ 1-10;

you're still making up syntax as you go. It would be the equivalent of me walking up to you to have a conversation and saying "Car nematode went see down global equivocally dentist." It's kind of grinding on the mind to read.

Look up rand and srand to get an idea so that you can say something like energy = energy - (rand() % 35 + 1); which will reduce the energy between 1 and 35 points. Use srand() once in your program to seed the random number generator.

dusktreader commented: "Car nematode went see down global equivocally dentist." -> classic! +1
Nick Evan commented: :) +12
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Your do/while syntax is incorrect. It should be:

do{


}while(condition);

You're going to have to nest some of these menus so do a brief sketch on a piece of paper as to how they should be laid out.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster
double arrive = integar1 + (integar2/100);
double depart = integar3 + (integar4/100);

What portion of an hour is 30 minutes? It's surely not 0.3.

Otherwise just go ahead and do the portion for the truck.

(and just a nitpicky thing but you don't need to include fstream)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

That's correct if you're using the absolute value abs(x - checksum) or unless you know for absolutely sure that x will always be greater than checksum. If not you need the && with the (x - checksum) > -100 as what if the relation between the two is flipped around.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

some wire strippers

I believe the term "dancer" is preferred nowadays ;)

(I know I know... I just couldn't resist)

Ezzaral commented: hehe +0
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

(x - checksum) must be less than 100 AND (x - checksum) must be greater than -100 (or you can use absolute value but this is much cheaper)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Would it help you to know

char a = '1';
a++;

will give you '2'?

Now use the array indicies to offset the value by the number of rows (with the appropriate number of columns) and by the leftover columns. Trial and error should get it if nothing else.

Honestly, it's almost less work to do it the way you have it there.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Okaaay. Now I remember :) There are still a lot of the same errors in there as before. You really need to sit down and spend some time with the fundamentals (e.g. array declaration, avoiding goto, if statements). I realize the focus of your course may be the numerical methods themselves but you still have to put the time in on your own to learn the language. Lines 89-126 are still in "no mans land" (global) as far as I can tell. I'm not sure what else to tell you. Write small programs first (i.e., get your routine working in the main() program, test it and then move it out to a function if you have to) and then work your way up.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Everybody will probably give me guff for saying this but if this isn't your assignment and you are trying to process a lot of real data try "preconditioning" it in Excel or the like.
It looks like maybe that's what someone had done with the -999 but I'm not sure of that. If that's the case already then you'll just have to deal with that type of situation in post-processing by sorting the outliers together and either treating them differently or ignoring them.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Apologies because I'm at a loss. Since it is a reference it must be initialized in the constructor. I just don't know what you should initialize it to in the default constructor since no arguments are being passed in.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

It's probably unrelated but aren't you inheriting GWin from Board? If so why are you redeclaring it?

As to the main problem, I think that your GWin needs to be initialized (even if there is no value for it) since it is a reference. Try writing the default constructors as Board : Gwin(NULL) {} and Ship : Gwin(NULL) {} Regrettably I'm not sure that even if it works it is necessarily the right approach.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Put Board() {} in the header (no semicolon and the empty braces). Then you will not need to put the definition in the implementation file. I thought the problem was with Ship, though. You may need to do it for both.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Try it out on paper for something simple like 10/2 (repeat your subtraction of until you get to zero). A pattern will emerge. Determine a "base case" when you should stop subtracting.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I got it to run fine as is on my machine:

Enter the first input (EOF to end):
10
Enter the next input (EOF to end):
10
Enter the next input (EOF to end):
10
Enter the next input (EOF to end):
30
Enter the next input (EOF to end):
^Z
sum = 60.000000

What are you using for EOF? On Windows it's CTRL-Z (or F6) on *nix it's CTRL-D.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I have a feature suggestion, since I know you are nothing short of super ultra busy or anything :P

I use the Previous Thread / Next Thread links at the bottom of the page of posts all of the time, but I'd like to be able to do the same with the subscribed posts. Maybe someone has found a workaround to this but when I log in I go right for User Control Panel and the subscribed threads. When I'm in the first one I want to go to the next one and so I go back to User Control Panel and click the next one (I don't necessarily want to use the back button to go through as perhaps something has changed by that point). Repeat ad infinitum. So if it's at all feasible I was wondering if there could be "Previous Subscribed Thread"/"Next Subscribed Thread" links at the bottom of every post?

On a related note to the links at the bottom of the page, I've always been curious why the code snippets don't have Previous Thread/Next Thread links? Is it because they are stored separately? I just get some momentum going through the threads and then bam, run into a roadblock.

I'm not a web programmer by any stretch of the imagination so I can't really tell if these would be quick fixes or if they require a lot. These are really matters of convenience so if it's the latter file it on the …

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I'm confused. "tags" is an int (line 16), and you're reading into like it's a string (line 41) and you're trying to compare it to multiple characters (line 56) within a spot for a single character (single quotes).

I'd say grab a good book and spend at least a week or so going through some of the basics.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

See, I didn't even have to say anything. :D I think I had started to but got distracted. Don't forget the conio.h too, nice and non-standard.

jephthah commented: heh. my edit and your post passed each other like ships in the night :) +6
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Not a problem. Good luck with it.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Ah yes I know that one well. Unfortunately it doesn't give me too much to go on...it was worth a try.

On line 15 of your second-to-last box is there some reason why you have the parameters flipped around?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

What I would do is use a low-tech method: read the line into a string using getline() and step through it to count the spaces. If you don't have all the numbers you need, record the line number of the bad data, throw out the string and read another line.

Otherwise knowing whether something is of the proper nature for that element of the struct would be kind of tricky.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

What is the message with the error that it is giving you?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

== does not work to compare strings in C (nor does >=). Use the strcmp function in the string.h header. Here's a reference http://www.cplusplus.com/reference/clibrary/cstring/strcmp/ (ignore that it's on a C++ site).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

No. if you are returning *this what are you returning? What does this point to? An object of what type?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I believe if you specify a constructor other than a default one you must define a default one. So just pop it into the header file of your class (as you only need the MyConstructor {} variety). Then you won't even need it in your implementation file.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

So what datatype do add sub mul div return?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Once you've modified this in your methods you need to return *this; thus what type is your return value??

Also, on lines 15,21,25,29,35,41,47 of post number 4 is where you need to specify the return value. These definitions are no different than when you have

int myRegularFunction (int parameter) 
{
      etc. etc.
}
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You're making a bigger deal out of the arrow operator than you need to.
When you have a class you access the (public) members via the dot operator. myClass.MyMethod() for example.
But when you have a pointer to a class you need to dereference it first via the * operator. So

ClassName * myClass = new ClassName();
*myClass gets you the class object back and
(*myClass).MyMethod() calls the method (note the parentheses which are necessary for doing the deref first and then the . operator)
The shorthand for 
(*myClass).MyMethod()
is
myClass->MyMethod()

So every class has a pointer to itself known as this. To get at one of your methods you need to dereference and dot, so this->MyMethod() Without the pointer you just use the dot but the pointer is what we have to work with.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Is there a reason for returning 0 from your methods regardless of the outcome. Also in your definitions you need to put the return type

int Complex::Set_C(double x,double y) though I suspect you made them ints to make the compiler happy anyway which isn't the right approach. If you're not actually returning anything from your methods make them void.

Try and make some of those changes. I'm sure there's going to be stuff that still isn't working but see what happens.

EDIT: Also, hint: some of your methods will need to return an object of complex type.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

isn't this what happens at the end of every input line of ACM problem?

I know you like to do the contests but I am not at all familiar with the intricacies of each one.

what is the difference between endl and '\n'?

See this thread. Basically endl forces a flush the output buffer (since it is flushed under certain circumstances anyway) and inserts a newline but '\n' just gives you a newline.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Your code is kind of all over the place. The first thing you should be aware of is the syntax for declaring and defining a function (here is a rough layout):

#include<iostream>
using std::cout; //can also put "using namespace std;" (no quotes)
                           //but that can clutter up your namespace

int myfunc(int a);  //prototype or declaration of a function taking 1 
//integer parameter and returning an int
//note it's outside of main()
int main()
{
  int holder;
  int parameter = 10;
  holder = myfunc(parameter);
  return 0;
}
//following is the definition of the function which is placed outside of 
//main() -- it could be placed above main and then you wouldn't need 
//the prototype up there -- but this is more the convention.
int myfunc(int input)
{
     return (input+1);
}

You seem to have some of it down I just wanted to make sure you had a clearer road map.

As far as the gradient goes, it's simply the partial derivative of the function in each of the variables (all "d"s are partials):

e.g., grad F(x) = dF/dx
        grad F(x,y) = (dF/dx, dF/dy)
        grad F(x,y,z) = (dF/dx,dF/dy,dF/dz)

So for d/dx assume y and z are constants and treat them as such. I'm presuming since it's your course you recall exactly how to do that much better than me but it should be the usual (delta y)/(delta x) = f(x) type business.

Have a go with getting your functions and main correct and then post back and I …

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Big question what is the access specifier of all of these?

bool DieselTypeStatus;	//ok
	Truck();				//ok
	void Truck(bool);	       //wrong - no return type
	~Truck();			
	void DieselTypeStatus(bool);	//wrong-duplicate name
	bool getDieselTypeStatus()const;
        [missing - declaration for setDieselTypeStatus(bool)]
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Read through at least the first few paragraphs of this (the rest starts to get into some specifics you may not need right now).