daviddoria 334 Posting Virtuoso Featured Poster

You should step through the code with a debugger and determine exactly which line the segfault happens on. This will give you (and us) a better starting point.

daviddoria 334 Posting Virtuoso Featured Poster

I think you'll have better luck asking the OpenCV people: http://tech.groups.yahoo.com/group/OpenCV/

daviddoria 334 Posting Virtuoso Featured Poster

I strongly suggest Qt. The crossplatform-ness is a HUGE plus in today's very varied operating system landscape.

There are some examples here:
http://programmingexamples.net/index.php?title=Qt

And the Qt documentation itself is very good: http://doc.qt.nokia.com/latest/classes.html

daviddoria 334 Posting Virtuoso Featured Poster

You have posted everything except the findLowest function! What have you tried? I bet it should involve some conditionals (ifs) and some < operations.

daviddoria 334 Posting Virtuoso Featured Poster

Please try to pose your question in a way that can be demonstrated in < 20 lines of code and is generally usable for other readers.

daviddoria 334 Posting Virtuoso Featured Poster

I would suggest you go to sourceforge.net or github.com and search around for something that interests you. Many of these projects are small so people may be excited to receive help.

daviddoria 334 Posting Virtuoso Featured Poster

Here is an example:
http://programmingexamples.net/index.php?title=CPP/RandomNumbers

What is the error you're getting?

daviddoria 334 Posting Virtuoso Featured Poster

Please use code tags when you post code.

I don't think you should read the input as an int. I'd read it as a string then you can do whatever you want with it:

std::string input; 
cin >> input;

if(input.length() > 1)
{
std::cout << "You entered more than 1 digit";
exit(-1);
}

if(!isdigit(input[0]))
{
std::cout << "You must enter a numeric digit (0-9)";
}
daviddoria 334 Posting Virtuoso Featured Poster

I don't think you should try to catch this behavior (non integer entered) with a switch. You should look into the "isdigit" function:
http://www.cplusplus.com/reference/clibrary/cctype/isdigit/

Another thing to try is cout << input; to see what input actually is.

daviddoria 334 Posting Virtuoso Featured Poster

I didn't catch what exactly your question is?

daviddoria 334 Posting Virtuoso Featured Poster

Did you take a look through this tutorial? http://www.cplusplus.com/doc/tutorial/classes/

They have great explanations and examples.

David

daviddoria 334 Posting Virtuoso Featured Poster

Definitely. Threads are absolutely how you do multiple things at the same time.

daviddoria 334 Posting Virtuoso Featured Poster

Haha, we needed a mutex (or one of those other words I don't really understand... :) )

daviddoria 334 Posting Virtuoso Featured Poster

You are looking for "threads". Boost has a fairly easy to use thread (a simple example: http://programmingexamples.net/index.php?title=CPP/Boost/Threads) and Qt also has one (QThread). Don't be fooled though, threads get very complex very quickly, so you'll have to do your homework :)

daviddoria 334 Posting Virtuoso Featured Poster

Ah, yes, sorry. I've never profiled code in Windows.

daviddoria 334 Posting Virtuoso Featured Poster

I use KCacheGrind to look at the output of valgrind's callgrind option.

daviddoria 334 Posting Virtuoso Featured Poster

I would start not by trying to do the assignment, but by trying to break down the assignment into generic programming problems. "How do I get input from the user?" "How do I make an array?", etc. We can help you with these sorts of things (after you Google for some tutorials, of course). Once you have these building blocks, the assignment should be easy to complete.

daviddoria 334 Posting Virtuoso Featured Poster

Conversation view is very helpful when you are in a folder, but when you are in an actual email, it seems bizarre that it collapses the text like I showed. I guess I'll just have to deal with it, because I like the conversation view enough not to turn it off to fix this.

daviddoria 334 Posting Virtuoso Featured Poster

It would be great if you would share your solution so others can benefit from it.

Also, please mark the thread as solved.

daviddoria 334 Posting Virtuoso Featured Poster

I suggest you first write a linked list for ints. This will condense your code into at least a quarter of its current size. Also, remove the file input stuff and hard code some values. Once you have this working, you can "upgrade" your linked list class to support this other data structure.

Also, thanks for trying to use code tags, but you have to enclose the code in them, not just the filename.

daviddoria 334 Posting Virtuoso Featured Poster

Why do you have to name all of the operators? Can't you just push all operators from each string into two stacks and then compare the elements of the stacks? I suggest you hard code two strings, parse them into the two stacks, and then output the contents of the stacks. If this works properly, then you just need to compare corresponding elements and if all of the comparisons are true then the operators are the same and in the same order.

daviddoria 334 Posting Virtuoso Featured Poster

You look like you're off to a good start. Once you get some more of the details filled in, if you have any specific errors or questions let us know.

daviddoria 334 Posting Virtuoso Featured Poster

Looks fine to me. And yes, you would just delete the array at the end of the program.

daviddoria 334 Posting Virtuoso Featured Poster

I suggest hard coding a very small input, solving it by hand, then putting some output statements in your loop so you can see where what your programming is computing differs from your correct hand-computed solution.

daviddoria 334 Posting Virtuoso Featured Poster

This is not keyboard emulation (which would be GENERATING key presses), but rather just catching key presses, right?

Apparently this can be done using curses:
http://www.codeguru.com/forum/showthread.php?t=435771

daviddoria 334 Posting Virtuoso Featured Poster

I would ask the OpenCV people if they ever run anything on mobile platforms: http://tech.groups.yahoo.com/group/OpenCV/

daviddoria 334 Posting Virtuoso Featured Poster

You should step through the code with a debugger. If you don't want to do that, you should sprinkle output statements throughout the code. The goal is to figure out where the code is crashing.

daviddoria 334 Posting Virtuoso Featured Poster

'worked' does not appear at all in line 28, so I'm assuming you haven't pasted the code the same as it appears in your file?

daviddoria 334 Posting Virtuoso Featured Poster

You should definitely separate the user input from the computations. An added benefit of doing this is that you can hard code some values for testing purposes. Also, your function should return something and then you should output the answer from main.

daviddoria 334 Posting Virtuoso Featured Poster

Sure thing. Please mark the thread as solved.

daviddoria 334 Posting Virtuoso Featured Poster

You haven't implemented the << operator for your struct.

Here is an example of how to do this:
http://programmingexamples.net/index.php?title=CPP/OverloadOperator

Also, you still posted wayyyy more lines than necessary :)

daviddoria 334 Posting Virtuoso Featured Poster

Please use code tags when you post code.

You cannot re-use the word 'struct' here.

struct Data A1[100], A2[100], A3[100];

It needs to be:

Data A1[100], A2[100], A3[100];

Also, please only post relevant code - that is, the shortest compilable code that produces the error you are talking about.

Good luck,

David

daviddoria 334 Posting Virtuoso Featured Poster

Can you just make an AddPerson() function that modifies a member variable as:

NumberOfPeople++;

?

daviddoria 334 Posting Virtuoso Featured Poster

Are you having trouble with the logic of the elevator operation or some syntactical thing about how to pass your array?

A small note: bool exit; - you should not use 'exit' as a keyword. It is very likely used in other libraries etc. I know exit() is usually a valid way to terminate a program.

daviddoria 334 Posting Virtuoso Featured Poster

Thanks Mike. I was actually just reading about traits the other day. That is clearly the right solution here.

daviddoria 334 Posting Virtuoso Featured Poster

Thanks, that is a very important step, so others can see the solution as well.

There should be a section at the bottom of the thread that says "Has this thread been answered?" with a link that says "Mark this Thread as Solved". The idea is that people won't waste time reading your question and trying to answer it because then they can see that it has already been taken care of.

daviddoria 334 Posting Virtuoso Featured Poster

Great! Please mark the thread as solved.

daviddoria 334 Posting Virtuoso Featured Poster

I figured it out:

template <>
void CreateBlankPatch<UnsignedCharImageType>(UnsignedCharImageType::Pointer patch, unsigned int sideLength)
{
  CreateConstantPatch<UnsignedCharImageType>(patch, 0, sideLength);
}

How silly of me. I need a "fake post" button. No matter how long I look at something, I figure it out 4 seconds after posting a question about it.

Sorry for the noise.

David

daviddoria 334 Posting Virtuoso Featured Poster

I want to have a template function like this:

template <class T>
void CreateBlankPatch(typename T::Pointer patch, unsigned int sideLength)
{
  CreateConstantPatch(patch, typename T::PixelType::Zero(), sideLength);
}

It works fine as long as Zero() is defined for the class T. However, with POD types, this is clearly not the case. So I want an unsigned char version of the template, I tried to do this:

template <>
void CreateBlankPatch<unsigned char>(typename T::Pointer patch, unsigned int sideLength)
{
  CreateConstantPatch(patch, 0, sideLength);
}

but it complained that T is not defined. I tried this (even though every example I've seen has empty <> for specializations):

template <class T>
void CreateBlankPatch<unsigned char>(typename T::Pointer patch, unsigned int sideLength)
{
  CreateConstantPatch(patch, 0, sideLength);
}

and I get

error: template-id ‘CreateBlankPatch<unsigned char>’ in declaration of primary template

Anyone know how to do this?

Thanks,

David

daviddoria 334 Posting Virtuoso Featured Poster

Can you please clarify by giving a small example of the graph and resulting adjacency matrix?

daviddoria 334 Posting Virtuoso Featured Poster

This is quite a complicated function. It is almost impossible to follow - you have multiple nested loops, one letter variable names, and NO comments!! Just because it is called "code" doesn't mean it has to look like an encrypted document! Every one of those nested loops could probably be broken out into function. I bet you that code contains something like a SumRow(int) function and SumDiagonal(), etc. If you write it modularly like this, then you can test each function individually and see exactly which piece is going wrong.

daviddoria 334 Posting Virtuoso Featured Poster

Please pose a question clear enough to be explained and demonstrated in a < 30 line, compilable example. The code should then be posted using code tags.

daviddoria 334 Posting Virtuoso Featured Poster

You can always do a system() call to make c++ do it the way you would do it from the command line. In linux, I would use wget:

system("wget yourURL");

I'm not sure what you would use in Windows.

David

daviddoria 334 Posting Virtuoso Featured Poster

Please try to "abstract" your question. This has many benefits (more on this here: http://daviddoria.blogspot.com/2010/05/problem-abstraction-helping-others-help.html ). For example, instead of:

and im stuck at a part where my program crashes after the ships move for a while

which has little meaning to anyone not in your class, you should try to pose your question/problem as something generic and basically related to a programming concept:

and im having trouble passing an object by reference

(clearly that is unrelated, but just showing that it has nothing to do with you boats or your game, but a concept of general interest to other programmers (who are going to help you) and other readers (who are going to learn from the question/answer pair)).

daviddoria 334 Posting Virtuoso Featured Poster

So basically you are having a problem with file input? Can you post that code (using code tags)? Maybe make a small, compilable demo (< 30 lines) of what is going wrong?

daviddoria 334 Posting Virtuoso Featured Poster

There is no difference between "the compiled code" and "the executables created". The code compiles INTO the executables! Can you explain how you are running these "different versions"?

daviddoria 334 Posting Virtuoso Featured Poster

You call this:

string = zipCode;

before you have defined zipcode. Did you mean to say

string zipCode;

?

Also, you can access individual characters in a string with the [] operator. That is, you can check if the first digit is a '6' by doing:

if(yourString[0] == '6')

Good luck,

David

daviddoria 334 Posting Virtuoso Featured Poster

I suggest you work through this excellent tutorial:
http://www.cplusplus.com/doc/tutorial/

before attempting that assignment.

daviddoria 334 Posting Virtuoso Featured Poster

What do you mean "the number of sequences"? Please give an example number and explain what you would expect the result to be. Did you give it a try? You'll get much better replies if you ask a specific question about a problem you're having rather than just asking for the whole algorithm.

daviddoria 334 Posting Virtuoso Featured Poster

That's what you said before... but WHERE/WHAT is the trouble? Are there compiler errors? Does it crash? etc.