jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

jonsca,
thanks for that. I had a read at the tutorial, not sure if I understand it correctly though especially when it comes down to distinguish between fixed and default...

From that same site fixed means that: "the value is represented with exactly as many digits in the fraction part as specified by the precision field and with no exponent part." (presumably meaning that the implementation will find the closest floating point number that carries that value to a certain number of digits, and will not use scientific notation)
vs.
Floating point is a way to increase precision at the expense of the size of the number and vice versa. That is the default for cout.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You need to use the functions in iomanip. The decimals are there, they are just not being displayed.

So, #include <iomanip> and see http://www.cplusplus.com/reference/iostream/manipulators/setprecision/ . You'll have to set the fixed setting first like they do in the example.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

In the constructor you need to allocate memory for the array vector = new float[x];

Where have you done this step that AD indicated?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You want to include <cstring> (which is the old string.h from C that has strcpy, etc) instead of <string>. As you have it now, you are including <string> which has a class named std::string, which is probably causing a name collision.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Sorry, perhaps I wasn't clear, my fault. Move them out of the for loop and into the main body of the ValidPassword() function.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Take 62 to 73 out of the loop so they won't display for each character you are checking.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

See if using this->Hide() on line 5 gives you the effect that you want. Your first dialog will still be in memory. Unless your dialog has lots of controls on it, this shouldn't be a problem.

I think this has something to do with the fact that the second dialog is an object in the first dialog, so killing the first dialog (I think, it's logical) calls first's destructor which gets rid of the second dialog. I was getting the behavior that they both stay open, so there may be measures against this that are happening behind the scenes.

If this does not answer your question, see what AD can come up with, and if it still doesn't work try it over in C# (specify that you have asked it in C++ already). A slightly different syntax would be involved, but the same overall method that someone suggests should work.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

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

In your GetString() function, add a cin.ignore() after the cin.get. There's probably a stray '\n' in the stream which gets picked up by the cin call in the GetNumber() function.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

A simple

string surname;
string firsname = record1.takerecord(surname);
cout<<"record1="<<firstname<<" "<<surname<<etc.

There's no need to keep calling the method. I honestly can't remember if the order of execution of the "<<" is guaranteed to go left to right from implementation to implementation, which is why I didn't put it all on one line.

You could also modify your method to keep things less confusing.

void takerecord(string & name, string & surname)
{
    name = name1;
    surname = surname1;
}

Which avoids having to know which is returned and which is passed by reference.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

In celebration, I'm going to pour myself a tall glass of "who the hell cares." :D

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You can't return more than one value. Pass in your second variable by reference: string takerecord(string & surname) { //set surname equal to surname1 and return name1 }

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Can you post a couple of lines of your data file? Your code resembles C more than C++ (other than the fact that you included iostream).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Well, that's fine too. I was trying to point out it was a misspelling of the variable name (spelling counts, ya know).

Hint: at this stage of the game, put in a few lines of code, compile them with no errors. Add in a few more lines. Compile again. That way you'll be able to keep track of exactly which line messed things up.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Yes, I see what you are saying... How about if you put it within the p for loop, but only set maxDefect[p] = dayDefect[p] if it's the first p in the loop.

Set variance initially to maxDefect[1] - minDefect[1] (if it's the first part again, so you can include this one in your if statement from the first issue above) and use something similar to lines 32 through 35. Don't call the variable on line 36 minVar, call it something like Var and find the minimum of the Var values.

bool myFlag = false; //just a boolean value (true or false) in this case the 
//flag is unset, just expressions from old(er) folks

if (selection < 2)
{
   //Run your menu item 1
   myFlag = true;  //set the flag
}
else if(myFlag) //meaning myFlag == true, since it's already boolean
{
  switch(selection)
  {
      case 2: //etc. etc.

   }
}

You get the idea. I'm sure someone is bound to point out a fancier way of doing it, but trace it through by hand to see that if the flag's not set and the menu selection is something else, it will pass right through the if statements and you can loop around again.

Hopefully that leaves you some fun on your own.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Compare lines 17 and 25: Look carefully at your variable name.

Also, look at line 20: Can you assign an input value to an endl?

On line 25, see what happens when you remove the ==true

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

If it's not working to set the initial value inside of your for loop, try it before the for loop. That way it will be assigned for each iteration of the days and not reassigned for each product.

What is the formula you are supposed to use for minVar? I would suspect you would find the mean number of defects and the minimum variance would be the one with the least value for number of errors - mean.

Set a flag (bool value) between your first case statement and the break so it's true once you've run that method. Put an if statement around your switch statement that will only let a selection greater than 1 go through if that flag has been set.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You're missing a couple of () but yeah that's the general idea.

To consolidate it further:

if(myStudents[counter] == userChoice) //statement in parens evaluates to true or false
{
     cout<<"Yes,"<<endl;  //etc.
}
else
{
     cout<<"No,"<<endl //etc.
}

Someone is bound to point out that you don't need the braces, but it helps to put them in initially to tell where everything belongs.

So, look at the statement that I made and trace it though to see why it's equivalent to your statements (with a lot less code). Hint, saying anything == true is redundant.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Please use [code] //code goes here [/code] (code tags) to maintain the formatting of your code when you post it.

What are the errors that you are getting?

Try to consolidate your code inside your for loop down to just a couple of lines. Hint: myStudents[counter] == "Andy" resolves to either true or false.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I think you're on the right track with setting minDefect[p] equal to the first dayDefect[p] value, and do the same with the maxDefect[p]. If you were keeping track of this information on paper, you'd write down the dayDefect value for each of the 9 parts, so then your min and max for each of the parts would be equal to that part's dayDefect[p]. New day, new dayDefect[p] values which if they are greater than the old maximum, they are the new maximum, and if they are less than the old minimum they are the new minimum.

Hopefully that's clearer than it seems to be to me hehe.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Yeah, sorry I couldn't be of more help. If you are using C::B, you really don't need the text UI as the IDE has built in support for gdb...

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

That's the right way to do it with the if/else. Now all paths through that method will return a value.

In doing it the way you did, as long as your calling function could tell the difference between the error condition and the actual value requested as [0][0], but I'm not sure how you could do that without adding an extra parameter. I'm not sure what the best return value would be for the error. That'll be up to your design.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Evidently there's a configuration option that needs to be set (see http://davis.lbl.gov/Manuals/GDB/gdb_21.html at the top of the page)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

On line 34, why do you have your else within the braces of your if?

What the compiler is telling you is that there is a path through that method (the path taken if x >= rows || y >= cols || x < 0 || y < 0 is false) where there will be no value returned.

You'll need to rearrange that if/else structure, but also provide a return value to the calling method in the case that the dimensions are not correct.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Call srand((unsigned)time(0)) only once before your first call to rand() . This seeds the random number generator with the current time.
You'll need to include ctime (formerly time.h) for this.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Just type [code] at the beginning of your code and [/code] at the end :)

Yes, post back on this thread with any problems related to this assignment, start a new thread if it's pertaining to something else.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Please use the [code] //code here [/code] tags, that way all of the formatting is preserved.

Why are you using p as your index for totalDefect? You probably meant d.

Also, how do you know the array you are passing in will have trackDays spots? If it has less than that your program will crash.

Relatedly, when you have a for loop going from 0 to trackDays (inclusive), you're going to have trackDays+1 elements.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Post the relevant portion first and then we can see if we need more information.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

See http://www.codeproject.com/Messages/3198006/Communicating-with-main-GUI-thread-from-worker-thr.aspx you can't write directly to the GUI thread as that could lock up your main application.

You cannot use an ofstream object. Any unmanaged types have to be transferred in between the unmanaged and managed parts through marshaling. Use a StreamWriter (http://msdn.microsoft.com/en-us/library/system.io.streamwriter.aspx) but as it says in the documentation, it is not thread-safe. There is a Textwriter::Synchronized available, but I've never used it.

cwarn23 commented: Thanks for the hand. +6
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

All of those are unmanaged pointers which are not going to work in the CLR, unfortunately.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Poke around C# sites that cover BackgroundWorker too. The only issue is translating the syntax (. being both :: and -> at times). The forum here will probably have some examples too.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I'm not 100% certain myself. There may be issues of having to marshal copy the map values (as they are an unmanaged type and not compatible with the managed code).

As far as how to pass parameters, I'm assuming that for example on the line: e->Result = ComputeFibonacci( safe_cast<Int32>(e->Argument), worker, e ); e->Argument would have to be some kind of data structure or ref class containing all of your parameters (see http://www.codeproject.com/Messages/2369118/Re-Custom-DoWorkEventArgs.aspx for a posting on custom event args), but again, I don't think that will work with the std::map. I wish I had more help to give you, but hopefully this gives you some more terms to search on.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

@AD Since his application is on the CLR, it's probably easier to incorporate all of this as a BackgroundWorker class.

@OP Check out http://msdn.microsoft.com/en-us/library/system.componentmodel.backgroundworker.aspx and scroll about halfway down to "Examples" and make sure you have the C++ tab selected. It's not identical to what you are doing but you should be able to adapt it readily. I did not find a lot of information on C++/CLI threading out there, but if you look up the concept of delegates for C# you can adopt some of the information by changing the syntax (as it's all .NET under the hood).

(the code box starts out below the second screenshot, the one above that has nothing in it)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Yes, it's the same. Structs and classes in C++ only differ by the default visibility of their elements (public for structs and private for classes).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Seems to me your line class should contain the start and end points for a line. Then pass in a point to your "distance" method in Calculating. Seem like you might want a Point class too, perhaps...

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

It's probably in the same location as the .exe file. Either go to the directory into which you started the project or use Window's search utility to find it (you may have to expand the search area to include more than your documents, etc.).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Can you post your code with those if statements in there?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Hand trace through the do/while loop with different conditions and you'll see that even if gender was equal to one, it would not be equal to 2 and vice versa, therefore your loop condition is true and the loop continues.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Hint: what if your name input is not matched by the first line of the file? If they don't match keep going, reading in lines until it does. You need another loop.

Using "out" as the name of your input file might be confusing to someone (or you!)trying to read your program later.

Also, what happens if the file is not found or went bad?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

When you give cin a bad input for "value" (e.g., 't' in your example), the stream goes "bad" and you need to issue a cin.clear(); after line 32 to reset it.

See http://www.cplusplus.com/reference/iostream/ios/clear/ (the example is for a file stream, but it's the same idea)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Hint: Write the bar graph out line by line. Draw out a sample by hand and see which values have stars printed on which lines. After you've figured it out using cout, send the output to your ofstream object instead. Give it a try and see how far you can get.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Have a look at something like this:
http://msdn.microsoft.com/en-us/library/1b4az623.aspx

This is one of those unfortunate cases where the unmanaged and the managed data types cannot be interchanged, you need to marshal the string.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Depending on what system you are using textboxes can be read only or read/write. What are you trying to write this in (Win32 API, MFC, Winforms)?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

The best method (though I don't have any advice on it) is using a background worker: http://msdn.microsoft.com/en-us/library/system.componentmodel.backgroundworker.aspx

yoni0505 commented: thanks +1
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Under the Project menu: choose <projectname> Properties. Go to Configuration Properties. Under Linker/General: fill in the Additional Library Directories and under Linker/Input: fill in the Additional Dependencies with the .lib names

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

It's relatively easy:

#include <sstream>
//...
int numbervariable = 10; //or double, etc. or use your loop counter
std::stringstream ss;
ss<<"Firstpart"<<numbervariable<<"Secondpart"; //use it just like any other stream

std::cout<<ss.str()<<" is the string portion";
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Check out this thread.
http://www.cplusplus.com/forum/general/3570/page1.html#msg15410

Basically you're stuck with platform dependent (non-portable) solutions. Using a library like ncurses(on *nix) or pdcurses (http://pdcurses.sourceforge.net) would give a slightly more portable solution.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Mixing getline and cin can lead to this problem (I thought you meant you compiled the example on the cplusplus.com site and it gave you trouble).

Put in a cin.ignore(); before the getline. There is an extra '\n' left in the stream after the prior cin that the getline() then reads in and then terminates thinking it's the end of the input.

When posting code please use code tags [code] //code here [/code]

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I already had tried this sourcecode from "]http://www.cplusplus.com/reference/string/getline/" and it doesn't work. When I execute his sourcecode it just go through without askin' 'bout requestin' for data input. You can read "thank you, " but no data contain in the string variable str.

Post the exact code that you used.

Sorry for my scriptural English. If you have char or cha a [8] with this value "aaa aa a". How should i do to convert it into string included with white space?

No big deal. You can use the constructor for string that takes in a const char *

char str[] = "hello";
string stdstr(str);
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

use the getline function to get input with a space http://www.cplusplus.com/reference/string/getline/

What do you mean by "in the char it also contains white space"? What are you trying to accomplish?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

This is an ideal situation which which to use stringstreams. Are you locked into using the characters array?

Also, itoa is non-standard so it's not guaranteed to be available on all compilers.