title: Rewrite C++ code into Objective C
body: <p>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.</p>
  
  <p>It would be very nice if someone could help me please.</p>
  
  <p>Thanks</p>
  
  <p>I will poste the sourcecode here:</p>
  
  <pre><code>#include &lt;stdlib.h&gt;
  #include &lt;iostream.h&gt;
  
  #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&lt;10; i++) {
      std::cout &lt;&lt; currentState &lt;&lt; " ";
        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&lt;STATES; i++) {
    totalevents += transitionTable[currentState][i];
   }
   targetSum   = (int)(randfloat() * totalevents + 0.5);
   while (targetNote &lt; STATES &amp;&amp;
       sum+transitionTable[currentState][targetNote] &lt; 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&lt;STATES; i++) {
        for (j=0; j&lt;STATES; j++) {
           table[i][j] = value;
        }
     }
  }
  </code></pre>
  
  <p><strong>Update</strong></p>
  
  <p>I'm not only compiling the header file there is another file i'm compiling too </p>
  
  <p>SourceCode:</p>
  
  <pre><code>//
  //  markovThreadsChainsViewController.m
  //  markovThreadsChains
  //
  //  Created by Philippe Mokrzycki on 15.01.11.
  //  Copyright 2011 TGM. All rights reserved.
  //
  
  #import "markovThreadsChainsViewController.h"
  #import "markov.h"
  //#import "markovChainOC.h"
  
  @implementation markovThreadsChainsViewController
  
  @synthesize mcValueLabel, threadStartGenerateButton, threadStopGenerateButton;
  
  - (IBAction) startThreadGen:(UIButton *)sender{
      threadStopGenerateButton.hidden=NO;
      threadStartGenerateButton.hidden=YES;
      mcValueLabel.text = @"0";
  
      currentState=0;
  
  //  markovChainOC *mCobc = [[markovChainOC alloc]init];
  
  //  [mCobc setCurrentState:0];
      [NSThread detachNewThreadSelector:@selector(startThreading)  toTarget:self withObject:nil];
  }
  
  - (IBAction) stopThreadGen:(UIButton *)sender{
      threadStopGenerateButton.hidden=YES;
      threadStartGenerateButton.hidden=NO;
      [NSThread detachNewThreadSelector:@selector(stopThreading) toTarget:self withObject:nil];
  }
  
  - (void) startThreading {
      NSAutoreleasePool *pool = [[NSAutoreleasePool alloc]init];
  
      [NSThread sleepForTimeInterval:3];
      [self performSelectorOnMainThread:@selector(markovGen) withObject:nil waitUntilDone:NO];
      [pool release];
  }
  
  - (void) stopThreading {
      [NSThread cancelPreviousPerformRequestsWithTarget:self];
  }
  
  - (void)markovGen{
      transitionTable[0][0] = 25;
      transitionTable[0][1] = 25;
      transitionTable[1][0] = 25;
      transitionTable[1][1] = 25;
  
  //  int actualValue = [mCobc getCurrentState];
  
      int actualValue = currentState;
      mcValueLabel.text = [NSString stringWithFormat:@"%", actualValue];
      currentState = chooseNextEventFromTransitionTablee(currentState);
      [NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(markovGen) userInfo:nil repeats:NO];
  
  }
  
  
  /*
  // The designated initializer. Override to perform setup that is required before the view is loaded.
  - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
      if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
          // Custom initialization
      }
      return self;
  }
  */
  
  /*
  // Implement loadView to create a view hierarchy programmatically, without using a nib.
  - (void)loadView {
  }
  */
  
  
  /*
  // Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
  - (void)viewDidLoad {
      [super viewDidLoad];
  }
  */
  
  
  /*
  // Override to allow orientations other than the default portrait orientation.
  - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
      // Return YES for supported orientations
      return (interfaceOrientation == UIInterfaceOrientationPortrait);
  }
  */
  
  - (void)didReceiveMemoryWarning {
      // Releases the view if it doesn't have a superview.
      [super didReceiveMemoryWarning];
  
      // Release any cached data, images, etc that aren't in use.
  }
  
  - (void)viewDidUnload {
      // Release any retained subviews of the main view.
      // e.g. self.myOutlet = nil;
  }
  
  
  - (void)dealloc {
      [mcValueLabel release];
      [threadStartGenerateButton release];
      [threadStopGenerateButton release];
  //  [mCobc release];
      [super dealloc];
  }
  
  @end
  </code></pre>