jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

This is all happening from the output that's generated in lines 61-70? Ok, I was able to reproduce it. If that's not where it is we can look at some other areas.

I don't think it's related but you can eliminate the use of infile.eof() as your loop condition -- as using that can go one past the end of the list because of the way that method is designed.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Can you put up your current code. Also, specify where you are getting the random symbols.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Yes, except that's going to fill in a different order than 0,0,0 -> 0,0,1-> 0,0,2->... since the middle index will progress first. If you're going to have to read the file ( you wrote out) back into the program at a later time you'll want to keep a consistent format. That way your reading and writing loops will be similar to each other.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I changed the header file name?

Yeah, sorry about that one it was an assumption on my part that was false.

How are you compiling these two files? Did you try what I suggested in the other post, to compile the file from lines 1-54 before the main file?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

well i have changed them to cabin[3][4][13] now. should i change the for loop and get rid of the minus 1 to lvl, row, col and plus 1 parts lvl, row, col?

No, don't change the -1 for any of the dimensions, as you still need that since you are going from [0][0][0] to [2][3][12] over the range of the indexes.

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

Apologies. I don't know why I was under that impression. Tried it out and as usual Mr. P is right.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Actually that may be a big part of your problem. Are you overrunning the array when you try to write it out? I'm not convinced you're reading it in as you want to either...

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

A quick point before anything else

there are 3 levels in the cruise ship, with 4 colunms and 13 rows. that is where the 3d array comes in "cabin[2][3][12]".

is incorrect. If you had a cruiseship of those dimensions the indexes of your array would go from cabin[0][0][0] to cabin[2][3][12] but your array must be declared

char cabin[3][4][13];
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You need dynamic_cast. For example

(dynamic_cast<Class1*>(b))->GetValue()

will get you the value of 1 in your code.
Use the dynamic_cast to convert your Base * object to a Class1* type (essentially you're just moving down the class hierarchy hence you used dynamic_cast and "downcast" the object) and now that you have a full-fledged Class1 object you can access the GetValue() method. Same holds for the other Base * object except cast it to Class2*.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Yes, that was exactly what I needed. One more thing, how would I change the input method in a way that would allow me to use an unlimited amount of characters without underscores? I realized that you would need to change the declaration of the intial variable from the char charName[50] to string charName and probably the cin.getline(charName, 50) to getline(cin, charName). but would you need anything else to make sure there aren't any errors?

The way you described should work just fine. You'll still need the cin.ignore before the getline(cin,charName) statement.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

How are you getting the input for the variable "input"? If it's a cin >> as I suspect it is, now you would need the cin.ignore() after that cin statement or before the cin.getline on line 29. You can use that variant of ignore() you had before but since it's probably 1 newline gunking up the works the cin.ignore() with no arguments will probably suffice.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Can you show an example data file? I think if you know all the dimensions ahead of time you could just use a for loop to read in the data and make things slightly easier on yourself.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Line 99: There's an issue with case sensitivity here. In one file you include the header as "Point.h" and in main you include it as "point.h". If that's not the case make sure that your class cpp is getting compiled before your main cpp.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

It's initializing a character array of length 1 with the null character.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Replacing line 29 with cin.getline(charName,50); would be the best way to go.
The cin.ignore helps in the situation where there are newlines ('\n', resulting from pressing enter after your input) left in the input stream.
Since you would have the cin.getline statement first and then the cin >> there won't be a problem with an excess newline being left in the input stream since cin.getline reads in and disposes of the new line character (versus having the cin >>statement first which can leave an extra '\n' in the stream to get picked up by a subsequent getline thereby ending the getline before it starts).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Make sure you have a copy of it in the debug directory associated with your project (I assume you are using Visual C++ based on your error message above).
So you'll have a directory called "ProjectName" (fill in your own project name) wherever you saved it. Put the dat file in ProjectName\Debug.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

First, you need to learn how to format your code. Good that you got the code tags but what you have looks terrible and is hard to follow. Give this article a read: http://www.gidnetwork.com/b-38.html

Secondly, your switch syntax is completely wrong, you need colons after the cases not semicolons:

switch(sum)
{
     case 7:  //code for case 7
                 break;
     case 11: //code for case 11
                  break;
     
    // (etc.)
}
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Unfortunately, I don't have a system to test this out on. It's probably best to see how well the array arr was passed to the nodes. I regret it's been a while since I have done MPI but I remember the BCast being fussy.
It does take a void* but it still asks for the total number of elements and you have only provided it with N for a count. Either try giving it the count of M*N or try the whole thing as a 1D array with MxN elements (that will change your loops around). See if any of that helps. I've tried to do some searches as to passing a 2D array via BCast but didn't turn up anything worth noting. Wish I had more info for you.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

On line 32 you're using rand but you haven't seeded it. Include <time.h> and put a srand((unsigned)time(0)); before line 32 and also give a maximum value for rand by modding it with a maximum(so rand() % 10 +1 will give you random number from 1 to 10. I'm not sure that will solve the problem but it should give you a better idea as to where the negative values are coming from.

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

Well, the reason you get the error is that what you have is not the proper syntax for a "for" loop. I was just suggesting declaring them in the body of the for loop but you are correct they won't persist if you do that.

I perhaps misunderstood what you needed, for that I apologize. However, I'm confused as to why you read in all of the y values with a constant x and only vary x once you've reached 155 on the y. Rather than the x++ and y++ in post #2 you could probably use x+=3 and y+=3 to skip the proper lines.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

A better way (though not the only way) to write it would be with a nested for loop:

for (int x = 0;x<=384;x++)
{
    for (int y = 0;y<155;y++)
    {
//this way you wouldn't need the int x=0 and int y=0 at the top

because even if you were to use the two conditions in one loop you'd have to && them or || them together.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Okay, so you know that's not correct but how can you change it? In this case ptrnSize is not the right number of stars. Go back to post 28 and read it again. How many do you need on each row? It varies, but what does it vary based on?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Did you try putting a for loop in that spot and seeing if what if anything you could accomplish with it? It's a for loop to print the stars on the left side of the picture.
It needs to print (for a seven line shape):

(zero stars) line 1 -- based on you going 1-7 rather than 0-6
*
**
***
**
*
(zero stars again) line 7

After you've printed those on the appropriate lines, print out the rest of the line. There's a change you have to make so that you don't get extra characters that go beyond the end of the line. Just see if you can do this first part before that. You should be experimenting with it until you get it right or sitting down with a piece of paper and plotting it out. No one is going to do this for you.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Hint: Add another for loop at lines 8 and in between lines 19 and 20. Use it to print the first stars of the row. Modify the starting point of your for loops on 9 and 21 to take this shift into account.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Can you add the additional stars to the left margin? There's 0 on the first line, 1 on the second line, ..., up to (rows/2) stars in the rows/2 line and then down from there,...,1 on the second to last line and 0 on the last line.
i and k are your row counters in the code above -- use them to know how many stars to print at front of the line. It's going to push your rows out beyond the end but you can take care of that in the next step.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

output linenumber-1 * and then an &.

He's given you a good clue there. See if you can get the stars in front of the & at the left border of your creation.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I shouldn't reply since you keep bumping this... So what do you believe you have left to do? Looks to me like it's putting stars to head up the front of each of the rows and that you have to push some off the end those rows that receive extra stars. There's probably a bunch of ways you can pull it off.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

textfile and fileName are just string^s declared elsewhere. I was just using the caps as labels, wasn't yelling lol.

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

You'd have to replace your lines 13 and 14 with a while loop.

int temp;
while(cin >> temp)
{
   //Push back temp onto your vector
}

But you'll either have to have your user hit ctrl-z after they are done entering items(which would send an End Of File signal to cin>>temp which would stop the while loop) or you'll have to use a sentry value (like "Enter -999 when done" -- but then you couldn't have -999 as an element in your vector)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I'm not trying to do the alphabet, its supposed to be something like this

(1 2 3 4 5)
(6 7 8 9 10 11 12)

=
(1 6 2 7 3 8 4 9 5 10 11 12)

I see a little bit better now. Are you trying to ask the user for the number of elements? When I saw the 'a' I thought you were going to convert these numbers back to characters down the line.

Sorry our posts keep getting crossed.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

for the first for loop i didnt know what i should make the condition as due to the fact as its a user input, so idno how to make it any number.

Maybe that's what I don't understand. It seems like you are generating the vectors in the two for loops. What input would you need from the user?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I don't understand what you are trying to do on lines 14 and 16. The >> operator does not work with entire vectors like that. Also what's going on with your loops on 18 and 22? Check those loops by hand, if "i" starts at zero and it evaluates the loop condition i<0, it will already be false and the loop will stay right where it is. If the alphabet has 26 letters and you're going to be alternating them, you know how many elements each vector is going to have.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Well, it was worth a shot. Anyway, hope you can get it to work on your other system. Good luck.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Just for kicks try changing the 65 to 'A' etc. in lines 12-18 on your posting of your full code (like I had suggested before too). It could be a character set problem. Just another shot in the dark but writing stuff without the ASCII will guarantee it's platform independent.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Using your exact program:

Random letter 6: V
Random letter 3: M
Random letter 2: G
Random letter 4: N


Random letter 1: B
Random letter 0: A
Random letter 2: G
Random letter 6: V


Random letter 0: A
Random letter 5: R
Random letter 6: V
Random letter 4: N


Random letter 4: N
Random letter 0: A
Random letter 2: G
Random letter 5: R

No repro of that phenomenon on my end. Are you on any platform that's out of the ordinary?

As one of those "it's probably not but I've gotta ask" are you compiling an old version of your program by mistake?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

These

random letter 6: B
random letter 4: M
random letter 3: G
random letter 5: N

random letter 3: G
random letter 5: N
random letter 4: M
random letter 2: V

random letter 6: B
random letter 0: A
random letter 3: G
random letter 4: M

are 3 sample runs that I generated by using your post #6 and forming a main around it. Try running that section in isolation in another file (with a main around it and the variables declared). Post your complete code in case you have changed something but I'm not sure what it would be.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

It always generates R as the first letter, or what is the situation?

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

i included these libraries:

#include<iostream> //for i/o
#include<fstream> //for opening files
#include<string> //for strings
#include<iomanip>

Where does ReadData() come from then? I don't think that's included with any of these.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Double check your error formula. The error gets stuck at 1.419 or thereabouts. It could be that your chosen points are too far away from the solution but I didn't do any further calculations. Widen your epsilon a bit so you can debug without the program going on forever and then bring it down gradually to its current level.

EDIT: So I think one of the problems is that you never assign xnew back to x and ynew back to y. However, when I do that the errors grow into the 50000 range. I looked over some of the material online about the algorithm (I'm afraid I don't have much experience with it) and everything seemed to point to a negative correction term proportional to the slope of the derivative. Again, look over your material and see what you come up with.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You got the code tags backwards, put them around your code and don't put them around your question. There's still time to edit.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Use the sprintf function. It would look something like sprintf('apple%d.tiff',j); (I don't run matlab any more so I can't test it out) inside of a nested for loop

Outer for
     im1 = imread(sprintf('apple%d.tif',i);
     Inner for
         im2 = imread(sprintf('apple%d.tif',j));   
         Write corr2(im1,im2); into an i by j matrix (zeroed out before)
     end
end
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Give this thread a read. It goes into the specifics of why using scanf in the manner that you have isn't a good idea. Use fgets instead. Simple syntax: fgets(line,sizeof(line),stdin);

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

for(i=strlen(str)-1;i >= 0; i--) You needed both the -1 and the >=0. I had said you were on the right track with the >= sign, otherwise you lose the first character in the string.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Think of each letter of the alphabet as a number from 1-26. So a-z are just 1 thru 26. And aa = 1x26 + 1, ab = 1x 26 + 2, etc. zz = 26x26+26 = 702, aaa = (1x26x26)+(1x26)+1 = 703. So basically you would just parse the digits and do the conversion. It's not really a "base" per se as there are no a0,a1,a2, etc in between z and aa.

After all that, though I think there is a setting in Excel where you can change your column headings to be column number instead of this system.

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
Example_Struct * Foo::GetStructBar()
{
   return structBar;
}

char * Foo::GetBar()
{
    return bar;
}

Provided you have Example_struct structBar[10]; (your array length here obviously) and char * bar declared in your class. Make them Example_struct * and char * return variables in main also.