daviddoria 334 Posting Virtuoso Featured Poster

That is because you have not #include <cstdio> Also, you should pretty much never include a .cpp file.

daviddoria 334 Posting Virtuoso Featured Poster

Right, I stuck a "perl" in front of the file name inside the system() call.

A batch file would also work (cd to the directory you want and then "perl file.pl"), but it doesn't seem necessary here.

Dave

daviddoria 334 Posting Virtuoso Featured Poster

What is wrong with

system("perl C:\test\perl\a.pl");

?

daviddoria 334 Posting Virtuoso Featured Poster

Careful though, don't say anything is better than anything else or Narue will become angry!

daviddoria 334 Posting Virtuoso Featured Poster

I would use a std::vector<std::string> to get an array of strings to the constructor. Any time I see **, I think "there is definitely a better way to do this" :)

daviddoria 334 Posting Virtuoso Featured Poster

I'm glad you found your solution. Please mark the thread as solved.

Dave

daviddoria 334 Posting Virtuoso Featured Poster

First, I'm not sure if you actually copied and pasted, but in your A class, public; should be public: .

Second, you need semicolons after the closing brace of all of the class definitions.

The main problem is that you are defining m_b in the constructor of A (a local variable), then trying to access it from a member function of A. You need to define m_b as a member variable of A (outside of any functions, including the constructor).

Good luck,
Dave

daviddoria 334 Posting Virtuoso Featured Poster

I have a feeling that most of us geeks here are going to need a better explanation of what these rankings (0-3) mean, and a bit of an English explanation of what is going on before we can look at your code simulation.

daviddoria 334 Posting Virtuoso Featured Poster

You could simply take the input as a std::string and then use yourString.size(). If there were decimals, you could check each character to see if it is a number using something like this: http://www.java2s.com/Tutorial/Cpp/0040__Data-Types/Usingfunctionsisdigit.htm

int digitCounter = 0;
for(unsigned int i = 0; i < yourString.size(); i++)
{
 if(isdigit(yourString[i]))
 {
  digitCounter++;
 }
}

Dave

daviddoria 334 Posting Virtuoso Featured Poster

You need the .c_str() function. If you have a

std::string MyString;

and you want to pass it to something that accepts a char*, pass it MyString.c_str()

Dave

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

Do you have code to make a tree with 2 leafs per parent? Show us this and indicate where you think it would need to be modified to make more than 2 leafs, and we'll see if you're on the right track.

Dave

daviddoria 334 Posting Virtuoso Featured Poster

Welcome to DaniWeb! I have a few tips to get you started.

1) While we understand that English is not everyone's first language, you must still use proper English words. For example "plz" and "thx" are not proper words.
2) You must use code tags when posting code. It makes it MUCH easier for us to read.
3) stdio.h, stdlib.h, string.h, etc are deprecated. You should use #include <cstdio> etc instead.
4) You should break the problem down in a very specific question that we can answer. Try to separate the code into pieces and test each piece. When a piece fails, you should provide the input, current output, and expected output and we'll take a look.

Good luck!

Dave

daviddoria 334 Posting Virtuoso Featured Poster

I just think people here are typically more interested in STL ("new") c++ and that typically has nothing to do with hex and shift operators, etc. The C guys seem to like that stuff more :)

daviddoria 334 Posting Virtuoso Featured Poster

Glad to hear that you like Daniweb! It does sound like quite a task for a 2 week project. There is a game development forum here that may be able to help you out: http://www.daniweb.com/forums/forum71.html

It seems to me like the key will be to identify the intersection of the bottom of the falling piece with the top of every piece that has already fallen. When this intersection happens, stop the piece, drop the next piece, and update the "tops of all of the fallen pieces" data. This actually shouldn't be too bad since the game is inherently discrete.

Good luck!

Dave

daviddoria 334 Posting Virtuoso Featured Poster

There is a function called getline(), I'm not familiar with just get(). But you can use the >> operator with ifstream. Take a look and let us know when you run into a particular question.

Dave

daviddoria 334 Posting Virtuoso Featured Poster

Sounds like you want to concatenate vectors? You can do

vector1.insert( vector1.end(), vector2.begin(), vector2.end() );

to append vector2 to the end of vector1.

An equivalent statement is

std::copy(source.begin(), source.end(), std::back_inserter(destination));

Don't forget to vote for answer cataloging so this can be added to a solution database somewhere!: http://daniweb.uservoice.com/forums/62155-general/suggestions/830529-create-a-wiki-to-catalog-answers-and-examples-?ref=title

daviddoria 334 Posting Virtuoso Featured Poster

So what exactly is the problem? It looks like if you add a cout statement

getline(infile, Storeline);
std::cout << Storeline;

you'd have what you asked for (simply displaying each line of the file on the screen)?

daviddoria 334 Posting Virtuoso Featured Poster

Have you looked into using ifstream? This is the "new way" to read files where scanf is the "old way".

daviddoria 334 Posting Virtuoso Featured Poster

OpenCV is just as heavy as VTK, so take your pick. But ImageMagick would be much more lightweight than VTK, so that is probably the best suggestion.

daviddoria 334 Posting Virtuoso Featured Poster

I took it upon myself to create it:
http://daniweb.uservoice.com

I guess it could serve kind of like a bug tracker, but I believe it is intended more for generic concepts that users would like to see added. I started it off with a few recent things from this board.

Dani, if you're interested, I can sell it to you :) haha

Dave

daviddoria 334 Posting Virtuoso Featured Poster

Instead of dividing by 10, you can also do the stringstream thing to get the number into an std::string. Then you can access individual elements (numbers) with simply yourString[i] . You can do the conversion with +'A', then put humpty dumpty back together again.

daviddoria 334 Posting Virtuoso Featured Poster

Yes, #include <sstream>

daviddoria 334 Posting Virtuoso Featured Poster

Just push the big number into a stringstream and then read it out as a string:

std::stringstream ss;
int number = 12345;
ss << number;
std::string yourString;
ss >> yourString;
daviddoria 334 Posting Virtuoso Featured Poster

I posted this a while ago:

http://www.daniweb.com/forums/thread287028.html

Since there were not many replies, I'm assuming something like this doesn't exist? Maybe DaniWeb would like to start one?

Just a thought.

Dave

daviddoria 334 Posting Virtuoso Featured Poster

You may also try posting this in the C forum if you don't have any luck here.

daviddoria 334 Posting Virtuoso Featured Poster

I guess I didn't post a link? haha. Here is the code you'll need.

#include <vtkSmartPointer.h>
#include <vtkJPEGReader.h>
#include <vtkImageData.h>
 
int main ( int argc, char *argv[] )
{
  //parse command line arguments
  if ( argc < 2 )
    {
    std::cout << "Usage: " << argv[0]
              << " InputFilename(.jpg)" << std::endl;
    return EXIT_FAILURE;
    }
 
  vtkstd::string inputFilename = argv[1];
   
  // Read JPG file
  vtkSmartPointer<vtkJPEGReader> reader =
    vtkSmartPointer<vtkJPEGReader>::New();
  reader->SetFileName ( inputFilename.c_str() );
  reader->Update();
  vtkSmartPointer<vtkImageData> image = reader->GetOutput();
  
  // Get dimensions of the image
  int* dims = image->GetDimensions();
  
  // Access elements of the image
  for (int row = 0; row < dims[1]; row++)
    {
    for (int col = 0; col < dims[0]; col++)
      {
      //double* pixel = static_cast<double*>(image->GetScalarPointer(row,col,0));
      //std::cout << "(" << row << " , " << col << ") = (" << pixel[0] << " , " << pixel[1] << ")";
    
      unsigned char* pixel = static_cast<unsigned char*>(image->GetScalarPointer(col,row,0));
      std::cout << "(" << row << " , " << col << ") = (" << int(pixel[0]) << " , " << int(pixel[1]) << ")" << std::endl;
      }
    }
    
  return EXIT_SUCCESS;
}

I could have row and col reversed, you'll have to check it out.

Dave

daviddoria 334 Posting Virtuoso Featured Poster

Good idea gusano79, but I was thinking that he had to check many conditions (rows, columns, and boxes), so generating a permutation of a whole row at a time and then checking all 9 elements for those conditions may be just as slow as doing it one number at a time. If you do want to use a permutation of the numbers 0-9, it is very easy with the STL:

#include <iostream>
#include <algorithm>
#include <vector>

int main(int argc, char* argv[])
{
  std::vector<int> v;
  
  //add 10 integers (0 to 9)
  for(int i = 0; i < 10; i++)
  {
    v.push_back(i);
  }
  
  std::cout << "Ordered" << std::endl;
  for(int i = 0; i < 10; i++)
  {
    std::cout << v[i] << " ";
  }
  
  std::random_shuffle(v.begin(), v.end());
  
  std::cout << std::endl << "Shuffled" << std::endl;
  for(int i = 0; i < 10; i++)
  {
    std::cout << v[i] << " ";
  }
	
  return 0;
}
daviddoria 334 Posting Virtuoso Featured Poster

These are very "heavy" libraries. That is, they are DEFINITELY overkill for just reading images, but unless someone recommends something more "lightweight", it will get the job done. The one I am most comfortable with is VTK. You can download it from here

http://vtk.org/VTK/resources/software.html
(direct link: http://www.vtk.org/files/release/5.6/vtk-5.6.0-win32.exe)

Once it is installed, you will have to link to vtkHybrid. Then you should be able to use the code in the example I sent above. I will actually fix that example to show you how to access individual pixels. I'll let you know when that is done.

Dave

daviddoria 334 Posting Virtuoso Featured Poster

You probably want a 'do while' loop here. The condition of the loop should be if the input is not 0. The content of the loop should be to get the input and get it into a form that it can be compared with 0.

Give it a shot and we'll help you if you get stuck.

Dave

daviddoria 334 Posting Virtuoso Featured Poster

You absolutely cannot read jpg files with iostream! jpeg is a lossy format which means you need the inverse of the jpeg compression algorithm in order to read it! BMP may be possible, but you're crazy to read it yourself! My suggestion would be to use a library that has image reading capabilities. You could use VTK, VXL, and probably OpenCV to read a variety of image formats.

Good luck,

Dave

daviddoria 334 Posting Virtuoso Featured Poster

I'd say attaching a file is a last resort. There aren't many questions that can't be simplified into a very short, compilable version of the problem and posted reasonable with code tags.

daviddoria 334 Posting Virtuoso Featured Poster

Great, I'm glad it's working. Let me leave you with some words of advice.

It's a small program (< 1000 lines) and we'll never be modifying it in the future so it's not a big deal.

EVERY time I have said something like that, I have later said "Dang, I should have done this better/figured this out the first time!". I try to build a database of examples out of every little project so I have organized code snippets to refer to when I come across the same problem or type of situation in the future.

Good luck,

Dave

daviddoria 334 Posting Virtuoso Featured Poster

shuma -

Welcome to DaniWeb!

Here are a couple of tips to get you the answers you are looking for:
- Though we understand not everyone is fluent in English, please use proper English words. E.g. "plz" and "plzzzz" are not English words.

- Please do not "hijack" threads. That is, epicasian asked a question, and then you asked your own question as a reply to his question! You should start a new thread if you have a new question.

- Typically no one is going to help you without showing them what you have tried first. You'll have much more success here if you post some code saying "I tried to do this - but here is the problem I am having".

Good luck,

Dave

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

What you have described is called "rejection sampling". That sounds like a reasonable way to go about this to me. If you use std::vector to to store the elements you can then use find() from the stl to do the search. It shouldn't be that bad for something as small as a sudoku game.

Dave

daviddoria 334 Posting Virtuoso Featured Poster

You never tell it how big ClassFreq should be, then you start accessing elements! It looks like you should do

vector <int> ClassFreq(numberOfClass);

but I'm still not exactly sure what you are trying to do, it seems like there may be a better way using stl functions.

Dave

daviddoria 334 Posting Virtuoso Featured Poster

Welcome to Daniweb! Although your question is written in c++, you may have better luck with this kind of thing in the Game Development forum:
http://www.daniweb.com/forums/forum71.html

Also, be sure to use /code at the end of your code tags so they are applied!

I'd also try to simplify your question into sub-questions. To make something "bounce", it seems to me that you need to know how to do two things.

1) make an object move
2) detect collisions between two objects

Good luck,

Dave

daviddoria 334 Posting Virtuoso Featured Poster

I've seen a couple of "short lists" posted - are you guys aware of http://uservoice.com/ ? Here is a live site if you want to poke around: http://paraview.uservoice.com/

It is a really nice way to (openly) keep a list like this and collect in an extremely organized fashion users wants and needs. And unless they changed it, it is free if you get less than 100 comments or something like that per month (if you get more than that, it would probably be worth paying for!)

Just a thought!

Dave

daviddoria 334 Posting Virtuoso Featured Poster

If you are not already a fan on Facebook go here

I believe they have changed the terminology from "fan" to "like"? I'm not sure what the verb form (similar to "become a fan") of "like" is? "Tell Facebook that you like Daniweb?" haha

Dave

daviddoria 334 Posting Virtuoso Featured Poster

The dinner was great! It's always interesting to have conversations with people from such varying backgrounds. The pictures look great, too! What was the deal with the glasses with no lenses? I saw Dani had them on for a while, then they disappeared.

Unfortunately I couldn't stick around for much of the after party, but it was certainly rockin'!

Are there any more Daniweb events in the foreseeable future?

Dave

daviddoria 334 Posting Virtuoso Featured Poster

Welcome to Daniweb!

Please show us your attempts - we'll be much more inclined to help you fix something you already have instead of writing it for you from scratch :)

Can you also clarify the problem? Do you have a list of names? Are they in a std::vector<std::string>? If so, you should be able to use sort() from #include <algorithm> Good luck!

Dave

daviddoria 334 Posting Virtuoso Featured Poster

An adjacency list should simply be a std::vector<std::pair>, right?

http://en.wikipedia.org/wiki/Adjacency_list

You look like you have created more of a graph traversal structure here. Unless you are doing this simply as an exercise, there are some graph libraries out there already. I use vtkGraph (I put some examples here: http://www.vtk.org/Wiki/VTK/Examples#Graphs

It uses Boost Graph Library (BGL) under the hood, but these VTK wrappers make it much much easier to use.

Another suggestion would be to separate the actual input (cin) from the makeList function. This will allow you to populate the list either manually in the code, from the user (as you're doing now) or from a file with the maximum amount of code reuse.

Dave

daviddoria 334 Posting Virtuoso Featured Poster

Welcome to Daniweb!

First, please use descriptive titles. This will help you get answers faster as people will be intrigued by your title!

To answer your question, my suggestion would be not to use c++! I think you will have much better luck posting this question in the game development forum:
http://www.daniweb.com/forums/forum71.html

You should also include details about which types of games you are looking to develop (and examples of existing, similar games), what kind of background in programming you have, etc

Good luck,

Dave

daviddoria 334 Posting Virtuoso Featured Poster

Welcome to Daniweb!

First, in the future please use more descriptive titles. This will "help us help you". It will also get more people interested in your question as you can peak their interest with the title.

What is QRNA? Please post the smallest compilable code that will produce this error. This is a good habit to get into :)

Dave

daviddoria 334 Posting Virtuoso Featured Poster

Welcome to Daniweb!

To produce an executable, you need to "compile" or "build" the code. Also, you should use #include <iostream> and std::cout << "abc"; instead of #include <stdio.h> and printf("abc"); Hope that helps,

Dave

daviddoria 334 Posting Virtuoso Featured Poster

Yep, I'd agree with happygeek. I am one of those over-diligent people that felt inclined to follow the directions :). Had the directions said "do nothing, they site owners have already been notified" I would have been quite content to do nothing :)

daviddoria 334 Posting Virtuoso Featured Poster

I would use std::stringstream to put the int into a stirng. Then the logic is much more straight forward to get each digit of the string. You can again use stringstream to get each one back to an int before adding them.

iamthewee's option also works, but it could be more confusing to read in my opinion.

Dave

daviddoria 334 Posting Virtuoso Featured Poster

Doesn't sound like you want help with pointers, but more you want us to do your homework!

daviddoria 334 Posting Virtuoso Featured Poster

If you just want introductory information about c++ and some basic tutorials, I'm sure google has some :)