Thread: The C++ Programming Language(book) exercise troubles

  1. #1
    Registered User Daniel Primed's Avatar
    Join Date
    Jun 2005
    Posts
    13

    The C++ Programming Language(book) exercise troubles

    I’ve been learning C++ for the past year and feel as though there is something that I’m just so unsure about and I thought that this place might be able to help me out a bit.

    I have been learning C++ thru the book The C++ Programming Language by Bjarne Stroustrup. I firstly started off going through the book at a pretty fast pace and over my school holidays ended up around page 250. Then I figured that I ought to start again because I just couldn’t get the jist of the exercises. So I did and tried to go through a bit slower and more indepthly. This time around I used a few other resources to help me, such as your great tutorials. Anyways, I’ve currently been doing the exercises for chapter 6, p140. I managed to do okay in the last few chapters but these ones just seem so unreasonable. I’ve looked over the exercises and for quite a number of them it hasn’t gone through the concepts yet. Well it has gone over the concepts but not on what they are asking you to do. I just feel as though they are unreasonable. I remember in one of the past chapters you had to write the months in a year into structures yet it has never been through that before.

    I don’t know if its just me or what. I’ve been working at the book for a year and I feel as though I’m not getting too far thru the exercises. So I don’t know what to do. Since I figured that this book is quite popular I was hoping that someone else might be able to help shed some light on this. BTW keep in mind that I really like this book, its very indepth and is just an excellent resource. Also would I be right to assume that this book is substantially harder than the other C++ books out?

    I apologise if this thread is posted in the wrong section or this type of question has been asked many times. I don’t check out this forum much but I really should do.

  2. #2
    VA National Guard The Brain's Avatar
    Join Date
    May 2004
    Location
    Manassas, VA USA
    Posts
    903
    don't have the book.. but if you want, feel free to post an excercise.. post your best attempt at completing the excercise.. and maybe myself or others will be glad to offer you some tips and/or code to help you out
    • "Problem Solving C++, The Object of Programming" -Walter Savitch
    • "Data Structures and Other Objects using C++" -Walter Savitch
    • "Assembly Language for Intel-Based Computers" -Kip Irvine
    • "Programming Windows, 5th edition" -Charles Petzold
    • "Visual C++ MFC Programming by Example" -John E. Swanke
    • "Network Programming Windows" -Jones/Ohlund
    • "Sams Teach Yourself Game Programming in 24 Hours" -Michael Morrison
    • "Mathmatics for 3D Game Programming & Computer Graphics" -Eric Lengyel

  3. #3
    Registered User Daniel Primed's Avatar
    Join Date
    Jun 2005
    Posts
    13
    Sure but if anyone still knows about my other troubles than that might help.

    One of the exercises requires you to write the days of the month into a structure type via user input. Now this isn't exactly too hard to do IMO but up to what you've learnt it never goes through how to write to structures.

    Thanks.

  4. #4
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    That book is not exactly a beginner's book on how to learn the language. I suggest getting a book specifically targeted to teaching the language. The perfect choice for you is Accelerated C++ by Koenig and Moo. It is part of Stroustrup's In-Depth series, it is accelerated so it shouldn't be too boring for you since you've been going through the C++ bible already, and it is specifically designed to teach. Save TC++PL for reference and continue to go back to it and read it to learn, but get Accelerated C++ and follow it from start to finish as quickly as you are comfortable doing.

    For the structure problem, if you know how to write to classes, then you know how to write to structures, it is the same thing. If you don'tknow how to write to classes/structs, then look at overloading operator >>. A quick glance at that chapter shows that you might not be familiar with that yet. In that case, just read into local variables and then save the value of the variables to the structure.
    Last edited by Daved; 11-01-2005 at 11:43 AM.

  5. #5
    Registered User Daniel Primed's Avatar
    Join Date
    Jun 2005
    Posts
    13
    Sorry for the thread reserecting etc. etc. Australian times etc.

    Thanks, I have heard of that book before so I'll look into it. I also thought that I could write them into variables as well but I hadn't tried it. Thanks for the help.

  6. #6
    Registered User
    Join Date
    Apr 2003
    Posts
    2,663
    It is a good book, but as a reference--not to learn C++ from.

    Sure but if anyone still knows about my other troubles than that might help.
    The only trouble you mentioned is that you are having problems with structs.
    One of the exercises requires you to write the days of the month into a structure type via user input. Now this isn't exactly too hard to do IMO but up to what you've learnt it never goes through how to write to structures.
    That is trivial and doing something like that would be covered in any beginning C++ book(although they may skip structs since classes are identical except for one minor detail).
    Code:
    #include <iostream>
    #include <string>
    using namespace std;
    
    struct BookInfo
    {
    	string isbnNum; //can contain characters
    	double price;
    };
    
    int main()
    {
    	BookInfo book1;
    	cout<<"Enter the isbn number: ";
    	cin>>book1.isbnNum;
    	
    	cout<<"Enter the price: ";
    	cin>>book1.price;
    
    	cout<<"You entered: "<<endl
    		<<book1.isbnNum<<endl
    		<<book1.price<<endl;
    
                             
    	return 0;
    }
    What you need is a beginning C++ book. In two months, you'll be doing almost anything you want:

    http://www.amazon.com/gp/product/007...books&v=glance

    What you've been doing so far is like trying to learn to drive a car by reading a manual describing how all the parts of a car work: the alternator, the catalytic converter, the air conditioning system, the drive train, etc., and then getting behind the wheel and not knowing how to start the engine, and when that failed figuring that if you reread the manual, it would come to you.
    Last edited by 7stud; 11-01-2005 at 04:52 PM.

  7. #7
    Hardware Engineer
    Join Date
    Sep 2001
    Posts
    1,398
    Also would I be right to assume that this book is substantially harder than the other C++ books out?
    Like Daved said. It's NOT a book for beginners. It seems to be targeted at advanced computer science students or programming professionals. He assumes that you know a lot already. It's a bit like reading a book on brain surgery... You've got to know the biology, anatomy, and terminology to understand it! In one way that makes the book a little "outdated", because nowadays there are very few programmers at that level that don't already know quite a bit of C++. But, it's really cool to have the book written by the creator of C++!

    You can never have too many programming books! Since you already know the basics, here are a couple more book recommendations -

    Thinking In C++, by Bruce Eckel. It comes in two volumes that you can download free, or buy hard-copies. This book is written as a beginning C++ book for C programmers, but it makes a good 2nd C++ book too... Download it and judge for yourself.

    The C++ Standard Library, By Nicolai M. Josuttis. This book only covers the Standard Template Library, but it covers it completely. (And, it's much easier to read than Stroustrup. )

  8. #8
    Registered User
    Join Date
    Apr 2003
    Posts
    2,663
    Quote Originally Posted by DougDbug
    The C++ Standard Library, By Nicolai M. Josuttis. This book only covers the Standard Template Library, but it covers it completely. (And, it's much easier to read than Stroustrup. )
    That book was recommended in another thread, so I took a look at it. I don't like the way it starts off with a chapter on templating. Templating is intimidating stuff, and I think a lot of C++ programmers will take a look at that and decide the book isn't for them. Why not start off with the basics on how to use vectors? I think explaining how the STL containers are able to store different types using templates should be in the back of the book.
    Last edited by 7stud; 11-01-2005 at 04:58 PM.

  9. #9
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    Josuttis book is great as a reference. I've used it hundreds of times, and I've never read the first chapter.

    Also, as someone who has not read either book, I'd highly recommend Accelerated C++ over Schildt's book. Schildt is notorious for mistakes and using C style and techniques in C++ books, and just looking at the index on Amazon shows that this book doesn't even mention vectors. Accelerated C++ is written by "expert C++ programmers" rather than "expert book authors".

  10. #10
    Registered User
    Join Date
    Apr 2003
    Posts
    2,663
    I've paged through accelerated C++, and I didn't think it was a beginner's book. I've read Schildt's Beginning Java book, and I thought it was excellent.

  11. #11
    Registered User
    Join Date
    Apr 2003
    Posts
    2,663
    Quote Originally Posted by 7stud
    That book was recommended in another thread, so I took a look at it. I don't like the way it starts off with a chapter on templating. Templating is intimidating stuff, and I think a lot of C++ programmers will take a look at that and decide the book isn't for them. Why not start off with the basics on how to use vectors? I think explaining how the STL containers are able to store different types using templates should be in the back of the book.
    I took another look at "The C++ Standard Library" (Josuttis), and my initial impressions were mistaken. The book does start off with a discussion of templates, as well as explaining some other features of the Standard Library, but those introductory descriptions are short and the author keeps his explanations very simple with easy to understand examples. If the introductory discussion on the use of templates in the STL is still too frightening for you, you can go directly to chapter 5, which is an introduction to the STL containers and is probably what most people want to know about. And, there's not a template in sight.

    In chapter 5--I think the first 4 chapters are only about 30 pages long--he gives a few simple examples of the various containers, and his examples are so basic and clearly explained that anybody should be able to use one of the STL containers after only about 5 minutes of reading. The author also demonstrates the things you can do to containers with a few of the functions provided by the STL("algorithms" in STL speak). Once again, he keeps the examples very basic, and he explains them very clearly. The author says that chapter 5 is a brief overview of the STL, and the rest of the book will explain things in more depth.

    I spent about an hour in the bookstore, and I read most of the first 5 chapters, so the chapters are not long nor are they dense, and I would say chapter 5 alone may be worth the price of the book. I was impressed enough that now I plan on purchasing the book.

    Take a look for yourself and see what you think.
    Last edited by 7stud; 11-07-2005 at 02:01 AM.

  12. #12
    Registered User
    Join Date
    Apr 2003
    Posts
    2,663
    Quote Originally Posted by Daniel Primed
    Sure but if anyone still knows about my other troubles than that might help.

    One of the exercises requires you to write the days of the month into a structure type via user input. Now this isn't exactly too hard to do IMO but up to what you've learnt it never goes through how to write to structures.

    Thanks.
    I took a look at C++: A Beginner's Guide(2nd edition, Schildt) in the book store and it looks very similar to his "Java 2: A beginner's guide". I didn't see any errors in the first few chapters, and he covers input from the keyboard on p.19. Knowing that and what a struct is, you could easily do the exercise you seem to think is "unreasonable".

    I also paged through Stroustrup's book to look at the exercises in the early chapters, and they seem pretty easy--but of course that's all relative. Get a good beginning book and start doing some programming, and when you have trouble post your code and ask questions.
    Last edited by 7stud; 11-07-2005 at 02:00 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. programming exercise
    By mashour06 in forum C Programming
    Replies: 1
    Last Post: 06-01-2009, 06:22 AM
  2. Line of data input method
    By larry_2k4 in forum C Programming
    Replies: 2
    Last Post: 04-28-2009, 11:34 PM
  3. Creating a Sorted Linked List, Help Please!
    By larry_2k4 in forum C Programming
    Replies: 4
    Last Post: 04-28-2009, 01:12 AM
  4. Tutorial review
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 11
    Last Post: 03-22-2004, 09:40 PM
  5. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM