Difference between revisions of "Programming:C++/Books/You Can Do It!: A Beginners Introduction to Computer Programming"

From WhyAskWhy.org Wiki
Jump to: navigation, search
m (Added note for header build steps; incomplete)
m (Added back space)
 
(8 intermediate revisions by the same user not shown)
Line 3: Line 3:
 
[[Category:Books]]
 
[[Category:Books]]
  
These are my notes from '''You Can Program in C++: A Programmer's Introduction''' <ref>ISBN 0470449586</ref>.
+
These are my notes for '''You Can Program in C++: A Programmer's Introduction''' <ref>ISBN 0470449586</ref>.
  
{{OldContentWarning}}
 
  
 +
== About the book ==
 +
 +
I'll attempt to give proper remarks for this book later, but suffice to say this book is ''well'' worth your time if you're learning C++.  I like how Francis pays particular attention to the pitfalls of the language.  He teaches you to always check for failing function calls (something a lot of "beginner books" fail to do) and teaches you how to use strings and vectors from the beginning in place of arrays.
 +
 +
 +
== What if you don't have the cd? ==
 +
 +
Before purchasing a copy of the book & CD, I checked out a copy of the book from a library and did not have the CD. This was ok because at the time the author made the contents available from his website. <ref name="ycdi-book-website">[http://www.spellen.org/youcandoit/resources.htm Official website for this book]</ref> Unfortunately [http://www.whyaskwhy.org/blog/1176/ the author's website hasn't been operational for some time], however on the same note the publisher ''has'' newer content available for download. <ref name="ycdi-book-publisher-website">[http://www.wiley.com/legacy/wileychi/glassborowc++/material.html Publisher's book page]</ref>
 +
 +
At the time the author's website had a broken link to Quincy 2002, <ref name="quincy-2002-homepage">[http://alstevens.com/quincy.html Quincy 2002 homepage]</ref> but I was able to find Quincy 2005 <ref name="quincy-2005-homepage">[http://www.codecutter.net/tools/quincy/ Quincy 2005 homepage]</ref> which is a newer version of it. Thankfully it is still available for download for those that want to use it. Since Francis Glassborow made the source for the '''FGW Library''' (aka, "Playpen") available, we can compile it using newer versions of [[wikipedia:Mingw|MinGW]] or different compilers altogether. That's great because I like to use [[wikipedia:Netbeans|Netbeans]] and the current MinGW and plan on trying out Visual Studio as I'm going through the book.
  
  
== About the book ==
+
=== Preparing to build the library ===
 +
 
 +
==== (Optional) Install Quincy ====
 +
 
 +
If you plan to use Quincy 2005, download it <ref name="quincy-2005-homepage" /> then proceed with the rest of these instructions.
 +
 
 +
==== Arranging the directory structure ====
 +
 
 +
# Download the <code>windows_tutorial.zip</code> file from the publisher's website for the book <ref name="ycdi-book-publisher-website" /> and extract to a temporary location.
 +
# Move all folders inside of <code>windows_tutorial</code> to <code>C:\tutorial</code>.
 +
# Move all files from the <code>C:\tutorial\source</code> directory to the <code>C:\tutorial\fgw_headers</code> directory, choosing to overwrite existing files.
 +
# Remove the <code>C:\tutorial\source</code> directory (should have nothing inside of it).
 +
# Remove the <code>C:\tutorial\libraries</code> directory as we're going to build a newer library file. Aside from the volume serial number, you should see the following:
 +
<pre>
 +
C:\tutorial>tree /F
 +
Folder PATH listing
 +
Volume serial number is 38B9-1B1A
 +
C:.
 +
├───chapter_1
 +
├───chapter_10
 +
├───chapter_11
 +
├───chapter_12
 +
├───chapter_13
 +
├───chapter_14
 +
├───chapter_15
 +
├───chapter_16
 +
├───chapter_17
 +
├───chapter_18
 +
├───chapter_2
 +
├───chapter_3
 +
├───chapter_4
 +
├───chapter_5
 +
├───chapter_6
 +
├───chapter_7
 +
├───chapter_8
 +
├───chapter_9
 +
└───fgw_headers
 +
        adler32.c
 +
        colournames.h
 +
        deflate.c
 +
        deflate.h
 +
        fgw_text.h
 +
        flood_fill.cpp
 +
        flood_fill.h
 +
        infblock.c
 +
        infblock.h
 +
        infcodes.c
 +
        infcodes.h
 +
        inffast.c
 +
        inffast.h
 +
        inffixed.h
 +
        inflate.c
 +
        inftrees.c
 +
        inftrees.h
 +
        infutil.c
 +
        infutil.h
 +
        keyboard.h
 +
        libfgw.a
 +
        line_drawing.cpp
 +
        line_drawing.h
 +
        makefile
 +
        minipng.cpp
 +
        minipng.h
 +
        mouse.h
 +
        playpen.cpp
 +
        playpen.h
 +
        point2d.cpp
 +
        point2d.h
 +
        point2dx.cpp
 +
        point2dx.h
 +
        shape.cpp
 +
        shape.h
 +
        trees.c
 +
        trees.h
 +
        winplaypen.gpj
 +
        zconf.h
 +
        zlib.h
 +
        zutil.c
 +
        zutil.h
 +
</pre>
 +
 
 +
 
 +
===== (Optional) Checkout a copy of the source code from public Subversion respository =====
 +
 
 +
As an alternative to downloading the zip file and arranging the directories as mentioned in the preceding instructions, you can check out a copy of the source code from an unofficial public Subversion repository. Provided you have Subversion installed, you should end up with the same content in <code>C:\tutorial</code> as you would downloading the zip file from the publisher's site and arranging the directory content.
 +
 
 +
# Open a command prompt
 +
# <code>mkdir C:\tutorial</code>
 +
# <code>cd C:\tutorial</code>
 +
# <code>svn co http://projects.whyaskwhy.org/svn/fgw_library/trunk/ .</code>
 +
# <code>prep.bat</code>
  
I'll attempt to give proper remarks for this book later, but suffice to say this book is ''well'' worth your time if you're learning C++.  I like how Francis pays particular attention to the pitfalls of the language.  He teaches you to always check for failing function calls (something a lot of "beginner books" fail to do) and teaches you how to use strings and vectors from the beginning in place of arrays.
 
  
 +
==== Updating your System Path variable ====
  
== Getting by without the cd ==
+
You should only follow the directions for one of these, not both.
  
If you're like me and checked this out from the library you probably did not get a copy of the cd.  I visited the book's website <ref name="ycdi-book-website">[http://www.spellen.org/youcandoit/resources.htm Official website for this book]</ref> and downloaded the material from there. What didn't work for me was the link to [http://alstevens.com/quincy.html Quincy 2002].
+
===== Quincy 2005 =====
  
Instead I visited Google and searched for it.  I found that [http://www.codecutter.net/tools/quincy/ Quincy 2005] was available so I grabbed that. Thankfully Francis made the source for the graphics library used in the book available so it could be compiled for other versions of Mingw and even different tool-kits entirely.
+
If you're using Quincy 2005 <ref name="quincy-2005-homepage" />, modify your PATH by following these directions.
  
{{InfoBox|info|Make sure to keep a copy of the <code>fgwlib.zip</code> file in a safe location in case you mess up any of the steps. This way you can unzip it and try again.}}
+
# Open a command prompt (Start->Run->cmd->Enter)
 +
# <code>set path=%path%;C:\Program Files\quincy\MinGW\bin</code>
  
=== Building the fgw library for use with Quincy 2005 ===
+
===== Current MinGW & MSYS release =====
  
# Download Quincy 2005 v1.3 and install it.
 
# Download all archives from the book's website <ref name="ycdi-book-website" />.
 
# Run <code>tutorial.exe</code>, extract to the folder where the tutorial already resides.  It should create a folder called <code>tutorial</code>. For the rest of the directions I'll refer to this folder as the <code>tutorial</code> folder. I'll pretend it's located at <code>C:\Documents and Settings\deoren\Desktop\ycdi_files</code>
 
# Open the <code>tutorial</code> folder and look for a <code>fgw_headers</code> folder.
 
# Copy <code>C:\Program Files\quincy\mingw\lib\COMPLETE_THIS_PATH\libgdi32.a</code> and replace the <code>libgdi32.a</code> file within the <code>fgw_headers</code> folder.
 
# Extract <code>fgwlib.zip</code> and copy the updated <code>fgw_text.h</code> header file to <code>fgw_headers</code>.  Choose to overwrite the older file.
 
# Extract library_source.zip.  This should give you a folder called source4net.
 
 
# Open a command prompt (Start->Run->cmd->Enter)
 
# Open a command prompt (Start->Run->cmd->Enter)
# <code>set path=%path%;C:\Program Files\quincy\mingw\bin</code>
+
# <code>set PATH=%PATH%;C:\MinGW\bin;C:\MinGW\msys\1.0\bin</code>
# <code>cd C:\Documents and Settings\deoren\Desktop\ycdi_files\source4net</code>
+
 
# <code>make</code>
+
 
# Copy <code>libfgwz.a</code> to <code>fgw_headers</code>
+
 
# Delete <code>fgwlib.a</code> so there is no confusion which file to add to your projects.
+
==== Copy libgdi32.a to fgw_headers directory ====
# Every time the book tells you to add <code>fgwlib.a</code> to your project, add your newly compiled <code>libfgwz.a</code> instead.
+
 
 +
===== Quincy 2005 =====
 +
 
 +
Copy <code>C:\Program Files\quincy\MinGW\lib\libgdi32.a</code> to <code>C:\tutorial\fgw_headers\libgdi32.a</code> and replace any existing copy if it exists.
 +
 
 +
===== Current MinGW & MSYS release =====
  
 +
Copy <code>C:\MinGW\lib\libgdi32.a</code> to <code>C:\tutorial\fgw_headers\libgdi32.a</code> and replace any existing copy if it exists.
  
=== Building the fgw library using the latest MinGW and MSYS tools ===
 
  
{{InfoBox|warning|These steps assume you've previously built the library and already have the <code>tutorial.exe</code> contents extracted and the library source files updated. I'll need to clean up these directions so they make better sense.}}
+
=== Building the library ===
  
# Download and install the latest MinGW and MSYS tools
+
# Open a command prompt
# Either permanently modify the PATH variable, or temporarily modify it with <code>set PATH=%PATH%;C:\MinGW\bin;C:\MinGW\msys\1.0\bin</code>
+
# <code>cd C:\tutorial\fgw_headers</code>
# <code>cd \tutorial\fgw_headers</code>
 
 
# <code>rmdir /s /q Release</code>
 
# <code>rmdir /s /q Release</code>
 
# <code>mkdir Release</code>
 
# <code>mkdir Release</code>
Line 52: Line 149:
 
# <code>make clean</code>
 
# <code>make clean</code>
 
# <code>make</code>
 
# <code>make</code>
# <code>cp Release/libfgwz.a .</code>
+
# <code>cp Release/libfgw.a .</code>
# Configure IDE as appropriate
+
 
 +
 
 +
=== Using the new library ===
 +
 
 +
Every time the book tells you to add <code>fgwlib.a</code> to your project, reference <code>C:\tutorial\fgw_headers\libfgw.a</code> instead.
 +
 
 +
== References ==
  
 
<references />
 
<references />

Latest revision as of 20:45, 29 July 2012


These are my notes for You Can Program in C++: A Programmer's Introduction [1].


About the book

I'll attempt to give proper remarks for this book later, but suffice to say this book is well worth your time if you're learning C++. I like how Francis pays particular attention to the pitfalls of the language. He teaches you to always check for failing function calls (something a lot of "beginner books" fail to do) and teaches you how to use strings and vectors from the beginning in place of arrays.


What if you don't have the cd?

Before purchasing a copy of the book & CD, I checked out a copy of the book from a library and did not have the CD. This was ok because at the time the author made the contents available from his website. [2] Unfortunately the author's website hasn't been operational for some time, however on the same note the publisher has newer content available for download. [3]

At the time the author's website had a broken link to Quincy 2002, [4] but I was able to find Quincy 2005 [5] which is a newer version of it. Thankfully it is still available for download for those that want to use it. Since Francis Glassborow made the source for the FGW Library (aka, "Playpen") available, we can compile it using newer versions of MinGW or different compilers altogether. That's great because I like to use Netbeans and the current MinGW and plan on trying out Visual Studio as I'm going through the book.


Preparing to build the library

(Optional) Install Quincy

If you plan to use Quincy 2005, download it [5] then proceed with the rest of these instructions.

Arranging the directory structure

  1. Download the windows_tutorial.zip file from the publisher's website for the book [3] and extract to a temporary location.
  2. Move all folders inside of windows_tutorial to C:\tutorial.
  3. Move all files from the C:\tutorial\source directory to the C:\tutorial\fgw_headers directory, choosing to overwrite existing files.
  4. Remove the C:\tutorial\source directory (should have nothing inside of it).
  5. Remove the C:\tutorial\libraries directory as we're going to build a newer library file. Aside from the volume serial number, you should see the following:
C:\tutorial>tree /F
Folder PATH listing
Volume serial number is 38B9-1B1A
C:.
├───chapter_1
├───chapter_10
├───chapter_11
├───chapter_12
├───chapter_13
├───chapter_14
├───chapter_15
├───chapter_16
├───chapter_17
├───chapter_18
├───chapter_2
├───chapter_3
├───chapter_4
├───chapter_5
├───chapter_6
├───chapter_7
├───chapter_8
├───chapter_9
└───fgw_headers
        adler32.c
        colournames.h
        deflate.c
        deflate.h
        fgw_text.h
        flood_fill.cpp
        flood_fill.h
        infblock.c
        infblock.h
        infcodes.c
        infcodes.h
        inffast.c
        inffast.h
        inffixed.h
        inflate.c
        inftrees.c
        inftrees.h
        infutil.c
        infutil.h
        keyboard.h
        libfgw.a
        line_drawing.cpp
        line_drawing.h
        makefile
        minipng.cpp
        minipng.h
        mouse.h
        playpen.cpp
        playpen.h
        point2d.cpp
        point2d.h
        point2dx.cpp
        point2dx.h
        shape.cpp
        shape.h
        trees.c
        trees.h
        winplaypen.gpj
        zconf.h
        zlib.h
        zutil.c
        zutil.h


(Optional) Checkout a copy of the source code from public Subversion respository

As an alternative to downloading the zip file and arranging the directories as mentioned in the preceding instructions, you can check out a copy of the source code from an unofficial public Subversion repository. Provided you have Subversion installed, you should end up with the same content in C:\tutorial as you would downloading the zip file from the publisher's site and arranging the directory content.

  1. Open a command prompt
  2. mkdir C:\tutorial
  3. cd C:\tutorial
  4. svn co http://projects.whyaskwhy.org/svn/fgw_library/trunk/ .
  5. prep.bat


Updating your System Path variable

You should only follow the directions for one of these, not both.

Quincy 2005

If you're using Quincy 2005 [5], modify your PATH by following these directions.

  1. Open a command prompt (Start->Run->cmd->Enter)
  2. set path=%path%;C:\Program Files\quincy\MinGW\bin
Current MinGW & MSYS release
  1. Open a command prompt (Start->Run->cmd->Enter)
  2. set PATH=%PATH%;C:\MinGW\bin;C:\MinGW\msys\1.0\bin


Copy libgdi32.a to fgw_headers directory

Quincy 2005

Copy C:\Program Files\quincy\MinGW\lib\libgdi32.a to C:\tutorial\fgw_headers\libgdi32.a and replace any existing copy if it exists.

Current MinGW & MSYS release

Copy C:\MinGW\lib\libgdi32.a to C:\tutorial\fgw_headers\libgdi32.a and replace any existing copy if it exists.


Building the library

  1. Open a command prompt
  2. cd C:\tutorial\fgw_headers
  3. rmdir /s /q Release
  4. mkdir Release
  5. bash
  6. make clean
  7. make
  8. cp Release/libfgw.a .


Using the new library

Every time the book tells you to add fgwlib.a to your project, reference C:\tutorial\fgw_headers\libfgw.a instead.

References