Learning C++ by Writing C++

Recommended Posts

So I have a class next semester where I need to learn C++. I'll be going through the class textbook too of course, but I hate textbooks because I learn much better by programming than taking notes. I understand there's got to be some reading just to understand the syntax, but I have trouble remembering much from a whole chapter before programming. I prefer to work with smaller bits of information and gradually expand.

So my question is, how could I learn C++ in smaller bits?

Share this post

Link to post
Share on other sites

Sounds like you need a good ol' fashioned cup of Don't Worry About It. If you're taking a programming class in school (especially at the university level), you'll have more than enough hands-on programming exercises, assignments/projects, and exams/quizzes to get the practice you need.


If the class is shaping up to be something that doesn't fit your learning style, work with your teacher/professor to get the right instruction for you (which could possibly mean dropping the course, to take it with a different professor.. but I'm getting WAY ahead of myself).

Edited by masskonfuzion

Share this post

Link to post
Share on other sites

Due to my experiences over the last four semesters, I think I'm just going to be transferring to another college. That likely won't be until after the next semester though.  I don't have the option to take any of my planned courses with anyone else, and I sign up for 12 credits or higher or my Financial Aid will be cut by more than $2000.

For instance, we had no chapter quizzes in Computer Architecture this semester despite our professor listing them in the syllabus. we're going to take our final in a few weeks and it will be the first test or quiz we've had in the class. Otherwise he just lectures, or gives fairly random assignments. Once he assumed we (who had no prior ARM programming experience) would be able to write iterative and recursive Fibonacci and Factorial programs in an ARM simulator without a MUL instruction (and many others) in two days. That professor is also my advisor, and he recommended the class to me, and overrode the class requirements despite it requiring content from two other classes I hadn't taken.  Many other classes and professors have had similar sorts of problems.

I don't like to complain about this sort of thing, but I'm really up against a wall here. I had to withdraw from two of four classes this semester to avoid failing grades, and that costs my folks they shouldn't have to spend. My parents also agree with my idea of transferring. 

I'm just trying to get a leg up for next semester here, and get ideas for how I can improve.

Edited by RidiculousName

Share this post

Link to post
Share on other sites

Hmm, that sounds like an incredibly disorganized teacher/department/curriculum, and/or one that lacks oversight.  If the professor isn't following his own syllabus, that's not a great sign.  Also, it's not customary for professors/advisers to be so liberal with pre-reqs (though it's not unheard of to recommend classes even if you haven't taken the pre-reqs).

Like you, I also had experiences with professors not knowing the prerequisites (mainly adjunct profs who weren't actually employees of the school).  That's a tough situation to be in, but it happens, unfortunately.  It sounds like you do need a more organized program, and one where hopefully the 'bad seed" teachers are held accountable and weeded out.

As for your original question -- how to learn C++ in small bits -- I don't have the definitive answer, but one thing I've done personally is to google for computer science lecture slides/assignments/exams that are available from other schools.  E.g. if you search for "Intro to C++ site:edu", you'll find all kinds of material (the "site:edu" bit limits the search results to those with a domain of .edu).  Your mileage may vary, but hopefully some of the results might fit your learning style.

I wish you the best of luck with your education.


Edited by masskonfuzion

Share this post

Link to post
Share on other sites

I see books as sources of information for look-up, rather than a collection of knowledge that I have to learn by heart.

That is, I don't necessarily need to know everything that's in it, but I do need to know what kind of information I can find in it. As a simple example, I would not bother about the precise syntax of a class definition, but I would remember it tells me "basic stuff about classes".

So whenever I have problem falling in the category "basic class problem", I know which book to pick to find the information I need.


It is, as you say, much easier to learn by doing, preferably before you have to make something "for real". I always try to  do a small private project beforehand. Anything that you pick is good, as long as it contains the matter you want to learn about. In a sense, whether the project succeeds isn't even relevant for learning.


As for your education, can't you express your concerns? If you get courses that don't work eg because you didn't have other courses, why not say so? If you got a course chosen, and it doesn't work as proposed, try to find an alternative solution by moving things around and discuss that. If you don't, you're the only person with the problem, so it's in your own interest to speak up.

Share this post

Link to post
Share on other sites

I learned C++ by doing the following. This is by no means how you should do it, it's just how my brain is wired.

1. http://www.learncpp.com/
I went to the above site. I read every single article that the person wrote on there, and I wrote my own articles on my personal blog

2. I took a C++ course at my university, and I asked as many questions as possible

3. I bought the book "Jumping into C++"
I believe that the author is the guy that manages www.cprogramming.com, however, I could be mistaken.  The book is cheap (relatively) and not that many pages (my kind of book).

4. I transferred to a position internally at my old company where they needed someone to do some C++ work.
I did this while I started my course at school in C++, and during this time I was reading the book that I mentioned above and I was writing articles on my blog about what I had learned from the site mentioned above, and from other sources.

Overall, regardless of what you know coming into it, with discipline and focus you can pull off anything you want to achieve. By the way, personal projects are your best friend, just try and keep the scope small.

Good luck.

Share this post

Link to post
Share on other sites

I followed the same road as Daniel pretty much.

I started with the worse C++ book in the world.  Teach yourself C++ in 24 hours.  24 hours I later signed up for a course at a local community college where I completed two semesters.  I transferred to a job within my company where C/C++ skills were needed.  I continued at the university level.

I have to say the best way to learn this language is by writing code in it.  Find a good book with plenty of exercises and a code examples.  When you start chapter one come up with a generic project of your own...a text based RPG for instance.  Every chapter read, do the exercises and then implement something you learned in the lesson into your project.  

Share this post

Link to post
Share on other sites

I also learn programming much better by writing programs. "A capar se aprende cortando cojones", my father would say. ("You learn how to castrate by cutting balls.") :)

I would use the textbook as a list of concepts to learn. Take a look at the table of contents and see what they cover first. Say it's basic integer types and input and output using <iostream> (I have no idea if that's a reasonable place to start, but whoever wrote the book probably has thought about the proper order more than I have). Challenge yourself to do something with that. For instance, try to write  a program that asks the user for 2 integers, adds them up and displays the result. You can learn how to write that however you learn best (tutorials, references, reading sample code...). Once you are satisfied that you understand the concepts, go back to the textbook and read the chapter. Chances are it will be very easy to understand at that point, and there might be things you didn't figure out yourself, or details that you had overlooked.

If you have a hard time getting started, or if you get stuck, or if you want some suggestions for a targeted challenge, you can post here, or you can PM me.


Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Forum Statistics

    • Total Topics
    • Total Posts
  • Similar Content

    • By Josheir
      void update() { if (thrust) { dx += cos(angle*DEGTORAD)*.02; dy += sin(angle*DEGTORAD)*.02; } else { dx*=0.99; dy*=0.99; } int maxSpeed = 15; float speed = sqrt(dx*dx+dy*dy); if (speed>maxSpeed) { dx *= maxSpeed/speed; dy *= maxSpeed/speed; } x+=dx; y+=dy; . . . } In the above code, why is maxSpeed being divided by the speed variable.  I'm stumped.
      Thank you,
    • By Benjamin Shefte
      Hey there,  I have this old code im trying to compile using GCC and am running into a few issues..
      im trying to figure out how to convert these functions to gcc
      static __int64 MyQueryPerformanceFrequency() { static __int64 aFreq = 0; if(aFreq!=0) return aFreq; LARGE_INTEGER s1, e1, f1; __int64 s2, e2, f2; QueryPerformanceCounter(&s1); s2 = MyQueryPerformanceCounter(); Sleep(50); e2 = MyQueryPerformanceCounter(); QueryPerformanceCounter(&e1); QueryPerformanceFrequency(&f1); double aTime = (double)(e1.QuadPart - s1.QuadPart)/f1.QuadPart; f2 = (e2 - s2)/aTime; aFreq = f2; return aFreq; } void PerfTimer::GlobalStart(const char *theName) { gPerfTimerStarted = true; gPerfTotalTime = 0; gPerfTimerStartCount = 0; gPerfElapsedTime = 0; LARGE_INTEGER anInt; QueryPerformanceCounter(&anInt); gPerfResetTick = anInt.QuadPart; } /////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////// void PerfTimer::GlobalStop(const char *theName) { LARGE_INTEGER anInt; QueryPerformanceCounter(&anInt); LARGE_INTEGER aFreq; QueryPerformanceFrequency(&aFreq); gPerfElapsedTime = (double)(anInt.QuadPart - gPerfResetTick)/aFreq.QuadPart*1000.0; gPerfTimerStarted = false; }  
      I also tried converting this function (original function is the first function below and my converted for gcc function is under that) is this correct?:
      #if defined(WIN32) static __int64 MyQueryPerformanceCounter() { // LARGE_INTEGER anInt; // QueryPerformanceCounter(&anInt); // return anInt.QuadPart; #if defined(WIN32) unsigned long x,y; _asm { rdtsc mov x, eax mov y, edx } __int64 result = y; result<<=32; result|=x; return result; } #else static __int64 MyQueryPerformanceCounter() { struct timeval t1, t2; double elapsedTime; // start timer gettimeofday(&t1, NULL); Sleep(50); // stop timer gettimeofday(&t2, NULL); // compute and print the elapsed time in millisec elapsedTime = (t2.tv_sec - t1.tv_sec) * 1000.0; // sec to ms elapsedTime += (t2.tv_usec - t1.tv_usec) / 1000.0; // us to ms return elapsedTime; } #endif Any help would be appreciated, Thank you!
    • By mister345
      Hi, I'm building a game engine using DirectX11 in c++.
      I need a basic physics engine to handle collisions and motion, and no time to write my own.
      What is the easiest solution for this? Bullet and PhysX both seem too complicated and would still require writing my own wrapper classes, it seems. 
      I found this thing called PAL - physics abstraction layer that can support bullet, physx, etc, but it's so old and no info on how to download or install it.
      The simpler the better. Please let me know, thanks!
    • By lawnjelly
      It comes that time again when I try and get my PC build working on Android via Android Studio. All was going swimmingly, it ran in the emulator fine, but on my first actual test device (Google Nexus 7 2012 tablet (32 bit ARM Cortex-A9, ARM v7A architecture)) I was getting a 'SIGBUS illegal alignment' crash.
      My little research has indicated that while x86 is fine with loading 16 / 32 / 64 bit values from any byte address in memory, the earlier ARM chips may need data to be aligned to the data size. This isn't a massive problem, and I see the reason for it (probably faster, like SIMD aligned loads, and simpler for the CPU). I probably have quite a few of these, particular in my own byte packed file formats. I can adjust the exporter / formats so that they are using the required alignment.
      Just to confirm, if anyone knows this, is it all 16 / 32 / 64 bit accesses that need to be data size aligned on early android devices? Or e.g. just 64 bit size access? 
      And is there any easy way to get the compiler to spit out some kind of useful information as to the alignment of each member of a struct / class, so I can quickly pin down the culprits?
      The ARM docs (http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.faqs/ka15414.html) suggest another alternative is using a __packed qualifier. Anyone used this, is this practical?
    • By Josheir
      In the following code:

      Point p = a[1]; center of rotation for (int i = 0; I<4; i++) { int x = a[i].x - p.x; int y = a[i].y - p.y; a[i].x = y + p.x; a[i].y = - x + p.y; }  
      I am understanding that a 90 degree shift results in a change like:   
      xNew = -y
      yNew = x
      Could someone please explain how the two additions and subtractions of the p.x and p.y works?
      Thank you,
  • Popular Now