mrnutty 761 Senior Poster

Else statement is connected to the if statement. Once the if statement is executed, else statement is not executed even if the while statement inside the if returns false or true or never returns.

mrnutty 761 Senior Poster

Royal blue, bought my first car last summer. 2007 tiburon GT. Sexy little self. Got it for a bargin too. 21K miles for 8G.

mrnutty 761 Senior Poster

Member functions are not the same as regular functions. There is a little more work, here is an example:

class SampleClass
{
public:
    int plusfunc (int a, int b);
};

int SampleClass :: plusfunc (int a, int b)
{
    return a + b;
}

typedef int (SampleClass::*functor3) (int a, int b);

int main(){
 SampleClass sc;
 functor3 f[1] = {&SampleClass::plusfunc};
//note you need an object to call the function that f points to
 cout << (sc.*f[0])(1,1) << endl;
 return 0;
}

http://codepad.org/w6WexeJy

mrnutty 761 Senior Poster

Your code seems fine, it might be how you setup the environment. How'd you set up your environment? I haven't used netbeans in years. But typically in any ide, there is an option to create a C++ project. Did you try to run a simple hello-world program and see if that works:

#include <iostream>
using namespace std;
int main(){
  cout << "TEST" << endl;
  return 0;
}
mrnutty 761 Senior Poster

Is that function a virtual function, can you change its sigs? Why not return a std::pair<bool,Handle> ?

mrnutty 761 Senior Poster
if(Clock.GetTime() >= FPS){
            Screen->StartFrame();
            Player.Draw();
            Screen->ShowFrame();
            Clock.Start();
        }

Why do you do Clock.start() here again? A better way to handle it is like so:

if(Clock.GetTime() >= FPS){
    Clock::TimeDiff diffTime = Clock.GetTime() - FPS;
    updatePhysics(diffTime);
    updateEntities(diffTime);
}

Check out a full tutoial here

mrnutty 761 Senior Poster

while (v[i] < 2147483648 && v[i] > -2147483647)

I have no words...except this sentence.

mrnutty 761 Senior Poster

If you don't know the size of the parameter 'a' in your example, then it is not possible to correctly write the needed logic with the given information. Sure we can assume things such as the char array is null terminated which is a natural assumtion in this case, but its still an assumption.

mrnutty 761 Senior Poster

Your asking for private code. I told you what I was doing.

Welp for one calm that attitude down. Second good luck with your problem then.

mrnutty 761 Senior Poster

post more code

mrnutty 761 Senior Poster

Somthing like this perhaps

template<typename FirstContainer, typename SecondContainer, typename BinaryOp>
void iterateTwoContainer(const FirstContainer& firstList,
                         const SecondContainer& secondList,
                         const BinaryOp op2){
 for(int i = 0; i < firstList.size(); ++i){
   for(int j = 0; j < secondList.size(); ++j){
     op2(firstList[i],secondList[j]);
   }
 }
}

void handleItemAndToys(const Item1& item, const Toy& toy){/*...*/}
void handleItemAndApples(const Item2& item,const Apple& apple){ /*...*/}
int main(){

   iterateTwoContainers(listOfItem1,listOfToys,handleItemAndToys);
   iterateTwoContainers(listOfItem2,listOfAppels,handleItemAndApples);
}
myk45 commented: thanks! +5
mrnutty 761 Senior Poster
// Append element to array
template <class eltType> Array<eltType> &Array<eltType>::operator+=(eltType elt, const Array<eltType> &A)
{
    if (A.itemsUsed() != A.size())
    {
        elements[A.itemsUsed() + 1] = elt;
        A.incItemAmt();
    }
    else if (A.itemsUsed() == A.size())
    {
        eltType *temp=new eltType[capacity+1];

        for (int i = 0; i < size(); ++i)
            temp[i]=elements[i];

        temp[capacity++]=elt;

        delete [] elements;

        elements=temp;

        return(*this);
    }
}

Oh man this is a pretty confusing operator. Consider just renaming it .push_back or something. Also your problem is that itemAmt isn't being initialzed inside your constructor.

mrnutty 761 Senior Poster

Initialize you letter grades.

 char A('A'), B('B'), C('C'), D('D'), E('E'), F('F');
mrnutty 761 Senior Poster

Innovative...hmmm

Some bullshit I can think of are ...

- Better design
- Cleaner Interface
- Great Client Usability
- More stuff about good design, usability, accessability...
mrnutty 761 Senior Poster

Go for sfml, but there might be more documentation on sdl. Check out gamedev, they are generally good with helping with graphics. Or you can post here and we'll help as well. Just get some simple screen gonig on sfml then move on further from there.

mrnutty 761 Senior Poster

You listed the answer, 1 = 5 therefore 5 = 1.

Sometimes simplicity is overlooked.

mrnutty 761 Senior Poster

Either manually make sure the vector size isn't correct, or use an static array, or inherit from vector and make the resize function private.

mrnutty 761 Senior Poster

Another option is to make a File struct.

struct FileInfo{
    std::string name;
    //possibly other things
    explicit FileInfo(const std::string& name = ""): name(name){}
}

class Lexical{
     ReturnType read(const std::string& sentence);
     ReturnType read(const FileInfo& fileInfo);
}

but I suggest to go the istream route as suggested in previous post.

mrnutty 761 Senior Poster

You're looking for conversion operator. Something like

class Point{
  private:
    int x,y;
  public:
    operatir POINT()const{
       return POINT(x,y);
    }
};
triumphost commented: Perfect! I never ever saw that before. Thank you. +5
mrnutty 761 Senior Poster

How could one insert new elements in the vector ?

By using std::vector::push_back or std::vector::insert function

Would it be a good idea to create the vector within the class / the constructor?

Sure, if you need an array of something, then std::vector is usually a good choice.

mrnutty 761 Senior Poster

Please reformat your code. What is the problem you are having?

mrnutty 761 Senior Poster

glTranslate translate the current view matrix, not just one object. So it can be used for different things

mrnutty 761 Senior Poster
mrnutty 761 Senior Poster

Depends on the compiler I suppose...

Idk, maybe someone more knowledgeable can comment. I haven't seen one implementation that uses a list, simply because calculating at runtime is very fast and way less memory intensive than generating a list of pseudo random numbers, which can be very very long.

mrnutty 761 Senior Poster

>>Random numbers are not calculated, they are pulled from a huge list

Are you sure? I thought they were calculated via linear congruential algorithm given a seed to start from.

mrnutty 761 Senior Poster

You probably forgot to seed it. Try this:

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

int main(){
 srand( time(0) ); //seed the RGN
 for(int i = 0; i < 10; ++i){
   std::cout << (rand() % 100 + 1) << std::endl;
 }
 return 0;
}
mrnutty 761 Senior Poster

Ok so what I need to do is take the key and find the value in the array that matches the key and replace it there. But wouldn't I still have to move the data over to the right and insert the new data into the empty spot?

Key should be unique to each hashtable. So every key of value 5 for example, should map to the same spot in the array.

mrnutty 761 Senior Poster

No all you need is a insert function. Usually what happens is that if you try to insert into the map with a key that already exist you return the already existed key/value pair. It is up to the user to decide whether to remove that key or just replace the value associated with that key

mrnutty 761 Senior Poster

why do you have that? A key should be unique. In your insert function you are shifting values around. That would cause the get method to fail or act incorrectly because a key that was hashed into a slot is no longer in the same slot.

mrnutty 761 Senior Poster

why do you have both "put" and "insert" function? Most likely, you should only have one function to insert into the hashmap.

mrnutty 761 Senior Poster

whats the problem?

mrnutty 761 Senior Poster

I think it will be easier if you try to compress a series of bytes into a smaller chunk instead of trying to compress a byte into something smaller. I suggest to read this and see if it helps.

mrnutty 761 Senior Poster

>>I am storing many variables of different types.

Can you convert/encode all those variables to a string version?

mrnutty 761 Senior Poster

I'm not sure what exactly you are saying. What is a binary tree with 1 and 2? Maybe a picture would help.

mrnutty 761 Senior Poster

You would want to use the concept of iterators, and just assume certain property like being able to move forward. Check out http://www.cplusplus.com/reference/algorithm/find/ for more reference.

mrnutty 761 Senior Poster

In my opinion "++" in C/C++ is just terrible. I don't even know why they allow it to be part of the language. Try

pID = pID + 1;

"++" increment its value by 1 and assigns it to the variable. However, if the operator is inserted inside a conditional statement "as the condition to be evaluated", the value will be assigned to the variable, but the conditional statement will treat it as if such an operation never happened. Just terrible, but that's just me, many programmers use "++" as "the best way".

I disagree. That is all.

mrnutty 761 Senior Poster

thank you! I don't have any formal training in time complexity and all the examples online only show how to denote a single variable. Basically I wrote a whole program and I was trying to figure out the time complexity but it had so many variables in it I didnt know how to show it. this should help me finish.

My only question now is, is there any real point to time complexity? I mean granted it helps show how quick or slow an algorithm is but it not it terms of iterations in relations to but they dont fully represent the correct time. Take sort by insertion it time complexity is averages 0(N^2) however, if you are dealing with mostly sorted data, which most programs are it would be (N*D) D-being the number of things need to be inserted. So is there really a point?

Big-O allows one to compare between different algorithms. That is the point you should get out of this. How else would you cleanly compare bubble-sort against merge-sort?

mrnutty 761 Senior Poster

>>M- happens to be a unknown function of N

That means, M = f(N), and you can't assume anything about f(N), so the runtime would be O(N * f(N)).
That could be linear, polynomial, quadratice, factorial, or whatever; all depending on f(N)

grh1107 commented: thanks! very helpful +1
mrnutty 761 Senior Poster
INPUT-BUFFER: 973 456.2 77F NEWLINE 973 456.2 77F

1)	cin>> m;  //m = 973 
INPUT-BUFFER: 456.2 77F NEWLINE 973 456.2 77F

2)	cin.clear (); //clears the state bits
INPUT-BUFFER: 456.2 77F NEWLINE 973 456.2 77F

3)	cin.ignore (200, '\n');  //ignores 200 characters or until a new line is reached
INPUT-BUFFER: 973 456.2 77F

4)	cin>> letter>> n>> n;   //letter = '9' , n = 73 then n = 456

INPUT-BUFFER: [ is in a failed state I think not sure, sets the state bits ]

5) cout<< letter<< m<< n<< endl; //pass out 9973456
mrnutty 761 Senior Poster

You know if you use std::vector, it does that for you.

int main(){
 std::vector<int> array; //size = 0;
array.push_back( 1) ; //size = 1, [1]
array.push_back(5); //size = 2, [1,5]
}
mrnutty 761 Senior Poster

When you run a program, it creates a process for that program. So when you call exit within that process, the os kills that process and cleans up memory. As for its actual implementation, I do not know. It is most likely implementation specific, that is I don't think there would be one set of implementation that all would follow. But as homework you can create your own exit function using winAPI, by manually deleting the associated process. Other than that, I don't believe you should worry about its details too much.

mrnutty 761 Senior Poster

Sometimes it helps to see concrete examples:

int r1 = rand() ; //random number from [0 , RAND_MAX]
int r2 = rand() % 100; // random number from [0,100);  Note doesn't include 100
int r3 = rand() % 100 + 1; //random number from [1,100]; Note includes 100

const int max = 100;
const int min = -100;
int r4 = rand() % (max - min) + min; // random number between [min,max)

When you want to look up a function, you can see examples here. Bookmark it if you need to. Its a good reference

mrnutty 761 Senior Poster

Skip defines and macros. Use enums when you need type saftey and when it makes more sense.

mrnutty 761 Senior Poster

Yes you can usesetprecision just like you are using setw.

mrnutty 761 Senior Poster
mrnutty 761 Senior Poster

Yes you can Overide any operator you want. This can be done globally or at a specific level.

http://www.parashift.com/c++-faq-lite/operator-overloading.html#faq-13.5

mrnutty 761 Senior Poster

Learn the concept first! When I say learn it, I mean know it inside and out. Its easy to pick up a language once you get the concept down. Stick with one language for now, and use it for your needs. Program data structures using that language and become a master at it

mrnutty 761 Senior Poster

Another way is to use java applets with JNI. You can use JNI to access C++ functions and then you can use java to use applets to embed them on the web.

mrnutty 761 Senior Poster

I think you're implementing it wrong. It should be,

if(CheckCollision(bPos, b_Width, b_Height, p1Pos, p1_Width, p1_Height))
{
		Vector norm;
		norm.myVector.x = 1;
		norm.myVector.y = 0;

                // i - (2 * n * dot(i, n)) 
		bPos.myVector.x = bPos.myVector.x - 2 * norm.myVector.x * bPos.DotProduct(norm);
		bPos.myVector.y = bPos.myVector.y - 2 * norm.myVector.y * bPos.DotProduct(norm);

		
	}
	
}

You had an extra 2 term

mrnutty 761 Senior Poster

You do know that std::string has a function that returns constant char pointer. check it out