mrnutty 761 Senior Poster

int ch, count=0, desc[10];

This is wrong decleration for desc, what you want as suggested is

 const int MAX_SIZE  = 10;
 desc descriptions[MAX_SIZE]

Then on each function you will pass in descriptions and MAX_SIZE like so

 void del(desc[] descriptions, const int MAX_SIZE, int targetCode){
       for(int i = 0; i < MAX_SIZE; ++i){
             if(descriptions[i].code == targetCode){
                descriptions[i] = 0;
             }
       }
 }

Then you can call it like so

  int x = 0;
  cout << "Enter code to delete: ";
  cin >> x;
  del(descriptions,MAX_SIZE,x);
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

It's a little more natural syntax for setters and getters.

I guess it could be considered more natural by some. But in my opinion for stronlgy typed language such as C++ which has concepts of public/private/protected it would be more natural for me to call a member function instead of just using the wrapped variable. But that's just my opinion. Maybe I say that because that is how I was taught and started learning.

mrnutty 761 Senior Poster

Rather than trying to explain, I'll link you to a article that talks about namespace. In general for simple question you should try to be more independent. Take care.

mrnutty 761 Senior Poster
 testClass c ;
 c.flag = true ;
 c.flag = false ;
 c.flag = true ;

Can someone explain why this would be a good idea? It seems like a lot of work for little benifit.

mrnutty 761 Senior Poster

If you are returning by value on built in type, don't return it constant. It might confuse the user, but its arguable. See here

mrnutty 761 Senior Poster

@gon: No its just a way to clear my mind and free myself from all the thoughts that goes on my head.
@nitin1: Quick tell me the winning lotto number so I wan win millions muahahah
@stult: See you in the past then

mrnutty 761 Senior Poster

@nit: Yea in USA its 12/11/2012 right now
@Rev: haha yes, of course the code will be considered obselete in style and practice given enough time passing.

mrnutty 761 Senior Poster

I've been just working at this new enhancement for my company for these few months. I feel like my design is actually good in fact one of the best I've written. But don't be mistaken, it probably isn't the best there could be, I just tried to do my best to create some sort of design which fits nicely and works well with our current system. Anyways, I've been doing medidation lately, it feels really good. I need to do it more often though, I only do it like 2-3 times a week. So what's up with my community? Anything new going on or something you would like to get off your chest? I'm interested so please do tell...

regards, Mr.Nutty

mrnutty 761 Senior Poster

@Gonbe, I think he wants to know if an arary is a subarray of another array at same position. For example

1 2
4 5

is a subarray of
1 2 3
4 5 6

however 
2 1
5 4
not a subarray of

1 2 3
4 5 6

because the position differs.

@op, correct me if its not the case.

mrnutty 761 Senior Poster

Sure no problem, I'll be glad to help. Just post here or private message me.

mrnutty 761 Senior Poster

There are 5 airplanes with 50 seats. Your job is to create a user interface that will assign the seats in the airplanes. So first you should create the data structure for airplanes. If you aven't learned about structs/classes then just use arrays. Here is an example

const int MAX_AIRPLANES = 5;
const int MAX_SEATS_PER_AIRPLANE = 50;
bool airplaneSeats[MAX_AIRPLANES][MAX_SEATS_PER_AIRPLANE] = {false}; 

airplaneSeats[0][0] = true; //assign seat for airplane0 seat0
airplaneSeats[1][12] = true; //assign seat for airplane1 seat12

So now you should create some sort of while loop like so

bool isDone = false;
while(!isDone){
  showMenu();
  int i = getInput();
  processInput();
  isDone = isUserFinished();
}

That above code isn't working but it should give you an idea on how to structure and start off.

mrnutty 761 Senior Poster

Have you learned about structs and classes?

mrnutty 761 Senior Poster

Yes. here is an example

class A{
   public: 
   void foo(){
    cout << "A" << endl;
   }
};
class B{
 public:
  B(A& a){ a.foo(); }
};

int main(){
   A a;
   B b(a); //b will call a.foo in its constructor
}
mrnutty 761 Senior Poster

Well you can do something like so:

Vector3 nextCircularPosition(const Vector3& currentPosition, float angle, float radius){
   return Vector3( currentPosition + cos(angle)*radius,
                   currentPosition + sin(angle)*radius       
   }
void display(){
    Object.position = nextCircularPosition(Object.position,currentAngle,radius);
}
mrnutty 761 Senior Poster

@L7Sqr method1 and method2 do two different things. Consider method1(0) and method2(0). In method1 all if gets executed in method2 only the first if gets executed. So I want to make note of the logistic difference between multiple if versus elseif

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

You probably wany New(Shoe,num);

mrnutty 761 Senior Poster

How do you call it

mrnutty 761 Senior Poster

It is conventional and more readable to use a for loop or a foreach loop, if the language has one.

for(int i = 0; i < array.Count; ++i){ 
    Console.Write( array[i] );
}
mrnutty 761 Senior Poster

Hmm...is your logic something like so:

 1) sprite.x += vx;
 2) sprite.y += vy;
 3) checkCollision();
 4) reactCollision();

Try checking for collition after step 1 and after step 2.

mrnutty 761 Senior Poster

If you are going that route, then in your deletewithTwoChild instead of swapping values, swap the actual node pointers.

mrnutty 761 Senior Poster

Also, if you really need to findFather, since it looks like it is being used extensively, consider adding another pointer in your Node. That new pointer would just point to its parent if any.

deepecstasy commented: Can't do, not allowed by teacher, +0
mrnutty 761 Senior Poster

Simplify your delete to this

 void BinaryTree<mytype>::deleteWithNoChild(BTNode<mytype> *temp){
    delete temp;
    temp = NULL;
 }

No need to worry about finding its father and whatnot. That finding father in that function is probably causing the weird result, because in your deletewithTwoChild function, you don't swap the nodes, but just swap the values. So when you do findFather(temp) in your deleteWithNoChild, its not finding the father you want. Try that and see what happens.

mrnutty 761 Senior Poster

in your reachToCollision, can you remove the check for lastMove.equals and check collision for all lines? See if you get a collision with that.

mrnutty 761 Senior Poster

Never used allegro but I assume you can use both at the same time.

mrnutty 761 Senior Poster

leaf = leaf->left; //move leaf 1 time to right

That comment conflicts with that is written.

leaf->key_value = temp->key_value; //assigning temp's key to leaf

That's not really needed since leaf is going to be deleted right.

Also I'm not sure why you are treating left-child different than right child when deleting using that algorithm. All you are doing is swapping a leaf node with the node to be deleted and deleting the stale leaf node. I don't see how this algorithm has any relation to a leaf having two children as your function deleteWithTwoChild suggests. Just being nitpicky there. If this is fro homework, then you probably want to follow the proper guidlines.

Anyways, can you print out the tree after each deletion? Also what happens if father is null? Have sanity check to see if father or temp is null. If possible post full code in pastebin.com because, the problem might be elsewhere. Can you post your deleteWithNoChild function? And also the destructor for this class.

deepecstasy commented: Comment is correct, yes leaf->key_value modification doesn't make a difference but I just wrote it to be clear, & I have pasted required functions, +0
mrnutty 761 Senior Poster

Also note that you might be able to skip transversal if the number of nodes isn't a power of 2. If it is, then you have to transverse just to make sure it fits the definition.

mrnutty 761 Senior Poster

Do you have a direction associated with the rectangle? For example if the rectangle is going to the right, then it might always be the case for you that the right-side has intersected.

I haven't used Slick2D but you should be able to do a line-rectangle collision test. For example

//assume (rectangle.x,rectangle.y) is the point in the top left corner
Line topLine = Line( rectangle.x , rectangle.y , rectangle.x + rectangle.width, rectangle.y);
Line rightLine = Line(rectangle.x + rectangle.width, rectangle.y, rectangle.x+rectangle.width, rectangle.y+rectangle.height);
//.. so on
bool topLineHit = topLine.intersect( otherRectangle );
mrnutty 761 Senior Poster

I like <MICHAEL> avatar, it makes me smile lol

mrnutty 761 Senior Poster

Are you rectangles rotated? Do you expect us to just write one for you? Or do you have a specific question?

mrnutty 761 Senior Poster

Set::Node* cons(int x)

The proper syntax is

Node* Set:::cons(int x)

Similar for the other decleration as well.

mrnutty 761 Senior Poster

what language is this? Its hitting default because none of the cases match, try printing out target and see what it shows and try to match it to the case statement. You might just want to check if target contains('Erikpl') to avoid the extra stuff.

mrnutty 761 Senior Poster

Accessing arrays doesn't necessiarly have to throw out of bounds exception, at least I don't think that is a standard requirement. Are you in debug mode? Try running it on release mode and see if it throws an exception or crashes?

mrnutty 761 Senior Poster

Yea you seem to be a little confused. First here is how you should declare the class, doing things for simplicity right now.

class Coordinate{ //declare a class named Coordinate
 private:
   float x; //has a member variable x
   float y; //has a member variable y
   float z; //has a member variable z
 public:
 //create a constructor that takes in 3 float valuex, namely (X,Y,Z) which is default
 //initialized to 0
  Coordinate(float X = 0, float Y = 0, float Z = 0){ 
    x = X; //assign our member variable x with the one passed in 
    y = Y; //assign our member variable y with the one passed in 
    z = Z; //assign our member variable z with the one passed in 
  }
   //create a function called print that prints the member variables x,y,z in the
   //form (x,y,z)
  void print(){
    cout << "(" << x << "," << y << "," << z << ")" << endl;
  }
};

int main(){
   Coordinate c1;
   Coordinate c2(1,2,3);

   cout <<"c1 = ";
   c1.print();

   cout << "c2 = ";
   c2.print();

   return 0;
}

So that should get you started in terms of syntax. As for your add,subtract,multiply, and divide function it will have a form similar to this

class Coordinate{
 //same stuff from above
public:
void add(const Coordinate& c){
  x = x + c.x; //set our member variable x to itself plus the c.x passed in
  y = y + c.y;
  z = z + c.y;
}

Hopefully that can get …

mrnutty 761 Senior Poster

@Michael: Cool! I always like to meet similar people with similar interest. Your bunny looks surprised lol

mrnutty 761 Senior Poster

I know the question was who, but lets cover more ground my casting it to what. What makes me happy are the things I love to do and enjoy. Some of which are

  • Spending time with family
  • Spending time with my brother, more specifically
  • Playing basketball
  • Programming
  • Making people smile
  • Helping people to make their day better
  • Simply appreciating life, and so much more
mrnutty 761 Senior Poster

What do you think it does? Did you test it out?

mrnutty 761 Senior Poster

What do you need help with exactly? Start by creating a class which has a char* as a member variable. And get it to allocate when calling the constructor. Then go on from there.

mrnutty 761 Senior Poster

You need to also limit your frame rate. See this site for a good reference and code.

mrnutty 761 Senior Poster

So first you should know that although multiple inheritance is frowned upon by some people, that doesn't necessairly make it wrong. Second, it is an accepted design if you inherit from multiple interface.

So simple example( the size, display ) you can characeterize each property into some catagory and make it an interface like so

struct IRender{
  virtual void render() const = 0; 
};

struct IBodyFeature{
  virtual int mass() const = 0;
  virtual int weight() = const = 0;
};

class Object: public IRender , IBodyFeature{
 //...
};

Now for your example

In the first stage I will make just a simple console program, with a menu: 
a. Show all phones (from txt files at first)
b. Compare 2 terminals
c. Insert characteristics 
d. Administrative 
        a.Add phone
        b.Remove phone 
        c.View files
etc.

Have a base phone class

class PhoneInterface{
     public:
       enum Type{ IPHONE, ANDROID };
     public:
     virtual bool hasWireless() const = 0;
     //...
};

class IPhone : public PhoneInterface{ ... }
class AndroidPhone: public PhoneInterface  { ...}

Implement that then you can go on from there.

mrnutty 761 Senior Poster

Yes in C++ you can return a pointer by reference, doing so will allow you to change the pointing address of the pointer and have it affect out of scope. For example

void reallocateRef(Node*& node, int newValue){
    node = new Node(newValue);
}
void reallocateNoRef(Node* node, int newValue){
    node = new Node(newValue);
}
//...
Node * n1 = new Node(-1);
Node * n2 = new Node(1);
reallocateRef(n1, 0); //   n1.value = 0 instead of -1
reallocateNoRef(n2,0); // n2.value is still 1 instead of 0

As for what it is good for, it depends on context, somtimes it plays a good role for helper function and other times you just might need it. Usually you just pass pointer by value, but if you need to change what it is pointing to then it is necessary to pass by reference. There could be similar reasoning for returning by value versus ref for pointers.

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

++C++ Primer Plus

mrnutty 761 Senior Poster

Instead of making two different functions, make the function take an argument and adjust

function createLink(linkId,ElemId){
    //saftey check
    //Create the link
    a = document.createElement('a');
    //Give the link a Id
    a.id = linkId;
    //Set the href
    a.href = "javascript:showHide(linkId,elemId)";
    //Create a variable for the link text
    var linkText = document.createTextNode('Visa mera information');
    //Append the text to the link
    a.appendChild(linkText);
    //Create a variable for the paragraph
    var elem = document.getElementById('show2')
    //Insert the text before the paragraph with the Id show2
    elem.parentNode.insertBefore(a,show2);
}
function populateLinks(){
    createLink('show1_link','show1');
    createLink('show2_link','show2');
}
mrnutty 761 Senior Poster

Yea you can greatly reduce it to something like so http://codepad.org/ZR7IGhKu

mrnutty 761 Senior Poster

First problem, your function name and variable are same, more specifically, newLink is declared as a function then inside, you have newLink as variable. Change the variable name to something else like newLinkElement.

mrnutty 761 Senior Poster

You need to start k at 1.

mrnutty 761 Senior Poster

Maybe three?

[h1 h2 h3 h4 h5 h6 h7 h8 h9]

Race 1: [h1 h2 h3] -> hi = 1st place finisher
Race 2: [h4 h5 h6] -> hj = 1st place finisher
Race 3: [h7 h8 h9] -> hk = 1st place finisher

[hi, hj, hk] would be the 3 fastest horse?