OK I realize that the last example was really simple, but understanding those basics are crucial to understanding the other more complex parts of a CNC machine.
To sit down and write your own complex program would be difficult, and take a lot of time. So what can we do? We turn to CAD/CAM applications to help us out!
CAD is "Computer Aided Design" and in a CAD application, such as Autocad or BobCad, or a hundred other options, you will DESIGN the part you want to make using lines and arcs, circles, squares, etc... Then you would load that design into a CAM, or "Computer Aided manufacturing" program where it would look at your design and, taking into consideration your router bit size and materials, it will generate the G-Code program for you. All you have to do after that is load that program into your CNC machine and cut away!
There are many CAD applications and there are just as many CAM applications, there are even some that do both the design and g-code generation, such as Mastercam. There are also many FREE CAD/CAM applications that you can use - it all depends on your budget and what you are trying to accomplish. Some programs are geared around making simple 2 dimensional parts, some are mainly for making signs or doing engraving, and some can make full 3D G-Code programs that mill out a 3D shape - of course HOW you cut that out on your machine is another topic that we will discuss when we get to the various types of CNC machines in the next few sections.