daviddoria 334 Posting Virtuoso Featured Poster

VTK (vtk.org) and ITK (itk.org) also have a lot of tools that could be useful. VTK even has a huge set of examples :) http://www.vtk.org/Wiki/VTK/Examples/Cxx

Lusiphur commented: Useful links :) +1
daviddoria 334 Posting Virtuoso Featured Poster
daviddoria 334 Posting Virtuoso Featured Poster

I recommend you use an std::string instead of a character array for m_name and Name.

daviddoria 334 Posting Virtuoso Featured Poster

Another vote for using std::vector instead of an array. It will save you countless headaches.

daviddoria 334 Posting Virtuoso Featured Poster

sunny - please use code tags.

loyd - no one is going to do your exam for you. Also, please don't "hijack" threads - that is, if your comment isn't directly useful for the original poster, you should start a new thread instead of replying to this one.

David

daviddoria 334 Posting Virtuoso Featured Poster

hanvyj

In cases like this, I'd suggest making a short, compilable program outside of the context of your big program.

#include <iostream>

int main()
{

 long myLong = 20.3;
 std::cout << myLong << " " << (int)myLong << " " << int(myLong) << " " << static_cast<int>(myLong) << std::endl;

 return 0;
}

This should really help you understand what the expected results are. Once you know this, you should be able to more easily find the problem in your real code.

David

daviddoria 334 Posting Virtuoso Featured Poster

So what is the problem?

daviddoria 334 Posting Virtuoso Featured Poster

Also, please use code tags when posting code.

daviddoria 334 Posting Virtuoso Featured Poster

No no, while(!gameover) does NOT set game over to false. It is saying "while gameover is equal to false". This is CHECKING its value, not SETTING it. You could exactly equivallently write while(gameover==false) . Note the double '=', this is c++ for "comparison".

DO NOT do while(gameover=false) . This DOES set gameover to false and this will DEFINITELY not work as you expect.

David

daviddoria 334 Posting Virtuoso Featured Poster

I think you are supposed to use reinterpret_cast for this, but it doesn't work (surely I'm doing something wrong)

#include <iostream>

int main () 
{
  float f = 2;

  unsigned char* c = reinterpret_cast<unsigned char*>(&f);
  std::cout << (int)*c << std::endl;
  
  return 0;
}

It outputs 0 when I would expect 2.

daviddoria 334 Posting Virtuoso Featured Poster

You'll have to make sure you set GAMEOVER to false before you start the loop.

Also, the loop doesn't stop as soon as game over is set to true. For example

while(!gameover)
{
//some stuff

gameover = true;

//more stuff

}

In that example, more stuff will be run even after gameover is set to true, it has to get to the end of the loop to then go to the beginning of the loop and check the condition.

Hope that helps,

David

daviddoria 334 Posting Virtuoso Featured Poster

Why did he make it complicated? It looks pretty reasonable to me.

daviddoria 334 Posting Virtuoso Featured Poster

That garbage value is most likely caused by an uninitialized variable.

Any time I see '**':

neuron** connections;

I cringe...

Have you considered using:

std::vector<std::vector<neuron> > connections;

instead?

daviddoria 334 Posting Virtuoso Featured Poster

I would step back for a second and ask why you are writing your own bitmap writing function? I bet there are bunches of libraries that include such a thing. Then you can spend your time writing new code!

daviddoria 334 Posting Virtuoso Featured Poster

You can also use find() to check your results: http://programmingexamples.net/index.php?title=CPP/STL/Set

The loop would be something like

while(!found)
{
 if(currentItem() != searchElement)
 {
 next();
 }
}

Once you've given it a shot let us know and we can help you if you get stuck.

David

daviddoria 334 Posting Virtuoso Featured Poster

You're going to have to provide much more detail. Also, if this is a class assignment, you're going to have to show us you tried hard before asking for help.

David

daviddoria 334 Posting Virtuoso Featured Poster

I'd suggest trying to hardcode the values to see if there is something wrong with your input. I'd also suggest using <string> instead of <string.h>

This works fine for me:

#include<iostream>

#include<string>

int main(int argc ,char* argv[])
{

  std::string line1 = "Test 12345 Test 6789";
  std::cout << line1 << std::endl;
  line1.replace(10, 1, "W");
  std::cout << line1 << std::endl;

  return 0;
}

David

daviddoria 334 Posting Virtuoso Featured Poster

Why not use a vector of vectors?

Something like this:

http://programmingexamples.net/index.php?title=CPP/2DVector

but rather than initialize it like this:

std::vector<std::vector<int> > items ( 5, std::vector<int> ( 5 ) );

simply do:

std::vector<std::vector<int> > items;
 std::vector<int> row1;
//construct row1 however you want and as long as it needs to be
items.push_back(row1);

 std::vector<int> row2;
//construct row2 however you want and as long as it needs to be
items.push_back(row2);

Let us know if that does what you're looking for.

David

daviddoria 334 Posting Virtuoso Featured Poster

The title says "Matlab/c++ programming question". I see the Matlab... but where is the c++? This question seems better for this forum: http://www.mathworks.com/matlabcentral/newsreader/

David

daviddoria 334 Posting Virtuoso Featured Poster

I would suggest writing a CSV (comma separated value) file. Excel will then be able to import this.

David

daviddoria 334 Posting Virtuoso Featured Poster

Andreas5,

Please use an informative title for your threads. This will attract the correct set of readers.

David

daviddoria 334 Posting Virtuoso Featured Poster

Seems like a simple for loop should do the trick, no? Show us what you've tried and we can help if you get stuck.

David

daviddoria 334 Posting Virtuoso Featured Poster

Can you be much more specific?

daviddoria 334 Posting Virtuoso Featured Poster
daviddoria 334 Posting Virtuoso Featured Poster

Rather than delete the thread, you should post what you figured out. This way when someone searches the forum, if they find your question they will also find the answer!

daviddoria 334 Posting Virtuoso Featured Poster

I don't even understand the output you are looking for?

Can you make a list of the first 11 numbers you would like to output?

daviddoria 334 Posting Virtuoso Featured Poster

I may be mistaken, but here is my understanding...

You can't convert "matlab code" to "c++ code". What you can do is write c++ code and then give it a matlab interface and "compile" it with the Matlab MEX compiler. The result is a function that you can call from matlab but is actually written in c++.

Look up "matlab mex" and you may find more details.

Good luck,

David

daviddoria 334 Posting Virtuoso Featured Poster

Kanoisa is right, you are returning the variable by reference AND by value, which is not at all necessary.

Also, in your latest post, you are calling the function with only one argument:

incr10(num);

when you have declared it as taking two!

int incr10(int& num, int& value)

David

daviddoria 334 Posting Virtuoso Featured Poster

While this is a pretty short program, I think it would still help to break it down in to functions. Some ideas for functions would be:

void GuessLetter(char letter); //the main logic - every user input should trigger this function
bool ContainsLetter(string word, char letter); //determine if 'letter' is contained in 'word'
void ReplacePlaceholder(string &word, char letter); //replace an '*' with 'letter'
bool IsDone();

Those are just examples, but the point is that then your code is very readable, like this:

do
{
  cin >> letter;
  GuessLetter(letter);
}while(!IsDone())

void GuessLetter(char letter)
{
  if(ContainsLetter(word, letter)
  {
  ReplacePlaceholder(word, letter);
  }
}

Good luck,

David

daviddoria 334 Posting Virtuoso Featured Poster

Welcome to DaniWeb!

(Please use code tags when posting code, it makes it much easier for us to read :) )

What you have there looks good. To add a second variable, simply do this:

int incr10(int& num, int& var2)

You didn't specify what this second variable is for, but hopefully that will get you started down the right path.

Good luck!

David

daviddoria 334 Posting Virtuoso Featured Poster

Is it just me? Or has everyone a drastic slow down in recent days?

David

daviddoria 334 Posting Virtuoso Featured Poster

You can start another program using the system() function.

As for a GUI, I would suggest Qt4.

Dave

daviddoria 334 Posting Virtuoso Featured Poster

Try to break the problem down into as small of parts as possible. Make a < 20 line program that demonstrates one problem you have having and post it for us. It will be much easier to teach you little bits at a time using this procedure than to simply write your code for you.

daviddoria 334 Posting Virtuoso Featured Poster

French or not, you're going to have to show us that you have tried. We are not going to do your assignment for you, but we'd be happy to teach you something along the way!

daviddoria 334 Posting Virtuoso Featured Poster

You are only supposed to access the front and back of a queue too right? So why does queue get an iterator but stack does not?

daviddoria 334 Posting Virtuoso Featured Poster

With std::queue I've been using this:

std::queue<int>::iterator pos = std::find( q.begin(), q.end(), 5);

But when I try that with std::stack :

std::stack<int>::iterator pos = std::find( s.begin(), s.end(), 5);

I get

error: ‘iterator’ is not a member of ‘std::stack<int, std::deque<int, std::allocator<int> > >’

Anyone know how to do this?

Thanks,

Dave

daviddoria 334 Posting Virtuoso Featured Poster

Please don't delete the question - rather post the answer in a reply so that other people searching the forum can find the solution as well.

daviddoria 334 Posting Virtuoso Featured Poster

What do you mean by "does not work"? What is an example triple of input? The current output? The expected output?

I'd recommend making a small demo program to test the functions without any user interaction - that is, hard code three values and see if it gives you the correct result. Separating the input state from the computation stage is always a good idea to at least make sure you're looking in the right place for the problem!

daviddoria 334 Posting Virtuoso Featured Poster

I don't understand why current_loc even needs to be a pointer? Why not just have each player have a member object of your location enum? Maybe I missed something?

daviddoria 334 Posting Virtuoso Featured Poster

Hi Mike - welcome to DaniWeb!

Can you detail the problem more for us? What is wrong? Are there are any compiler errors? Give an example input, the current output, and the expected output.

Looking at this code:

Rational obj1,obj2,obj3;
	{
		obj1 = numerator,denominator;
		obj2 = numerator,denominator;
		obj3 = t;
	}

The first line declares three instances of the Rational class. The braces are unnecessary.

As far as I know, this syntax is not valid:

obj1 = numerator,denominator;

what are you trying to do here?

Good luck,

Dave

daviddoria 334 Posting Virtuoso Featured Poster

Please use code tags when posting code. Also, which numbers are not working correctly? You should be as detailed as possible when posting your problems so people here can help you as efficiently as possible.

David

daviddoria 334 Posting Virtuoso Featured Poster

Welcome to DaniWeb!

First, please use real English words. E.g "plz" is not a word.

Second, please tell us what is wrong? What is the input? What is the current output? What is the expected output? Are there any compiler errors?

These things will help us help you as efficiently as possible.

David

daviddoria 334 Posting Virtuoso Featured Poster

Welcome to DaniWeb!

It would really help if you could "abstract" the problem that you are having. That is, try to make a <20 line compilable example that demonstrates the problem. It is much easier for us to teach you something that you can then apply to your large program than it is for us to debug your large program directly.

David

daviddoria 334 Posting Virtuoso Featured Poster

I use VTK for everything 3D (vtk.org). You ask for c++ and VB in the same sentence though - which would you prefer?

daviddoria 334 Posting Virtuoso Featured Poster

My suggestion (same as Mike's) is to convert everything to a CMakeLists.txt file. It will take some initial time, but it will make everything MUCH easier.

daviddoria 334 Posting Virtuoso Featured Poster

By 2D vectors I think he means

std::vector<std::vector<double> >

.

Also, is this for an assignment? If not, you should definitely stick with a matrix class that is already made - vnl_matrix from the VXL package or something like that. It will save you lots of headaches.

Dave

daviddoria 334 Posting Virtuoso Featured Poster

try

g++ yourfile.cpp

This will produce a binary called a.out. You can also do this to specify the name of the binary file:

g++ yourfile.cpp -o nameOfBinary
daviddoria 334 Posting Virtuoso Featured Poster

I got really annoyed with the "low-level-ness" of OpenGL and GLUT. SDL provided what I thought was a much more reasonable level of an interface. It was also nice that you don't have to enter the "glut main loop" so you don't have to change your existing code so much if you want to add graphics.

daviddoria 334 Posting Virtuoso Featured Poster

Currently I am pointing my domain (mydomain.com) somewhere by using this as the index.html:

<html>
<head>
<meta HTTP-EQUIV="REFRESH" content="0; url=http://somewhere.com">
</head>
<body>
</body>
</html>

However, when I go to mydomain.com, it redirects to somewhere.com, but the URL is actually changed to "somewhere.com" in the browser. Is there a way to make it forward but have the browser url still say mydomain.com?

Thanks,

Dave

daviddoria 334 Posting Virtuoso Featured Poster

You should read a line at a time and use this:
http://programmingexamples.net/index.php?title=CPP/Strings/Split

You should have a Data class and overload the input operator to handle parsing the dates (with the /'s etc)