Rewrite C++ code into Objective C

Posted by Phil_M on Stack Overflow See other posts from Stack Overflow or by Phil_M
Published on 2011-01-15T15:36:08Z Indexed on 2011/01/15 16:53 UTC
Read the original article Hit count: 161

Filed under:
|
|
|

Hello

I got some C++ Sourcecode that I would like to rewrite into Objective C. It would help me alot if someone could write me a header file for this Code. When I get the Headerfile I would be able to rewrite the rest of the Sourcecode.

It would be very nice if someone could help me please.

Thanks

I will poste the sourcecode here:

#include <stdlib.h>
#include <iostream.h>

#define STATES 5

int transitionTable[STATES][STATES];

// function declarations:
double randfloat                 (void);
int    chooseNextEventFromTable  (int current, int table[STATES][STATES]);
int    chooseNextEventFromTransitionTablee (int currentState);
void   setTable                  (int value, int table[STATES][STATES]);


//////////////////////////////////////////////////////////////////////////

int main(void) { 
   int i;

   // for demo purposes:
 transitionTable[0][0] = 0;
 transitionTable[0][1] = 20;
 transitionTable[0][2] = 30;
 transitionTable[0][3] = 50;
 transitionTable[0][4] = 0;
 transitionTable[1][0] = 35;
 transitionTable[1][1] = 25;
 transitionTable[1][2] = 20;
 transitionTable[1][3] = 30;
 transitionTable[1][4] = 0;
 transitionTable[2][0] = 70;
 transitionTable[2][1] = 0;
 transitionTable[2][2] = 15;
 transitionTable[2][3] = 0;
 transitionTable[2][4] = 15;
 transitionTable[3][0] = 0;
 transitionTable[3][1] = 25;
 transitionTable[3][2] = 25;
 transitionTable[3][3] = 0;
 transitionTable[3][4] = 50;
 transitionTable[4][0] = 13;
 transitionTable[4][1] = 17;
 transitionTable[4][2] = 22;
 transitionTable[4][3] = 48;
 transitionTable[4][4] = 0;

   int currentState = 0;
 for (i=0; i<10; i++) {
    std::cout << currentState << " ";
      currentState = chooseNextEventFromTransitionTablee(currentState);
   }
   return 0;
};


//////////////////////////////////////////////////////////////////////////


//////////////////////////////
//
// chooseNextEventFromTransitionTable -- choose the next note.
//

int chooseNextEventFromTransitionTablee(int currentState) {
 int targetSum   = 0;
 int sum         = 0;
 int targetNote  = 0;
 int totalevents = 0;
 int i;

 currentState = currentState % STATES;  // remove any octave value
 for (i=0; i<STATES; i++) {
  totalevents += transitionTable[currentState][i];
 }
 targetSum   = (int)(randfloat() * totalevents + 0.5);
 while (targetNote < STATES &&
     sum+transitionTable[currentState][targetNote] < targetSum) {
  sum += transitionTable[currentState][targetNote];
  targetNote++;
 }

 return targetNote;
}





//////////////////////////////
//
// randfloat -- returns a random number between 0.0 and 1.0.
//

double randfloat(void) {
   return (double)rand()/RAND_MAX;
}



//////////////////////////////
//
// setTable -- set all values in the transition table to the given value.
//

void setTable(int value, int table[STATES][STATES]) {
   int i, j;
   for (i=0; i<STATES; i++) {
      for (j=0; j<STATES; j++) {
         table[i][j] = value;
      }
   }
}

© Stack Overflow or respective owner

Related posts about iphone

Related posts about c++