jaskij 45 Junior Poster in Training

Try Orwell Dev-C++ - someone finally picked up Dev-C++ after all those years.
http://sourceforge.net/projects/orwelldevcpp/

jaskij 45 Junior Poster in Training

IMO, you could just go by every single value and check if they're equal. Like when comparing strings. It doesn't really matter how you go through them, if the matrices are equal you WILL go through every single value anyways. And what you do just asks for bugs.
Why not do something like

// 262144 is 512^2
bool equal=true;
for(i=0;i<262144;i++){
	if(a[i]!=b[i]){
		equal=false;
		cout<<different;
		break;
	}
}
if(equal)cout<<equal;

Also, you could think of pre-computing some cheap (?) metric of those matrices and using it as a precondition when checking for equality.

jaskij 45 Junior Poster in Training

1. #include <typeinfo> and typeid() http://en.wikipedia.org/wiki/Typeid

3. I tend to be wrong recently, but IMO an empty template parameter would incur a compile error.

triumphost commented: You're right! +6
jaskij 45 Junior Poster in Training

It's a problem of context.
The pointer node* head is local to the constructor.

Depending on what it is you are trying to do, maybe a static node *head member will be the right choice for you?

jaskij 45 Junior Poster in Training

The thing is, insertProc() accepts argument of type el_t , not PCB.
The way this is now, you would do something like

myLL.insertProc(arr[0].id)
jaskij 45 Junior Poster in Training

Seems legit, just one thing: make count static, so that the value is shared across all instances of LL.
Further reading on static members:
http://cplusplus.com/doc/tutorial/classes2/

jaskij 45 Junior Poster in Training

Dynamic allocation of memory here is a must, since the user determines the size of the arrays.

Theoretically you could approximate the maximum size of the array and statically declare it with that size, but that is not a good idea, since it wastes memory and such.

jaskij 45 Junior Poster in Training

Constructor is just a normal method, just with no return type, so declare and define it like you would do with any other method (usually declaration in header file and definition in cpp file).

I just wrote it like that to make the code put in the forum as short as possible.
Of course don't forget to declare members of PCB ;)

jaskij 45 Junior Poster in Training

Please use code or icode tags. arr[j*cols+i] is just addressing an element in the array.

Consider the example:

1 2 3
4 5 6
7 8 9

Becomes 1 2 3 4 5 6 7 8 9 in this representation. I suppose you can figure out how it works from here. int *arr=new int[rows*cols] just allocates the memory for the array. How else did you want to do it?

jaskij 45 Junior Poster in Training

First, consider writing a constructor, like

struct PCB{
	PCB(el_t id_,string state_){
		id=id_;
		state=state_;
	}
};

Second, consider making the state an enum - that would be much better IMO, but it depends on you.

Finally, an array of structs is nothing special, just use operator.() , like:

int main(){
	PCB arr[50];
	for(int i=0;i<49;i++)
		arr[i].id=1;
}

Finally, are you sure you can assign an int to type el_t ?

jaskij 45 Junior Poster in Training

Learn pointers. Just do it.
Loads of more advanced problems require them.

The solution provided by Behi John seems legit, so if you HAVE TO use a 2-d array, use that, but that's a stupid thing IMO.
Or you can represent the 2d array as a 1d one in the memory, see the code below.
Iterating over it may get a little tricky, but it's nothing you can't debug :)

#include <iostream>
#include <new>

void func(int *arr,int cols,int rows){
	for(int i=0;i<cols;i++)
		for(int j=0;j<rows;j++)
			cout<<arr[j*cols+i];
}

int main(){
	int rows,cols;
	cin>>rows;
	cin>>cols;
	int *arr=new int[rows*cols]
	func(arr);
}

@Behi John: either you somehow have the cutting edge of c++ (c++ 0x standard was approved 12th of August 2011) in your compiler or it's the non-standard Microsoft way, not sure which.

jaskij 45 Junior Poster in Training

Arrays are EVIL. Use a vector of vectors.
They work similarly to arrays, but have resizing and a bunch of other things, like checking if you don't call for elements outside of the array.
Like this:

#include <vector>
#include <iostream>

using namespace std;

void display(vector<vector<int> > &arr){
	//	do your stuff here
}

int main(){
	vector<vector<int > > arr;
	int w,h;
	cout<<"Width: ";
	cin>>w;
	cout<<"Height: ";
	cin>>h;
	arr.resize(w);
	for(int i=0;i<w;i++)
		arr[i].resize(h);
	//	get the array from the user
	display(arr);
}

That was the preferred solution.
Another would be to make a 1-dimension array of size w*h, then refer to items like arr[y*cols+h] . But still, it's not recommended, as dynamic allocation is prone to erros, although unaviodable.

Actually, making it one dimension (instead of two) is desirable with vectors too, since with two-dimensional arrays (or array-like classes) there is no assurance that all the numbers will be in one block.

@Behi Jon:
The >> for template class declaration was added in c++ OX, there should be a space in there, like > >

jaskij 45 Junior Poster in Training

Look at the STL algorithm header, there is a whole load of functions using this concept, like std::count_if() .

Also, if you want to compute an integral over a range, I found it preferable to pass the integrated function as a pointer, but that's a whole another case and may not be true in general.

jaskij 45 Junior Poster in Training

http://cplusplus.com/doc/tutorial/polymorphism/ - a pretty nice explanation IMO

jaskij 45 Junior Poster in Training

Guess I made a fool out of myself there. Thanks for pointing those out WaltP :)

And what I suggested at the beginning was mostly because OP used those, although I knew that :/ damn my laziness :/
What I meant by "catching" the EOL is that it stays in the buffer and that is the cause of the unintended behavior.

jaskij 45 Junior Poster in Training

1. The problem you have is gets catches the EOL you get after hitting return for the number of the kids. Adding something like getch() before that gets() should fix this. Or just use gets() twice.

2. Use string instead of string.h - the second one is legacy AFAIK.

3. Don't mix C++ and C I/O. Use istream::getline() or getline() from the string library.

WaltP commented: Terrible suggestion. -4
jaskij 45 Junior Poster in Training

For integer division, a/b, you subtract b from a, as along as a>b, counting how many times you did that. The rest is a remainder (a mod b)

jaskij 45 Junior Poster in Training

Didn't you get a makefile with those examples?
Try looking for one and compiling with it, that should work.

Also, looking at the file header, it is an example from 2002, boost might have changed since that time.

jaskij 45 Junior Poster in Training

Nice one, that :)
Your number is 5-digit in binary. Based on that, in each guess, you set one digit of the number to 1, and then output all the possibilities for the other four digits (which are exactly sixteen), if the user answers 'yes' - you leave that digit as 1, if the answer is 'no' - you set that digit to 0.

For example: I fix the second digit, so the list is:
{2, 3, 6, 7, 10, 11, 14, 15, 18, 19, 22, 23, 26, 27, 30, 31}
If the user answers 'yes', I know the number is of the form xxx1x, if 'no' then number is of the form xxx0x.
Repeat for every binary digit.

There's a whole hell of things you can do to optimize such a thing, but I'll write more once I see some code.

jaskij 45 Junior Poster in Training

You are expected to post the code in the first post, but well.
The algo is pretty simple here - remember those multiplication lessons back in elementary school? For a*b you just make a+a addition b times. Similar with division.

jaskij 45 Junior Poster in Training

No problem ;P

Inside your class:

void RecordAsset(const MaxSDK::AssetManagement::AssetUser& asset){
int a;
}

Sorry for the lack of indentation, wrote it in the forum posting box.

jaskij 45 Junior Poster in Training

Just make an empty method or something, should work IMO.

The question here is, how will that work with Max.
Since the arg is a const reference it shouldn't have much of an impact though.

jaskij 45 Junior Poster in Training

As you can see, you should implement the RecordAsset() method.

Take a look here: http://download.autodesk.com/global/docs/3dsmaxsdk2012/en_us/index.html

No idea what it does though, I suppose this has something to do with 3dsMax's internal management or what...

jaskij 45 Junior Poster in Training

To be honest with you, I'd say it's not a task for C++, rather a computer algebra system - they tend to cope with similar tasks really well.

Anywas, there is next_permutation() in the STL algorithm header, this should help you using what VernonDozier wrote. Just pick a digit to repeat, make an array(or vector) of them, sort it, then iterate through it's permutations using next_permutation() . Still, you have 10*9!=10!=3,628,800 iterations on your hands.

jaskij 45 Junior Poster in Training

Expected something of the kind.

I suppose telling you what the docs say will not help you, but they mention SIGSEGV after getting a null font.

txwooley commented: Thanks for the help. +3
jaskij 45 Junior Poster in Training

Hard to say, but my guess is you don't implement a pure virtual function that is in the class from which you inherit. Could you give a link to docs?

Also, for more extensive error descriptions, just google "Visual Studio error" adding the error you get. Microsoft provides nice descriptions, which sometimes are pretty helpful. Not this time though.

jaskij 45 Junior Poster in Training

What you have there is not a pure virtual function, but just virtual function.
A purely virtual function would be like: CoreExport virtual void EnumAuxFiles(AssetEnumCallback& assetEnum, DWORD flags)=0; .
A simple virtual function means only one thing: it can be re-defined by it's child classes.

There is a good description of this at cplusplus.com, if my explanation wasn't enough.

jaskij 45 Junior Poster in Training

I strongly recommend using SDL_Image and ditching BMP for better formats, like PNG where you can ditch color keying. It is described a few tutos later on LazyFoo.

Although the reference doesn't mention it, I wonder if SDL_Init() shouldn't be called before a call to SDL_DisplayFormat() .

jaskij 45 Junior Poster in Training

binaryhash.h line 46 You need a forward declaration of the struct node . Or just move the private part before the public one. binaryhash.h line 46 void deleteNode(node *n) takes a pointer, not a value. binaryhash.h line 54 This one I don't really get, probably some spelling mistake or something.

jaskij 45 Junior Poster in Training

+1 to WaltP

Actually, did you read the error(shouldn't it be a warning?)? It should clearly state the line where this uninitialized variables is used.

Other than that, you never set result inside main()

jaskij 45 Junior Poster in Training

This is a linker error.

The point here is, you are telling the compiler to compile this code as an app, not a library, so it expects int main(), which is nowhere in your code.

If this is a school assignment, just adding int main() somewhere below (which you would do anyway to show that it works) should be sufficient.

Or you can build this as a library. For specific instructions how to do it, google your compiler/IDE adding "building a library" - should help.
If, for example, your IDE is MS Visual Studio, google "Visual Studio buidling a library".

jaskij 45 Junior Poster in Training

Line 6 is a special constructor syntax, used if all you want to do in a constructor is assign values. Donno how to explain it much further without copying a longer text on constructors, classes and so on...

Second, for that code to work, you have to define the Point class somewhere.

Third, P is of type PointArray which has a member P, so to acces a single point inside your struct, you have to write P.P[pnt_index]

Fourth, not memset... why would you even want to use it there?
More like P.P.resize(size) to set the length of the array (if that's what you want to do)

And then to set the point coordinates use P.P[index].X=val; and P.P[index].Y=val;