jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

pi / 180 is what you'd use if you were making the conversion from degrees. i don't think he is doing that, his input is just in radians, actually the input is the multiplier, like 1/4 * PI or 2 * PI, etc.

I didn't read the OP's prompts, so that's my bad.

@OP: To illustrate the problem of approximations that jephthah was explaining look at this graph of sin x versus it's series approximation http://en.wikipedia.org/wiki/File:Taylorsine.svg. It only holds over a limited interval. I think you can in fact improve this a bit by specifying a point about which you are approximating the function (see http://en.wikipedia.org/wiki/Taylor_series#Definition where they have the (x-a) instead of x) but there's only so much you can do.

jephthah commented: good explanation +7
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Embaressingly simple!

Thanks again.

Nah, they're just new for a lot of people. They play very well with interfaces if you go down that road at a later time.

Never a problem.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Yep, you can shift to using "is"

foreach(BaseGameEntity bge in entityList)
    if(entity is Drop)
       //process it
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Use the "as" keyword to cast them (I ignored the list portion for simplicity):

BaseGameEntity bge = new Drop();
(bge as Drop).DropMethod();

or you can use the old fashioned

((Drop) bge).DropMethod();
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

See this recent thread of cwarn23. It's got an administrator response on there from Happygeek.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Do I have to put "revenuePercentage = revenuePercentage /100;" before line 27?

No, but look if your tickets sold is less than zero you don't give the user the opportunity to re-enter and control passes over the else leaving revenuePercentage (and moneyDistributed) undefined. It's definitely not assigned before that. Initialize it to zero and change your if/else(line 22/25) to a while loop where the user is reprompted. That way everything is all set and the program won't accept any negative ticket amounts.

Trace through your program with a pencil and paper by hand and see where different conditions change the flow. Also, it very rarely hurts to initialize these variables to a value when they are declared.

Banfa commented: Just for shear persistence in this thread +1
tux4life commented: That pencil-paper approach is superb! I speak from experience :P +8
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Can you find a path through your code in which revenuePercentage doesn't get assigned a value? Think about what you've corrected so far.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

The math.h functions take an angle in radians. Use the conversion pi radians is to 180 degrees to convert your angles before sending them in.

mrnutty commented: And the one that solves this mystery +5
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I'm not going to look at it until you put code tags (you may have to paste it in again to keep the formatting). And you still have the commas in with the numbers, are you even compiling this at all?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I was thinking of creating my own rival search engine and calling it "Crosby" ;)

I would see your unrelated Crosby entity and raise you Stills and Nash (and maybe even Young).

I keep wondering when Bing is going to start making decisions for me -- it's supposed to tell me which airline flights are bearing north by northeast while serving pretzels from a flight attendant named Gertrude. And how about that Wolfram Alpha...

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Make sure it's between 0 and 9 and then add '0' to it. char a; a= '0' + 1 (a = '1')

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

IMO, Head First C# is a good way to get from the ground to the first/second floor quickly. From there you could select something more suited to a specific area where you want to end up.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

What do you mean by fails to execute? What do you end up with in the string? Does it throw an exception?

EDIT: I just tested it with 3 copies of a (short) novel in a row (~500K) and had no problem

ddanbe commented: Congratulations with your nomination! :) +6
kvprajapati commented: Congratulations!!! +9
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Remember, if backwards starts empty, all you need to do is add the character from word with +

That was going to be my big finish :) If you want to do it by index of backwards set backwards to word initially so you have the right number of spaces in the array.

WaltP commented: Sorry for blowing you big surprise :P +11
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

In reality you can make your loop something like while(Input >> num[j]) and increment j within the while loop. If you know you have a constraint of 100 items and no more you can incorporate that into the while as while(j<100 && Input>>num[j]) just make sure j is initialized.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I didn't go over your code in great detail. I was able to run it with the following output:

There is no element at the given ID.
The ID of the station being added already exists.
Name: Boardwalk, ID number: 1
Name: Boardwalk, ID number: 6
Name: New York Ave., ID number: 3
Name: Marvin Gardens, ID number: 2
There is no element at the given ID.
Name: Boardwalk, ID number: 1
Name: Boardwalk, ID number: 6
Name: New York Ave., ID number: 3
Name: Marvin Gardens, ID number: 2

I think (unless I am confused by the usage) you are using a roundabout and incorrect method of accessing the dictionary. I know you had another thread about this but it doesn't look like you were able to change it. I'll give you a couple of lines and you can fix the rest in turn.
Since your id is an integer you can use the [] notation to access elements at a particular integer key:
(from lines 61 and 62 of the second file)

insert.Next = stationDictionary[id].Next;
//since stationDictionary[key] give you Value for that key
insert.Previous = stationDictionary[id];

Also, when you are using the automatic properties you don't need to have an explicitly defined private variable to hold the data-- so you don't need lines 13 and 14 of the first file.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Really you'd remember "to" and then "en" and then "em" and then in a shocking twist you'd remember "M."

That and for you, you'd have #include <stdio.h> tattooed on your arm and not remember why.

I don't know why, but every time i see this thread title Memento comes to mind. maybe it's because i just cant remember any other titles.

Ha ha. get it? I cant remember them!! LOL. you know, remember any ...

oh, never mind.

jephthah commented: that, and maybe "jonsca corrupted my stack" in mirror image letters on my forehead.... +0
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

If you're skipping over the design phase completely you're doing yourself a disservice. All of the work with the use cases, CRC cards, etc. should be done before you write a single line of code, that way you can include the OO principles from the ground up.

Salem commented: Absolutely! +20
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Here's an example that gives you something tangible when you click the button. Set the "Tag" property of each of the textboxes to "Text" (or some other moniker).

private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
	for(int i = 0;i<Controls->Count;i++)
		if(Controls[i]->Tag=="Text")	 
		{
	  	  dynamic_cast<TextBox^>(Controls[i])->Multiline = true;
		   dynamic_cast<TextBox^>(Controls[i])->Height = 5;
		}
}
tonymuilenburg commented: Wow, your post really saved me time and frustration! :) +0
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

SelectionStart is a property specific to TextBox. Text is a property that all Controls have. To access that property you need to downcast the controls to their particular type using a dynamic_cast to TextBox^ type. You'll have to do some checking to make sure that you have the right controls on your form, perhaps by tagging your textboxes and using that as a criterion to cast them.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

In the future please try to refrain from giving away a code sample that an OP can turn around and hand in for a grade (as I'm doubtful that not having exceptions and type safety will hinder that). Guide the poster through the process and help him/her reach the conclusions that they need to.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Without something to go on I don't know where your difficulties are. Can you write a program to read a data file? Can you write a program that writes a data file? Can you write a program that squares numbers? Start on one or more of those pieces and post back some actual code.

Also, it is disrespectful to tell us that something is urgent. Your rush does not become our rush.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I am trying to use a "while" loop because that is the chapter we're on.

The input is done by keyboard and the professor has hinted we should use some kind of "while input is good" event test for exiting the loop. We've done that sort of thing for reading from a file, but I don't know exactly how to do it for a cin string.

But with the std::string you have the information about the length already. You should probably use it, like you tried to in your example


while (count < length)

get next letter, if capital then charactrCtr = charactrCtr +1
++count

I don't know the proper command for the "get next letter" bit, though.

Sorry to be a doofus, but I don't understand exactly how to do this, even with your suggestion of "Use a for loop and march through the string by index (in string mystr = "abcd"; mystr[0] is 'a',mystr[1] is 'b')"

Is it possible to initialize count to 1, then use the count to point to the "next" letter?

Yep. That's what I was trying to say. In your snippet above if count starts at zero then userInput[count] would give you the letter at the "count" position (zero based).
So something like

string userInput = "input";
int count = 0;
while(count < userInput.length())
     cout<<userInput[count]<<" ";

would get you "i n p u t". That's all I meant when I said marching through the string. I happened to suggest …

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

So the healthy eating ethic and the non-spamming ethic don't overlap?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Except you missed the critical part: textBox->Text = textfile; and the streamreader is not called mystream, so just do sr->Closed();

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster
int x,y;
for (x = 0;x<=384;x+=3)
{
    for (y = 0;y<155;y+=3)
    {

will get you

{0,0},{0,3},{0,6} .....
{3,0},{3,3},{3,6} .....

So it will be compressed in both directions. You may need to adapt it to map properly onto your output device (so send {0,0} to pixel {0,0} and {3,0} to pixel {1,0}, etc.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Use a StreamReader object (in System::IO) to read in the text from the given filename as a string. You may be able to send it right to the textbox from there.

Here's the code I used:

private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) 
{
      OPEN DIALOG
      StreamReader^ sr = gcnew StreamReader(fileName);
      textfile = sr->ReadToEnd();
      CLOSE STREAMREADER
      SEND TO TEXTBOX
			
}
private: System::Void openFileDialog1_FileOk(System::Object^  sender, System::ComponentModel::CancelEventArgs^  e) 
{
     fileName = openFileDialog1->FileName;
 }
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

gets(String) ;

Don't recommend the use of gets. It can take input until the cows come home and tries to write it all to that array--> overrun. Use fgets instead.

jephthah commented: thank you +6
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

In your second example you haven't noticed the additional space that's being put in front of the word. This could very well be any junk character because when you reference str[strlen(str)] you overstep the bounds of the array. Remember, if your string is length 3 you're only going to have characters 0,1,2. So change that on line 23 to i = strlen(str) -1 and you'll have it right. You already figured out how you were missing the first element of the string when you had > instead of >=.

I would compliment you on a well written post (among all your other ones) but the title still needs work.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

That was your code that I had pasted in. I was just trying to narrow down the window for you to find the spot for it. You've got j in the right spot now. Use it to index your newstr array, so newstr[j] instead of i. Trace a sample run through by hand (or with your debugger) and see what the results are.

restrictment commented: Thanks a bunch! +1
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

gets(String) ;

Don't recommend the use of gets. It can take input until the cows come home and tries to write it all to that array--> overrun. Use fgets instead.

Salem commented: Yes! +19
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Check out the functions in ctype.h (include it as <cctype>). It has an ispunct() function which you could use as you're moving through your array. See this for a reference to all the functions in that header.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

OP seems to have record being passed in as a char* . Shouldn't it pass in as struct PATIENT * record ?

tux4life commented: Exactly :) +8
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

In order to place the string into the array of strings you must specify an index. E.g.,

cin >> stName[0]; //to write into the first string in the array
cout<<stName[0]<<endl;
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Hey Narue!

Why can't I have groupies? I'm sure she'll be thrilled with the shout-out.

Anyway... look at line 36 in relation to your while loop. Walk yourself through a cycle or two of the loop, noting when the file gets closed.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

When you don't use braces to delineate your if/else groupings only the statement immediately after the if or else gets executed:

if(condition)
   This would get executed when condition was true
A statement here would cause an error when an else is present
else
   This would get executed if condition is false
   {
       The stuff in these braces would be executed if the condition was false because it is with 
        the "This would get executed" statement 3 lines before
   }
This statement would be totally on its own, not part of the if or the else

So now you see why your output on line 13 was executing regardless.

I don't have a good text recommendation for you. I used to like Kelley/Pohl "A Book on C" but it's getting a little outdated and might be a bit too dense for folks just starting out. Their book "C By Dissection" (meant for beginners) is not very effective IMO.

I'll chide you one more time about the formatting too. Read the article WaltP linked in Post #3 (it's written by some guy WaltP at another site, probably just a coincidence). It's definitely hard to match your braces up and what goes with what when everything is crammed up against the left hand side like that. If it's easier to read it's easier to help you.

Xufyan commented: great - xufyan +1
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

The whole idea of the overloaded operator is you can now say something like if(Rational1 < Rational2) and it makes sense to the compiler because it has an overloaded operator to tell it how to perform the operation.

However, you have to implement it in your source file like you did on lines 90 to 98 above. Tetron's method of having one parameter member functions would work too but you seem to be more comfortable this way. You can then borrow the formula that you have posted on your latest post in red and so in that case

bool operator <(Rational &Fraction1, Rational &Fraction2)
{
	return ((Fraction1.numerator1 * Fraction2.denominator2) < (Fraction1.denominator2 * Fraction2.numerator2));
}

since we want a true or false value and the ordinary use of the < gives us true if the numerator-denominator products have this relationship. Therefore, reducing the problem to comparing integers (which is something the compiler knows how to do) helps us to compare the objects. Also, hint, the > operator can make use of this method.

On a peripheral note, your tests function above is meaningless as you have set it up. Mathematically a rational number is any that can be expressed as the ratio of 2 integers, with the denominator not equal to 0.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

It's not going to reach 5 either. The best way to do it would be to flesh out the for loop with the proper conditions (so say i=0;i<10;i++ ) and make the number of times it goes it independent of x. Either that or turn it into a while loop which breaks on some condition.

tux4life commented: Yes, that would indeed be a better idea :) +8
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

the [] only work if string is defined

Yep, just came to the same conclusion.

I think what you meant Tetron was to substitute output +=alpha[r] for the output[r] = alpha[t] .

Another option would be to dynamically allocate a char array but that wouldn't be able to take into account repeats in the letters of key.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

no i diddnt put getch(). What does that do?

Unfortunately getch is part of a nonstandard library for console input. A portable solution would be to put cin.get() in the same spot.

iam using visual c++ 6.0 on windows 7 64bit. so could it be compatability issues thats causing it to crash?

This is not outside the realm of possibilities. Try downloading the 2008 express edition as VC6 is almost 12 years old.

thanks for the reply jonsca but i forgot to mention that i need to do other things with the array afterwards. i was just outputting it in this instance for testing purposes

Gotcha. I'll try running your code and see what the outcome is.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You're still missing out on how the objects should be used. Your object contains a numerator and denominator and a way to print itself. Therefore you should have

Rational myrationalnumber;
myrationalnumber.setNumerator(2);
myrationalnumber.setDenominator(5);
myrationalnumber.showfraction();

which would print out 2/5
Then you can make another object for the second rational number.

Your class defines what the object has for members and how it behaves. Each object carries around its own numerator and its denominator. It knows how to print itself, therefore you don't need to pass it anything to print as it has access to its own member variables.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

when they're not home, because I'd get in trouble

Yet another latchkey kid gone terribly wrong. At least you've learned to write quality code in the process. To "bolster" my claim of you being older I wanted to find the poster who accused you of being middle-aged and bitter but I can't locate the post. Argh.

Dani is Al Gore

As long as "she" (Al) doesn't (mis)use the term "Information Superhighway" everything will be ok. She seems to have more personality in the tip of her pinkie than he does in toto. Well played in throwing us off the track, Al.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

That seems reasonable, but what if the buffer is 20 characters and the user only enters 4 and hits enter?

WaltP commented: Are you being silly, or are you having a brain fart? ;o) +11
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

IMO, you could have a system where posts on threads over 3 months old require moderator permission. It's more work in the short term but having to take the time to approve 5 threads rather than having to close 20 for the usual spam,"I have a totally unrelated problem but this thread looked good or had a lot of posts on it" etc. it would end up saving time. Sure it takes a little bit of control out of the hands of the community but if that's the chief complaint then why have moderators in the first place?

jephthah commented: word +0
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Think of P0 as a point on your shoulder, L0 to be the length of your upper arm, and L1 to be the length of your forearm. Now, put your finger at an imaginary point in space (don't allow your wrist to rotate). That's P1. Now if you have P1 and P0 you can use something like http://en.wikipedia.org/wiki/Law_of_cosines you can get everything as a function of the angles (since you know the distance from P0 to P1 too and you can assume your upper arm can rotate at the shoulder). I don't think your professor is looking for an exact answer but something in terms of the unknown quantities.

Anyway, hope that gives you some hint without ruining all of your fun.

Salem commented: Very nice analogy! +19
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You missed the obvious option, jwenting. Open the skull, put black ink over the cortex, stamp it on a sheet of paper. Voila, brain fingerprinting.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Check line 13 (and line 17 for good measure). One has something it doesn't need and the other needs something.

mitrmkar commented: line 13 == good catch +5
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

There are potentially a few issues here.

If the document is up and running in word it may be locked as far as the file system is concerned (I have not tested this).

If you are trying to read from a Word document in text mode (as in from a .doc file from a recent Word release) instead it needs to be a binary read/write (unless you are doing word 2007, in which case it's in XML).

If you are simply trying process between (plain) text files leave them closed and let your program do the opening, closing, and creating of the new file.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

inFile.open(filename.c_str()); will open up the file using the filename (that c_str() method provides the C string representation)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

There are no conditions on an else statement. You could have an else if with conditions but I don't think that's what you need here.