There's actually a book which answers exactly that question:
How to Design Programs – An Introduction to Programming and Computing by Matthias Felleisen, Robert Bruce Findler, Matthew Flatt, and Shriram Krishnamurthi
They are currently working on a second edition, and after that, a second volume (How to Design Components).
The really cool thing about this book is that it gives you a set of recipes for designing programs. In other words, it gives you step-by-step instructions which you can (semi-)mindlessly follow in order to design a program.
Or, to put it yet another way: it contains a set of programs for writing programs, so that you don't have to figure out how to write a program: the authors figured it out for you!