Last updated on 26th March 2014
I taught this course to Ist M.Sc. (Maths) students twice or thrice. The last time I taught the course would have been in 2008. The class size was typically around 20 to 25 students.
The course content consists of:
- Powerpoint presentations
- [A few presentation slides have only the topic names and corresponding sections in the book. If time permits and there is a demand I am willing to consider expanding these few slides to be more like the other explanatory slides.]
- Sample programs (some created by me and some from the course book)
- [For sample/example programs created by me, as WordPress does not permit .cpp/.cc files to be uploaded I have converted .cpp/.cc files to pdf and then uploaded them. I have also provided an external link to zip files containing these sample/example programs in original file format.]
The course is based on the book, “C++ Primer, Fourth Edition” by Stanley B. Lippman, Josee Lajoie & Barbara E. Moo. It is published by Pearson Education, http://www.pearsonhighered.com/educator/product/C-Primer/9780201721485.page. Please note that the fourth edition is reported as out of print in the above link and that the newer fifth edition of the book is available. However, pdf versions of the fourth edition book, as of now, can be easily obtained using Google search. The fourth edition book example source code can be downloaded from:
Windows format files: http://www.informit.com/content/images/0201721481/sourcecode/MS_files.zip
Linux format files: http://www.informit.com/content/images/0201721481/sourcecode/gnu_files.tar.gz
If there is demand and time permits, I am willing to consider upgrading this course content to the fifth edition sometime. I have not yet read the fifth edition book in detail and so I do not know whether most of this course content applies to that edition too. The material of this course does not cover the new C++ 11 standard. The fifth edition covers the new C++ 11 standard.
The course has a pre-requisite of the student having learnt ‘C’ programming. It focuses only on those aspects of C++ which are not present in ‘C’. [In many Indian colleges and universities, I believe, students are first taught ‘C’ programming over one or two semesters followed by a semester of C++. This is the environment in which I taught the course.] Further, it explains C++ concepts (over and above ‘C’ concepts) using relatively simple examples and assignments. So a Sales_item class or a string class is used as the example and/or assignment class instead of a somewhat more complicated graphics class. Such an approach I thought was suitable for the I M.Sc. (Maths) class that I taught as the institution did have some significant constraints in lab. time availability for programming work for those students.
For students who would like to do/follow/go through a more rigorous and perhaps time-consuming C++ course, taught at the freshman (first) year in a USA engineering college/university which does not seem to presume prior knowledge of ‘C’ language part of C++, information including links are provided about one such course designed by Prof. Bjarne Stroustrup, creator of C++, towards the end of this post.
Further, please note that, as a first step, I have focused on putting up the course content used by me to teach this course in the deemed university in Andhra Pradesh, India, suitably modified, on this blog. As part of the minor modifications for putting it up on this publicly accessible blog, some errors may have crept in. I have not checked all the modifications for accuracy (due to other demands on my time). If this course (on this blog) does get utilized by students then the errors in the modified part will come to light and will get fixed by me (or others). I think that is a better way of investing my (and others) time for fixing any errors in this course (on this blog).
The course covers the following topics.
1) Introduction to C++
- Importance of C++
- First C++ program
Powerpoint slides and example source file(s) in pdf format: Introduction.ppt, Introduction-2.ppt, Introduction-3.ppt and enumtest.cpp.pdf. Example source file(s) (my own, if I recall correctly, and so different from book example code) in original file format – zip file.
2) Introduction to C++ Classes
- Notion of Class
- How to use a class (as against how to create a class)
- Using member functions of a class
- Using operators of a class
Powerpoint slides: Classes-Introduction.ppt
3) C++ Standard Library
- Std namespace
- Using string class
- Using vector class (template)
- Using ifstream & ofstream classes
Powerpoint slides and example source file(s) in pdf format: stdLibrary1.ppt, stdLibrary2.ppt, fileio.cpp.pdf, filecin.cpp.pdf and countWordNLine.cpp.pdf. Example source file(s) (my own, if I recall correctly, and so different from book example code) in original file format – zip file.
4) Dynamic Memory
- Heap & Stack
- new expression
- delete expression
- Dynamic array allocation & deletion
Powerpoint slides and example source file(s) in pdf format: DynamicMemory.ppt, DynamicMemory2.ppt, newdelete.cpp.pdf, ccharstr.cpp.pdf and newsimple.cpp.pdf. Example source file(s) (my own, if I recall correctly, and so different from book example code) in original file format – zip file.
- Quick mention of C ‘functions’
- Reference parameters
- Default arguments
- Inline functions
- Class Member functions
- Scope of functions (Global & Class)
- Overloaded functions
- Function matching & Function Overload resolution
- Argument conversions
Powerpoint slides and example source file(s) in pdf format: Functions.ppt, Functions2TopicsOnly.ppt, Functions3.ppt, swap1.cpp.pdf, strparm1.cpp.pdf, swap2.cpp.pdf, strparm2.cpp.pdf, fnscope.cpp.pdf, fnscopeErr.cpp.pdf, ovlfns.cpp.pdf, ovlfns2.cpp.pdf and ovlfnsconv.cpp.pdf. Example source file(s) (my own, if I recall correctly, and so different from book example code) in original file format – zip file.
6) Classes (Creating own classes as against using supplied classes)
- Data Abstraction
- Data Encapsulation (Data Hiding)
- Class Definition; Difference between class definition and class declaration
- static class members
Powerpoint slides and example source file(s) in pdf format: Classes2TopicsOnly.ppt, g.cpp.pdf and static.cpp.pdf. Example source file(s) (my own, if I recall correctly, and so different from book example code) in original file format – zip file.
7) Copy Control, Assignment Operator and Destructor
- Copy constructor
- Copy initialization
- Synthesized copy constructor
- Argument copy of class object
- Copy of object returned by a function
- Own copy constructor; when is it necessary?
- Assignment operator overload
- Synthesized assignment operator
- Own assignment operator overload; when is it necessary?
- Shallow Copy vs. Deep Copy
- Quick mention of other operator overloads (+, -, == etc.)
- What is a destructor?
- When does it get called?
- Destructor syntax
- Synthesized destructor
- Own destructor; when is it necessary?
- Rule of Three
Powerpoint slides and example source file(s) in pdf format:
ClassesCopyControl.ppt, ClassesCopyControl2.ppt, ClassesCopyControl3.ppt,
return.cpp.pdf, ourstring.cpp.pdf, ourstring2.cpp.pdf, ourstring3.cpp.pdf,
ourstringNoCC.cpp.pdf, ourstringAssignOp.cpp.pdf, ourstringAssignOp2.cpp.pdf,
ourstring4.cpp.pdf and ourstring5.cpp.pdf. Example source file(s) (my own, if I recall correctly, and so different from book example code) in original file format – zip file.
- Simple inheritance example
- Derived class & Base class
- Invoking methods through pointers
- Invoking method through base class pointer or reference
- Virtual functions
- Inheritance hierarchy
- Dynamic binding/Polymorphism
- Pure virtual functions
Powerpoint slides and example source file(s) in pdf format: Inheritance.ppt, Inheritance2.ppt, Inheritance3.ppt, inherit.cpp.pdf, inherit1.cpp.pdf, inherit2.cpp.pdf, inherit3.cpp.pdf, shapes1.cpp.pdf, shapes2.cpp.pdf, shapes3.cpp.pdf and vecshapes1.cpp.pdf. Example source file(s) (my own, if I recall correctly, and so different from book example code) in original file format – zip file.
9) Exception Handling
- Exceptions are run-time anomalies
- ‘C’ program error handling; Painful
- Exceptions to the rescue in C++
- What if there is no try-catch?
- Java, C# exception usage
- Exception class hierarchy
- Multiple catch handlers
- Functions exited during search for an exception handler
- Multiple try-catch
Powerpoint slides and example source file(s) in pdf format: Exceptions.ppt, Modexception_example.cpp.pdf, except2.cpp.pdf, except3.cpp.pdf and except4.cpp.pdf. Example source file(s) (my own, if I recall correctly, and so different from book example code) in original file format – zip file.
10) More on Std. Library
- Container classes & Generic algorithms
- Sequential Containers & Associative Containers
- Std. Library design
- map; how to use it
- iterators; vector & map iterators
- set; how to use it
Powerpoint slides and example source file(s) in pdf format: StdLibmap.ppt, word_count.cc.pdf, word_count1.cc.pdf and word_count2.cc.pdf. Example source file(s) (my own, if I recall correctly, and so different from book example code) in original file format – zip file.
Former Student Feedback Comments
A former student who was taught this course by me in the deemed university in Andhra Pradesh, India, wrote the following over email on March 18th 2014 (modified slightly to fix a couple of minor grammatical errors):
It is great that you have shared the C++ programming teaching material prepared by you on your blog. I really hope that people make use of it for I know how useful it could be. I can say this as a direct beneficiary of this, and today that is what fills my bank account at the end of every month.
I just hope and pray that Swami gives you the strength and determination to keep up the good work. I also think that I too can take a tiny part of the credit in this endeavour of you putting up these slides, as I was perhaps one of the many who would have suggested that you put these slides up in some forum accessible to the students’ community. Thank you for considering the request.
Prof. Bjarne Stroustrup’s book and course on C++
Prof. Bjarne Stroustrup, creator of C++, teaches C++ at Texas A&M university (TAMU). The course is based on his book, Programming — Principles and Practice Using C++. Here’s the book support page: http://www.stroustrup.com/Programming/. An extract from the book support page, “This book is based on a course I designed for engineering freshmen at Texas A&M University. It has now been taught by me and others, at TAMU, and elsewhere, in academia and industry, for almost five years and to thousands of students. It is currently available in (physical and web) book stores.” This page also has a link to lecture slides (for teaching C++).
Note about Course Book Source Code Copyright
The course book (C++ Primer, 4th edition) source code files have permission for usage statements as comments in the beginning of the files. As an example a source code file of chapter 1 (folder named 1) – mysum.cpp has the following comments towards the beginning of the file:
* Permission is granted for this code to be used for educational purposes in
* association with the book, given proper citation if and when posted or
* reproduced.Any commercial use of this code requires the explicit written
* permission of the publisher, Addison-Wesley Professional, a division of
* Pearson Education, Inc. …
—- end extract from header comments of source file —
As this blog/website of mine is a free teaching service to students on the Internet, and not-for-profit, I can consider that permission has been granted for me to use code from the above file on this blog. Further, I can use code from all other example code files of the book which carry a similar permission grant statement on this blog/website. Of course, I have given proper citation on each blog post/web page and Powerpoint slides file that uses the course book code.
The status history regarding the permission issue and putting up the C++ course contents on this blog is available here.