jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Well, you want to open it using ifstream, but since your compiler is pre-standard it may not have that method of the class (I seem to remember this from another poster at one point).

What will probably work (and is also used) is to test that the ifstream object is not null:

ifstream ifs("myfile.txt");
if(!ifs)
   //file didn't open for whatever reason
anu07 commented: worked :) +0
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

free(y); ?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Mixing cin and getline like you do can cause problems. Since you press enter after entering in userInputString and cin does not take up that resulting '\n', it stays in the stream and gets taken up by the getline (and interpreted as the end of the input, so control appears to "skip" over it).

See the sticky thread in this forum about flushing the input stream for more details. However, in this case, with one stray '\n' it is probably sufficient to put a cin.ignore(); before your getline statement.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

If something is unclear you are welcome to ask.

Yes, why do you keep giving complete, compilable, cookie cutter solutions that the OP can simply turn in for a grade even thought you have been asked more than repeatedly not to do this?

jon.kiparsky commented: Keep hammering on this, it's worth the effort. +2
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I hate to tell you this, but you're going to have to narrow the code down dramatically and present questions about specific sections because someone is not going to go through and check all those steps for you.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

No, cout can handle C-strings okay. Hmm, when I compiled and ran it, it had no problem (though I didn't try it in Visual C++). What parameters are you giving your executable, and are you putting them in at the command line directly or via the arguments option in VC++?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

So that 'AC' becomes (('A' - 'A' + 1) * 10) + ('C' - 'A' + 1) which is 10 + 3 = 13

Except that AC is actually 29 (after Z comes AA, AB, AC, etc.), so for AA to be 27, A has to be 1 (you'd have to shift everything down by 1 to get a zero based index).

One way to make your life a little easier is to turn on the "R1C1 reference style" (I have it under Excel Options/Formulas/Working with Formulas in Excel 2007. This will give you a (1-based) column designation for each cell.

Ancient Dragon commented: I knew that, I was just testing you :) +36
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

This is a good thread on SO about it: http://stackoverflow.com/questions/628526/is-short-circuiting-boolean-operators-mandated-in-c-c-and-evaluation-order

Both are short circuiting, so since your first operand of || was true, it skipped the foo() call in the first example.

VernonDozier commented: Good link. +13
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

On line 1 of your second code listing of the first post, you still need the datatypes for str and level in the constructor definition

dragon::dragon(string str,int level) {
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

It's getting a bit outdated, but this one http://www.functionx.com/vccli/index.htm has everything together in one place.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Unfortunately, it's a pain (but not impossible by any stretch) to retrofit a complete piece of code to a GUI.

How comfortable are you with the GUI toolkit already? (like have you made a "Hello, GUI" with buttons or are you able to display a text file in a textbox? Those are the kinds of fundamentals that you'll need to get up to speed on first before trying to figure out where to place your existing code. With those ideas in place, you should start to see how things can be parceled up.

Since most GUI libraries are OOP based, in my opinion it is slightly easier to use objects with them. IIRC, your code that you were writing was more procedural, so I don't know how viable an option it is to do that.

Try it out, and see what specific problems you run into.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You need to designate that getData is a method of EmployeeDataList, since it's not defined within the class declaration.

void [B]EmployeeDataList::[/B]getData(fstream& dataFile)

Then you still need to declare "next" as a member variable of EmployeeDataList to avoid the second error.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Both numbers are on the same line, so you only need one fgets call, I think. Then you can get the digits from the string or use sscanf (but that's probably overkill).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Use gcc for the compiler, use whatever editor (Emacs or vim) for the editor. Anjuta looks good but it's unnecessary.

http://www.dosbox.com/download.php?main=1
The designers seem to think it's cross-platform.
Look before you leap.

Windows	 0.74	 Win32 installer
[B]FreeBSD package	 0.74	 TBZ
Fedora	 0.74	 rpm
Gentoo Linux	 0.74	 portage
Source	 0.74	 Source [/B]
Mac OS X	 0.74	 dmg (Universal)
RISC OS	 0.74	 zip
Solaris 10 - sparc	 0.73	 pkg
OS/2	 0.72	 exe (OS2)
BeOS	 0.63	 binary (x86)
Old dosbox versions	 0.50-0.73	 source + binary(x86)
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Okay, so I'm asking you why you need the quotes on the string constant "Please enter the starting balance" and not on the string constant "credit." It's the same idea. You need them both. credit is a variable named credit, "credit" is a string constant equal to the word credit. You want to compare xact_type to "credit", not to credit.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You've got xact_type where it's supposed to be now, he was saying take it out of the variables you were declaring as floats. That's all squared away.

You're getting closer, but how do you write a string constant -->> " "
you didn't write

cout <<Please enter the starting balance;

so why would you write

xact_type == credit
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Contact the company. If they are willing to release the code to you, they will. As it is, no one is going to help you disassemble someone's proprietary DLL.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You need to show some effort before anyone is going to help you. Copying/Pasting the assignment into the box is not sufficient. Can you create the skeleton for the program? can you declare the arrays? Do you know how to define a function? Give it a try and post back.

Nick Evan commented: Yep, no homework freebies here +16
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You have redeclared "smallest" and "largest" as ints in main(). There's no need to do that.

slygoth commented: thanks man this really help +0
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I took a course in Systems Analysis and Design eons ago and was taught something like the following: http://en.wikipedia.org/wiki/Systems_Development_Life_Cycle. I'm not a practitioner, so I don't know what people actually do, but that method of analysis abstracts it a bit from compilation and testing cycles, so it may not be exactly what you want.

AndreRet commented: Payback for the other reps, thanks. +6
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

i have a hard time believe that theres no way to clear a terminal screen

That's not what we've been saying. There is no standard way to do it that is portable across all platforms. If you don't want to listen to my advice or to WaltP (who's been doing this kind of thing for a couple of years now), there are plenty of other people who will tell you the same thing.

try to make everything encapsulate inside main();

Leave your functions (addition, subtraction, etc.) as they are, though. Don't try to jam those into main.

WaltP commented: Couple of years? Hmmmm... :o) +15
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I've only skimmed through it in the past, but check out http://www.freetechbooks.com/object-oriented-programming-with-ansi-c-t551.html (free and legal download). It does a lot of preprocessing on the code.

Something you might be interested in, as I think it's at least peripherally related is the cfront system that converted C++ to C (see http://en.wikipedia.org/wiki/Cfront) for compilation in the early years of C++.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

It doesn't run for the first turn through. In general, if the condition on a for loop evaluates to false to begin with, the loop is skipped.

In this case, after the for is skipped, x is incremented to 1, the next cycle of the while loop takes place, and that's when you see the '+' signs start printing.

Edit: beaten to the punch on that one

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I recently was using the BinarySearch method and I was curious about why the designers had coded the method with the following for a return value:

"Return Value

The zero-based index of item in the sorted List, if item is found; otherwise, a negative number that is the bitwise complement of the index of the next element that is larger than item or, if there is no larger element, the bitwise complement of Count."

(from http://msdn.microsoft.com/en-us/library/w4e7fxsh(v=vs.80).aspx)

I'm not concerned with the magnitude of the return value in my application, just whether it's positive or negative, but why did they not just design it to return the negative of the index of the next element or the negative of Count?

Thanks.

ddanbe commented: Good observation! +8
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Have a look at this http://www.daniweb.com/forums/post155265-18.html. It tells you how to avoid that situation.

ravenous commented: Link to excellent post, which has excellent links itself! +6
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Consider a smaller example:

1000 0000   //0x80 as a mask

Take the number:
0100 0110   //70 decimal  & it with
1000 0000  = 0000 0000, first digit is 0

<shift bit of mask to the right>
0100 0000 & it with
0100 0110 = 0100 0000 => second digit is 1

<shift bit of the mask to the right>
0010 0000 & with the original number

etc.

So, you're using & to test the bits one by one to see if the given number's bits are 1 or not. If they are 1, the and of the bit in the original number with the mask is 1.

The mask allows us to focus on the bits one at a time.

wildplace commented: explain well, thanks =] +2
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You have to add it to the tabPage of the tabControl directly. I hid the PB until I repositioned it to where it belongs. Other than that, what I replied with before should do the trick.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Declare a picture box, set it's coordinates and background image (and the background image layout). Once that's all done, use the .Add() method of the tab control to place it on the form (I think the default is visible, so you don't have to set that before adding it). See if that works, otherwise I'll put together an example to refresh my memory.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

It wouldn't change much of your code at all to put in the do/while loop

do {
/*all of your code from 8 to 22 */
} while(choice == 'y' || choice == 'Y');

then eliminate 23-25.

Calling main like you did is technically recursion. It's not forbidden, but be aware that each time main() would be called from itself, the "state" of each call to main would be conserved on the stack as another instance of it was called. Those representations (address/instruction to return to, and I think local variables, but I'm not sure) could pile up ad infinitum or potentially until it crashed your program.

Looking something like (but don't quote me on the specifics -- take a look at http://en.wikipedia.org/wiki/Call_stack for a good overall explanation):

[n-th call to main()]
   .... 
[3rd call to main()]
[2nd call to main()]
[1st call to main()]

I read up a bit on it, and it seems how you had it set up was a "tail" recursion, which the compiler can optimize away if possible. Doubtless someone knows whether or not this type of thing is allowable under the different standards (C89. C99, etc.), but I wasn't able to find any clear cut statement on that. I do know it's non-standard in C++, but that has no bearing on C per se.

The bottom line is that a simple do/while avoids all of this potential headache. I am not sure about your book's statement about …

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I'm not sure if this configuration is dictated by your assignment, but, in my opinion, I think your circle class should have a point member ("composition") instead of deriving from the point class. What you are seeking is more of "has-a" relationship ("a circle has a point(center)") instead of an "is-a" relationship ("a circle is a point"-doesn't really fit). I realize the is-a/has-a suffers from some limitations, so that's why I'm presenting it as an opinion.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Please use code tags [code] /*code goes here*/ [/code]

You shouldn't call main() like that, but the real problem is the semicolon at the end of your if statement if (choice=='y' etc) . If the if statement is true, the then "statement" is ; and then the program continues with the next line.

Read a little ahead in your book to the do/while statement section and replace your call to main() with that.

One final thing, when dividing 2 integers you're going to lose the decimal information. Also, try putting in a fraction like 5/7 and see what happens.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

That's the beauty of it, it will be your word processor, so it can have any functionality that you want. Start off with just a rich text box, which will give you a lot of the editing functions built right in (or start with a plain textbox and add in the functionality). Make an edit menu so you can cut and paste. Learn to read and write files so you can save the user's work (see System::IO::StreamReader and StreamWriter for that purpose, at least initially).

Spell check the way Microsoft does it will be a bit trickier. You'll have to parse what the user is typing and compare it against a dictionary. A spell checker that does it all in one pass is probably easier to implement.

Do you have enough experience with WinForms already that you know how to use the IDE to generate event handlers and such? If not, go back to a basic tutorial before you take on a large project like this. See, for example, functionx.com/vcnet/index.htm

kvprajapati commented: :) Indeed. +12
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

The +/- accounts for there being 2 points of incidence if the value of the discriminant is greater than 0. If the discriminant is 0, there is one point of incidence (the first part +/- 0 gives the same point). If the discriminant is negative, there are imaginary roots and so no intersection on the real plane. It's the cases outlined in the diagram at the top of the page.

So, if the discriminant is greater than zero, you need to have one calculation for [x = Ddy + (signum) * the discriminant, y = -Ddx + the discriminant as one point] and [x = Ddy -(signum) * the discriminant,y = -Ddx - the discriminant] as the second point.

Hope that makes it more clear, if not post back. Just think of it as the solution of a set of quadratic equations and maybe it will click for you.

Valaraukar commented: Clear and concise. Very helpful! +2
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Try using Int32.TryParse instead:

string str = "42"; //your string
int numb; //the number output from the method
if(!Int32.TryParse(str,out numb))
{
  //it failed
}
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Hi jonsca: Thanks for helping me with the problem. Do you think is the destructor definition the problem here?
Danni

I did not trying running your program, but the vtable error is eliminated. See http://stackoverflow.com/questions/4351077/how-when-do-i-use-a-virtual-destructor for corroboration that the change I proposed is necessary.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I don't do anything with GUIs or CLI, but I noticed you are using the compound addition operator to attach the EventHandlers. Maybe I'm missing something, but shouldn't that be the regular assignment operator, not a compound operator?

The compound operator is used there because it is possible to hook up more than one event handler to a single event.

Fbody commented: I understand now. Thanks. +5
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Recently, I am doing my thesis project

I'm sure your supervising professor said, just throw it up on the web and turn in whatever comes back...

For someone to begin to help you with this, you need to bring your existing code to the table. No one is going to write this for you.

Ancient Dragon commented: yes +35
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

main() is prototyped to return an int, but returns nothing.

Actually, that's ok according to the standard. A return of 0 is implied if none is specified.

Clinton Portis commented: learn = good +6
kernel>panic commented: Yes, agreed. +0
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

That's one of those questions that definitely depends on the project you are working on, etc. To me, if you know one of Java, C, or C++ you shouldn't have any problem learning the others and switching between them, but again that's just my opinion. I don't know much about Python, but it too is widely used and those that use it seem to enjoy it.

kvprajapati commented: :) cool! and nice avatar too. +12
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

The semicolons on lines 13 and 22 don't belong there. If you put them there, the if statement will execute the statement with which you intended it to be associated regardless of the condition.

if(lotterynumbers == "123456");   // <--- the ; is associated with the if
    NotifyUserOfWin();    //just a plain ol' statement, lotterynumbers could be "7"
                          //which makes the if statement false, but it gets executed anyway
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Great going, and thanks for posting what you found for others. :)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Yes there is. It's a class, not a namespace, so you have to qualify the calls to the static methods with Math, e.g., Math.abs() or whatever.

vedro-compota commented: +++++++ +1
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Test it and see if it works, but yes, that looks correct.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Line 23 should be openagain >> k; but see http://www.daniweb.com/forums/post155265-18.html about using .eof()

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

It is also incredible how you manage to write 4000 lines of code and have a problem like this. Did you not test your program as you went along?

Agreed. Also, as I suggested with your other difficulty, make a "toy" program that contains only the 2 textboxes and see if you can reproduce the problem that way.

Programming all of these magic numbers into your code is also going to spell disaster if you need to change anything. See if there is another way to approach your problems (e.g., storing some of your constants that vary with other values in parallel arrays or in a list). As it is, it's going to be difficult to maintain.

You may also want to hold off until you know some information about classes and use them to consolidate your code.

kvprajapati commented: N/A +11
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

How are you getting your code from Vim to the IDE? (in other words are you opening a project for it..or?) If you're writing in Vim, you could just possibly skip the IDE and compile right from the command line.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Either read it in as a string and access the digits as characters, or get the remainders after division by 10, subtract remainder, division by 100, etc.

Please post your attempt and someone will look it over.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You want something along these lines

int tb1value;
Int32::TryParse(textBox1->Text,tb1value); //enclose this in an if to make your own error handling
int tb2value = tb1value+comboBox1->SelectedIndex+12; 
//it doesn't matter what's in the box, just use the offset
textBox2->Text = tb2value.ToString();
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Double check it, but I think it amounts to an integer division (clock_t is usually a long int and I think the constant is an integer value). Cast one or both to float.

EDIT: Edged out by the Code Goddess :)

Clinton Portis commented: muy bien +6
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

There's nothing wrong with your codes. What's wrong with "Go To"?

Nothing, if it's used very judiciously, but it's awfully easy for it to make source code into a mess of spaghetti that's difficult to follow. Code readability is important.

jember commented: Thank you :) +1