Exercises, examples and other material relating to training module C232. This topic is presented on public courses Learning to program in C++
, C++ for C Programmers
, C and C++ Programming
How to set up your own classes of objects in
C++, and how to use those objects and also objects
that are available to you from elsewhwere. We also
introduce access levels in this module.
|Articles and tips on this subject||updated|
|4129||Simple OO demonstration in C++, comparison to Python|
From last week's quick introduction to C++ (a private course - half a day added on to the end of a C Programming course - an example of how C++ implements objects for a newcomer to C++ who's seen some Python.
Firstly, in C++ you must predefine the API - the interface between the user and the class. ...
|3978||Teaching OO - how to avoid lots of window switching early on|
One of the major benefits of Object Oriented programming is the clear and sharp dividing lines it provides between the different sections of logic - where code dealing with one type of data is specified, written, stored and tested in different files to the code dealing with other types of data (or code ...
|3810||Reading files, and using factories to create vectors of objects from the data in C++|
On our C++ courses, we concentrate on objects and object design. But we also take a wider look at topics such as references and templates that go to making the complete language, with sections covering changes to things like file handling from the underlying C language.
I've just added a new example ...
|3721||Naming blocks of code, structures and Object Orientation - efficient coding in manageable chunks|
Soon after you start to program, you'll learn that you want to re-use code. And that re-use will sometimes come in the form of loops, and at other times in the form of named blocks of code which you'll call up from multiple places in your program, or indeed from multiple programmers.
• A good ...
|3716||Learning C++ - a design pattern for your first class|
From today's C++ Course - a new, clear example of a design pattern for a simple class, its headers, and a test harness - [here].
When using an Object Oriented language, design patterns are really useful. Essentially, they're a known and standard way of combining the features of the language in a convenstional ...
|3250||C++ - how we teach the language and the concepts behind the language|
When I'm teaching an object oriented language such as C++, I like to write code and demonstrate from scratch to my class, getting them to 'feed' me with application data and information so that I can show them how programs are really developed using the OO approach - both in general, and in the specific ...
|2577||Complete teaching example - C++, inheritance, polymorphism|
On yesterday's C++ course, I provided a final example which illustrated polymorphism, and showed how even the simple example was best written, split, ito no less that seven source files.
1. The main C++ source code - for my example, a simple demo test harness
|2579||Creating, setting up and using objects in C++|
Early on this week's C++ programming course (including the C fundamentals), I wrote a new and short example that defined and used a class of objects of type "Hotel". Really, this initial example was very much shorter than any real program you would write and it used a very limited number of the facilities, ...
|2578||Where are your objects stored in C++?|
If you declare a variable to be of an object type in C++ (and potentially do so with parameters), you're going to be assigning memory for the variables that it includes on the stack - i.e. within memory that will be lost when you exit the closure (block of code - function - method) in which you are defining ...
|1925||Introduction to Object Oriented Programming|
"Object Oriented Programming" is a whole new philosophy for programmers who have been writing short scripts for years, and it can be quite frightening to learn with all these new buzzwords like "overriding", "encapsulation" and "polymorphism" creeping in. It's a beautiful concept and a lovely approach, ...
Examples from our training material
|a2.cpp|| Array of objects of different types|
|a3.cpp|| Inherited methods - test program|
|afuncs.cpp|| Class use with accessory functions|
|allin1.cpp|| Class definition and use all in one file|
|book.cpp|| Class implementation code - book|
|book.inc|| Class interface - book|
|dayfour.cpp|| Creating objects on the stack or heap|
|demo1.cpp|| Base class and subclass method definition|
|demo1.h|| Base class and subclass header definition|
|demo2.cpp|| Further base and subclass definition|
|demo2.h|| Further base and subclass header definition|
|demomake|| makefile for module c232|
|g_main.cpp|| Fundamental use of classes example - C++|
|hcd.cpp|| Class description with accessor functions|
|hmain.cpp|| First class in C++|
|hotel.cpp|| Class member code|
|hotel.inc|| Class descriptor|
|makefile|| Compile / Load instructions for examples in this module|
|melksham.cpp|| Class use with accessor functions|
|mylib.cpp|| Main application calling constructors and destructors|
|table.cpp|| code - the internals of the Table class|
|table.h|| Definition of API of a class|
|tabletest.cpp|| A test harness for the Table class|
|template.cpp|| Design Pattern for class definition and test |
|transport.cpp|| Hello c++ world - define and use an object / Compare to Python|
Some modules are available for download
as a sample of our material or under an Open Training Notes License
for free download from http://www.training-notes.co.uk
Topics covered in this module
Defining classes through struct and class.
Constructors and Destructors.
Private, Protected and Public.
If you are looking for a complete course and not just a information on a single subject, visit our Listing and schedule
Well House Consultants specialise in training courses in
. We run
throughout the UK (and beyond for longer courses), and
at our training centre in Melksham, Wiltshire, England.
It's surprisingly cost effective to come on our public courses -
even if you live in a different
country or continent to us
We have a technical library of over 700 books on the subjects on which we teach.
These books are available for reference at our training centre. Also
available is the Opentalk
Forum for discussion of technical questions.