1. Home
  2. Computing & Technology
  3. C / C++ / C#

Latest Programming Tutorials

About C, C++ and C# brings you the latest programming tutorials, a part work built up week by week. Choose C, C++ or C# or all three.

Latest Programming Tutorials

David's C / C++ / C# Blog

A Truly Open Cell Phone - Cell Phone

Tuesday July 8, 2008
Openmoko Mobile PhoneOpenMoko Neo FreeRunner is a cell phone that was launched last week though availability is still pretty limited. Whether it sets the world on fire or not (and I'm hoping it does), it will make a bit of an impact because it is truly open to the point where the manufacturer is happy for you to open the case and you can even flash the ROM. It runs Linux and has a USB cable included so you can hook into your Linux box and upload onto it directly.

The hardware includes 128MB SDRAM along with 256MB of Flash memory and a 480x640 2.8" touch screen. Add to that Wifi, Bluetooth and Tri-band GSM so in theory I could just add a sim card (cost £5 in the UK), add some credit and start using it as a phone. It has a 400 MHZ CPU with 2D and 3D accelerated graphics and includes 2 accelerometers and AGPS. Being Linux of course you can write anything you want to run on it and the OpenMoko wiki is a great place to start. There's an established community of hackers and plenty of links to useful information.

It occurs to me that having this hardware in an open package would make for some interesting development (assuming the market is there). You could use cryptography to send secure txt messages. Use the gps for location based games (and the accelerometers for using the phone as a joy stick). Or you could just use it as a mobile phone!

C++ Programming Puzzle

Monday July 7, 2008
Here's some source code for a class to manage planets in an astronomy program. A planet is created with co-ordinates (assume those are correct- the values are not the problem) and a name. So I've added Earth. This code works BTW, it prints out Earth. But it's flawed. How many bugs can you spot?

#include <iostream>
#include <string>

using namespace std;

class Planet
  {
  private:
    float x,y,z;
    char *PlanetName;
  public:
    Planet(float X, float Y, float Z, char * NewName ) ;
    void SetPlanetName( char * NewName ) ;
    char * GetPlanetName() {return PlanetName;};
  };

Planet::Planet(float X,float Y, float Z, char * NewName )
: x(X),y(Y),z(Z)
  {
    SetPlanetName( NewName ) ;
  }

void Planet::SetPlanetName( char * NewName )
  {
    PlanetName = new char[strlen(NewName) + 1];
    strcpy(PlanetName, NewName) ;
  }

int main(int argc, char* argv[])
 {
    Planet Earth(10789.0f,102345.4f,10234.23f,"Earth") ;
    cout << Earth.GetPlanetName() << endl;
    return 0;
  }

Answer on Wednesday.

Explore C / C++ / C#

More from About.com

  1. Home
  2. Computing & Technology
  3. C / C++ / C#

©2008 About.com, a part of The New York Times Company.

All rights reserved.