You Can Program in C++

Answers to the Practical Exercises from the book "You Can Program in C++ A Programmer's Introduction"


I decided to learn C++ some time ago. I have read several books on the subject. Unfortunately, after completing the books I have never been able to progress the skills that I learned. I have decided to try again, but a little differently this time. I bought Francis Glassborow's book and recieved it on New Years Eve 2008. So this is a New Year and a new attempt to turn myself into a good C++ programmer.

Now, as I work through the exercises in the book, I will publish my solutions on this website. I am a regular reader of the newsgroup alt.comp.lang.learn.c-c++ and so will get help from the experts when I need it. I also hope that by sharing my coding troubles with the newsgroup, I will learn and develop as a programmer.

Why is this website here?

Well, I have often lost my work if I had trouble with a hard disc and not backed it up. I have also got some free space provided by my ISP. In addition, I thought it would be fun to learn how to put together a basic website and doing so would help keep me motivated in studying the language. Finally, I know that there are a lot of people who will also be starting along the road of learning C++ using this book. This website will hopefully give encouragement and support to novice programmers while working through the book.

I will focus on regularly posting up my solutions to all the exercises, together with commentary on certain interesting aspects of C++.

What tools should I use?

The book recommends MinGW Developer Studio or Jgrasp. The advantage of using the recommended IDE is that you can just refer to the book to check that everything you do is exactly as has been instructed. I experimented a little with these IDEs and decided against using them. MinGW is no longer supported and I found that it sometimes crashed on my linux system, though it worked perfectly in windows xp. I just didn't like jgrasp - nothing personal. I played with a few other IDEs while working through the getting started chapter. I liked Anjuta because it felt stable. But it did not feel very intuitive for me.  I think KDevelop is also a good IDE.

As a novice programmer, I believe that it's very important to be able to use a IDE that has good documentation and support available. It is of course a matter of personal choice as to what environment you feel comfortable with.

codeblocks.png

In the end, I decided that I would use Code::blocks. It's specially a IDE for C++ development and it has a thriving user community to give advice and support. Here is a link to the official website Codeblocks

book cover image

Note the striking similarities between the book cover and the codeblocks logo.


The important step in getting started is to compile the source code for the fgw library, which is found on the CD-ROM that accompanies the book. This creates a static library needed to complete some of the exercises. In codeblocks, I found that I was getting an error with one of the library source files. I sought help from usenet and slightly modified the file. This enabled me to compile the library easily. You can find the un-edited full source code for the library here C++ Resources

If you dont have the book yet, I recommend you get it from Amazon. It's good value for money and it includes the full CD-ROM. This website is specifically written to support readers as they progress through the book, though the solutions may be useful even if you are following a different text on C++.

Chapter 1 contains guidance to getting the reader familiar with his or her IDE and instructions for compiling the fgw library and a 'hello world' program. I could not usefully add to this, so I have started at Chapter 2 and will work from there.

Chapter 1 contains no exercises.

Chapter 2 exercises

Chapter 3 exercises

Chapter 4 contains no exercises.

Chapter 5 exercises