mrnutty 761 Senior Poster

>> What kind of math do they use and how??

Every kind. From simple addition, to stokes equations, to rays to everything.

mrnutty 761 Senior Poster

std::set sorts the data, which is not what the op wants. The order of the data within the container needs to be preserved.

Well, I'm not completely sure, but since sets are implemented as a binary tree, and
the compare function that I listed just returns true, is the order not reserved? Because
all the sets is going to do, is append the data to the end of the list, and thus act like
a linked list. But while appending it to the end of the list, it still preserves the
uniqueness property. I may be wrong though.

mrnutty 761 Senior Poster

Use the property of sets. It only inserts elements that are unique. That means
no same element will exist in the container.

Do something like this. Note not compiled :

struct MyData{
 //bunch of datas
};
bool operator(const MyData& lhs, const MyData& rhs){ return true; }
std::istream& operator >>(std::istream& istream, MyData& data){
  //read in data here
}

std::ostream& writeData(std::ostream& out, const std::set<MyData>& data){
 //write data here
}
int main(){
 std::set<MyData> fileData;
 std::istream fileReader( "text.txt" );
 //read from file and insert into my set
 std::copy(std::istream_iterator<MyData>(fileReader), //begin reading
           std::istream_iterator<MyData>(),           //end reading
           std::inserter(fileData,fileData.begin()) );//insert the read-ed data to
 writeData(cout,fileData); //print the data read
}
mrnutty 761 Senior Poster

Because you essentially, creating a pointer of pointers. So that means you need
to deference it 2 times.

mrnutty 761 Senior Poster

>> don't I need to derefence

Yes you do

>>so the -> operator should be necessary on the first case

Nope. The operator[] deferences the pointer.

mrnutty 761 Senior Poster

Well, thanks narue for the offer and consideration. I guess I should have mentioned
that I needed help before today. I will have to send the paper today so thanks.

mrnutty 761 Senior Poster

Better yet, you should decouple the system. A player class should not have an array
that stores the animation sequence. Try something like this for example.

class Player{
  //blah blah blah
 void move(int x, int y){ /*logic goes here */ }
 //more blah blah blah
};

template<typename CoordType>
struct Animation{
 typename typedef std::pair<CoordType,CoordType> Coordinate;
 typename typedef std::vector<Coordinate> AnimationType;

 virtual void animate()= 0;
};


class PlayerAnimation: public Animation<float>{
private: 
 AnimationType sequenceOfMoves;
 Player thePlayer;
public:
 PlayerAnimation(const Player& player,const AnimationType& c) : thePlayer(player), sequenceOfMoves(c){};

 virutal void animate()const{
   //psuedocode here
   foreach(Coordinates coordinate in sequenceOfMoves){
       thePlayer.move(coordinate.x(), coordinate.y());
   }
 }
};
void fillPlayerMoves(const Animation::AnimationType& seq){
 /* logic to animate player goes here */
}
int main(){
 Player player;
 Animation::AnimationType listOfMoves;
 fillPlayerMoves(listOfMoves);
 Animation animation = new PlayerAnimation(player,listOfMoves);
 animation.animate();
}
Sodabread commented: Nice method. +1
mrnutty 761 Senior Poster

Hey thanks for the offer. I emailed you the paper. Tell me if you get it. Thanks again.

mrnutty 761 Senior Poster

If you ever decide to release the source code I would love to take a look at it.

Actually, its not hard at all. The method I used is actually an old one, called finite
difference. Here is an example.

Consider the following sequence,

[TEX]S = {1,2,3 ... }.[/TEX]


To find a approximated polynomial function that maps into those data points, we need to
do three things.

1) Find the polynomial degree needed.
2) Create a linear system of equation.
3) Solve the linear system of equation.


To do 1), we do compute the difference between i, and i+1, if possible, until we get
a constant row of numbers. So for the above example,



ROW 0 = 1 2 3
ROW 1 = 1 1


From above, we computed the difference between the adjacent numbers. And we see that
there is a row of constant number, namely Row 1. This tells us that there is a polynomial
of degree 1, that maps into ROW 0.

A polynomial of degree 1, has the following form :

[TEX]p(n) = an^1 + b;[/TEX] [a and b are scalers]


Now for 2), we need to come up with an linear equation for p(n). We can do the
following,

[TEX]p(1) = a(1) + b[/TEX]
[TEX]p(2) = a(2) + b[/TEX]

and by …

jonsca commented: Nice job with it +4
mrnutty 761 Senior Poster

Yes that worked. Not sure what happened with the other one. BTW it worked really well for your question. I had to break down and use my TI85.

Lol, nice.

mrnutty 761 Senior Poster

Not exactly sure where I would have posted this, maybe in the help wanted section, if there
is one,( sorry I didn't bother looking). But I feel like I should place this post here, because there are some smart people that lurks in these woods.

So I have my first real interview for a computer science internship coming this week.
I'm getting nervous talking about it already. They gave me per interview question that I
have to write about. I am done with it now. But I'm not a very proficient writer. So I need
someone to proofread it. Is there any one here with a strong English background that
can help me proofread it. Its only 1.5 page double spaced. I will not post it here, but
if someone decides to help, then I can send them the email or something.

Thanks.

mrnutty 761 Senior Poster

Try this.

mrnutty 761 Senior Poster

Also add std namespace :

#include<iostream.h>
void hi(void);
void name(void);
using namespace std;
int main()
{
...
}

Otherwise you get errors like "cin" not found, and so on.

mrnutty 761 Senior Poster

For this, read up on Modular exponentiation. Using that technique, will help you solve this problem.

mrnutty 761 Senior Poster

Wiki is pretty clear.
What part is confusing? Look at the UMLdiagram, and see if that helps.

mrnutty 761 Senior Poster

>> Should this be posted under code snippets or something

I was thinking about it, but then there is no code.

You forgot to ask "Would you like source with that?" Let's hope it's legit :D

I'd be interested to know which approximation you were using and stuff.

Wow, you really think it wasn't legit, lol. Actually, I'm flattered. Not sure I'f I
want to release it yet. So what do you guys think?

mrnutty 761 Senior Poster

Its this side thing I was working one, when I got the chance. Its not very good right
now, as its still in its developing stage. But its still ok, where I can show it of, lol.
Attached is an exe, that given a set of data points, it tries its best to return a POLYNOMIAL function that maps to those data points, and emphasis on polynomial!

For example here are some test runs :

<enter data points( '.' to end) >  1 2 3 .

<function : f(n) = n >
<f(n) evaluated from n = 1 to 20 : { 1,2,3,4,....19,20 }

Another example run :

<enter data points( '.' to end) > 2 4 6 8 10 .

<function : f(n) = 2n >
<f(n) evaluated from n = 1 to 20 : {2,4,6,8,10 ... 40 }

You get the idea. Again, its not very good. It can only do the simple things. And be nice .

mrnutty 761 Senior Poster

I found the solution just in case anyone is staring at this thread wondering the same thing about there template. The template is supposed to be a .h(header) rather than a .cpp.

Yes thats, a known fact. The up coming C++0x is going to fix this.

mrnutty 761 Senior Poster

Oh wow. This is so shocking. At least, now he's in a safe place with nothing but
happiness. Dave, if your listening, say hi to Jesus for me.

mrnutty 761 Senior Poster

Which version of MS Wrod do you have. In version 2007, it saves the formatting
and the colors. Perhaps, try copy/pasting it on a text file. And then export it on
M.S word.

mrnutty 761 Senior Poster

If i read your question correctly then you can just do this :

int twoD[90][10];
//initialize twoD here 

int * randPtr = 0;
int row = random(0,90); //some random function that returns a random number from [0,90)
int col = random(0,10);
randPtr = &twoD[row][col];
mrnutty 761 Senior Poster

Create a hierarchy :

class Item{
 //...
 virtual int points()const; //returns how much points this item is worth
};
class Book{
 //...
 int points()const{ return 2; }
};
class Food{
 //...
 int points()const{ return 5; }
} ;
//...
mrnutty 761 Senior Poster

Header should contain the prototype, if possible. So put the Timer class inside
the header, but strip the definition from it. Then implement the definition, in the
.cpp file

mrnutty 761 Senior Poster

Put it in different header and .cpp file.

mrnutty 761 Senior Poster

You can use sdl's timer or clock, or if your on windows, Queryperformance counter.
For example, here is one that uses clock().

#include <iostream>
#include <ctime>

using namespace std;

class Timer{
public:
	typedef clock_t TimeType;
private:
	TimeType _clockStart; //holds the time of reference
public:
	Timer(): _clockStart(clock()){
	}
	TimeType getTicks()const{ 
		return clock() - _clockStart;  
	}	
	float getSecondsPassed()const{
		return getTicks()* 1.0f/CLOCKS_PER_SEC;
	}
	void startTime(){
		_clockStart = clock();
	}
	void resetTime(){
		_clockStart = clock();
	}

};
int main(){	

	Timer tm;

	tm.startTime();
	int i = 0;
	while(i != 5){
		if(tm.getTicks() > 1000){ //every 1 seconds
			cout << ++i << " seconds" << endl;
			tm.resetTime();
		}
	}

	cout <<"BOOM!!!!!"<<endl;

	return 0;
}
mrnutty 761 Senior Poster

Can you explain a little more on what the problem is, and how you determine its a problem?

mrnutty 761 Senior Poster

Thats because uint3_t can only hold numbers. What you want is strings.

#include <iostream>
#include <string>
using namespace std;

int main(){
 string input;
 cout << "Enter something : ";
 cin >> input;
 cout << "You entered : " << input << endl;
 return 0;
}
mrnutty 761 Senior Poster

Whe you create BinaryTree<EmployeeInfo> tree;, you can only insert
EmployeeInfo into it. If you want to insert TreeNode into it, then create a
BinaryTree<BinaryTree::TreeNode> tree. I don't know why TreeNode is public. The user should not get a hold of it, since they can mess the tree up! So I suggest for you to make that private, and stay with BinaryTree<EmployeeInfo> tree; ,
and insert EmployeeInfo into it.

mrnutty 761 Senior Poster

my guess is that you are going out of the array bounds. Whats the size of the
array?

mrnutty 761 Senior Poster

Well each different key has its unique hash value, and you use some sort of hashing function to keep the hash value within bounds of the array. Then after you
get the hash value, you insert the value associated with the key inside the array.

So to retrive the object given the key, you get the hash value of the key. Then
you use the same hashing function that you used to keep the hash value within the
array. This gives you the index associated with the hash value. So now all you need
to do is return the value stored at that index.

The error you got, implies, that you probably mis typed something, or forgot
to define the type for an object. You need to show more code.

mrnutty 761 Senior Poster

How are you resolving collision?

mrnutty 761 Senior Poster

Well first fix the header and cpp issue. That error message is saying that
the compiler cannot find the constructor's definition.

mrnutty 761 Senior Poster

It depends, but generally strings.

mrnutty 761 Senior Poster

I need to see the definition of elem and sentinel before we jump to conclusion.

mrnutty 761 Senior Poster

In C++ you cannot seperate the template header from its definition. So You can't have
LinkedList.cpp. You need to put the definition in the same file as the header file.

mrnutty 761 Senior Poster

You don't necessarily need a matrix class. All you need is arrays. Better yet, you
should use std::vector < std::vector<float> >, as a 2d array.
Adjacency matrix are fairly easy to implement with the cost of O(row^2) of space.
What exactly are you having trouble with, in respect to Adjacency matrix.

mrnutty 761 Senior Poster

>> But if you aren't going to use OO Design Principles in C++ to modularize your software, then why the hell would you use C++?

I never claimed that I wouldn't use OOP in C++. I was just responding to your previous comment when you said that the whole point of C++ is OOP; which is untrue.

mrnutty 761 Senior Poster

Well by now I have gotten use to it. Can someone explain why this changed occurred in
the first place? Did I miss something.

mrnutty 761 Senior Poster

>> All of those terms are highly subjective

Point taken. But out of curiosity, from your experience, do you feel as using C++
rather than C, would not only make your life easier, but others maintaining it as well?

>>I'm not sure how that's relevant to the thread.
Its not, but I was throwing that one out there.

mrnutty 761 Senior Poster

Change your template to this :

template <class T, class T2>
T searchArray(T index, T2 answer, int numOfParts){
mrnutty 761 Senior Poster

>> And it's kinda the whole point of C++

No its not. C++ != OOP. C++ has OOP, but does not mean C++ is OOP.

mrnutty 761 Senior Poster

>> Perhaps you could enumerate those advantages so that I can address them directly rather than dealing with vague terms

Well, I feel that C++ allows for shorter code written for the programmer by utilizing
the more extensive libraries. C++ code, when written elegantly, is more readable, robust, and is more maintainable. And those few things is what makes
a well written software, a well written software. But I agree that, most C++
programmer who use OOP do not use it properly; I admit, I am one of those right now.

mrnutty 761 Senior Poster

Hey Narue, let me ask you something. If you got an offer to write a software,
and your choices were only C and C++. Which would you choose ?

"Different", yes. "Better", no"

Can you show why this is ? Thats a big claim. I understand that OOP programming
can lead to bad software design because of people not knowing the language well
enough. But for the people that are very proficient, in C++. Surely, they can
write very robust and maintainable software using C++, maybe much better than C programming. I see so much advantages that C++ provides over C, yet your claim
is that C++ is not better than C. Is it because, its in a "different" category
perhaps?

I'm just asking out of curiosity, not trying attack you or anything. Thanks

mrnutty 761 Senior Poster

>> Hello FirstPerson
Good morning to you to,em-kay.

Now just a few points.

1) Don't use global variables like that.
2) If you don't have a choice then at least, name your variables something meaningful,so I can understand what they are.

3) To move your circle you can do 2 things :
3.a) You can use the translation matrix to move the circles.
3.b) You can vary the x0 and y0 of each circle.

Last but not least, i'm not sure if your drawCircle is correct. You can use
something like this :

void drawCircle(double x0,double y0,double r){
	const float PI = 3.1515f;
	const float DEGTORAD = PI/180.0f;

	glBegin(GL_LINE_LOOP);
	for(int i = 0; i < 360; ++i){
		float posX = std::cos(i*DEGTORAD) * r + x0;
		float posY = std::sin(i*DEGTORAD) * r + y0;
		glVertex3f( posX, posY , 0.0f );
	}
	glEnd();
}

and don't use stuff like atan(1.0) instead of pi. Just use PI. Its more clear,
and no calculation is needed.

mrnutty 761 Senior Poster

Well the bug I found was a subtle one because its not being complained by the compiler.
The error message you are getting is because some sort of linking issues. Which
function is "_ZN3irr4core12irrAllocatorIcE12internal_newEj" and where is it defined?
I am guessing when you include"xxx.h", where xxx contains the _ZN3irr4core12irrAllocatorIcE12internal_newEj function, the compiler is defining it
more than once.

mrnutty 761 Senior Poster

Its hard because thats a lot of code, for 1 post, and plus its not mines. But
try something like this :

class CPlayer{
private:
  gfxSprite weapon;
public:
 void setWeapon(const gfxSprite& obj){ weapon = obj; }
 gfxSprite getWeapon()const{ return weapon; }
 void attack(){ /* logic here to attack with weapon */ }
};
mrnutty 761 Senior Poster

The problem is that here :

MotionState::MotionState(const btTransform& initalTransformation, irr::scene::ISceneNode* const node)
 : node(node), initalTransformation(initalTransformation)

Take "node(node)" as an example. Which one is your private member variable
and which one is the parameter variable ? You might know but the compiler does
not. So you need to change some names, and make then different. Try something like
this :

MotionState::MotionState(const btTransform& InitalTransformation, irr::scene::ISceneNode* const Node)
 : node(Node), initalTransformation(InitalTransformation)
{}
mrnutty 761 Senior Poster

See if this helps:

void decryptLetter(char encryptedLetter){
 char decrypt = /* encryptLetter plus 32 */
 message = // message plus decrypet
 //done
}
mrnutty 761 Senior Poster

Maybe this will help you :

char A = 'A';
int intValueOfA = A; //implicitly converted to int
char copyOfA = intValueOfA; //implicitly converted to int
mrnutty 761 Senior Poster

Here is an example :

//Sqrt.h
class Sqrt{
private:
 const float originalValue;
 const float sqrtValue;
public:
 Sqrt();
 Sqrt(float initValue);
 float sqrtValue();
 float originalValue();
}
//Sqrt.cpp
Sqrt::Sqrt() 
: originalValue(0.0f), sqrtValue(0.0f) //initializer list
{
}
Sqrt::Sqrt(float value)
: originalValue(value), sqrtValue( std::sqrt(value) ) //initializer list
{ /* empty */ }