Home Accessibility Courses Twitter The Mouth Facebook Resources Site Map About Us Contact
 
For 2023 (and 2024 ...) - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
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
See http://www.wellho.net/resources/ex.php4?item=c051/further.cpp

2. The C++ source code of the first class that my example used
See http://www.wellho.net/resources/ex.php4?item=c051/starredhotel.cpp

3. The C++ source code of the second class that my example used
See http://www.wellho.net/resources/ex.php4?item=c051/selfhotel.cpp

4. The C++ source code of the base class from which my two sample classes were derived.
See http://www.wellho.net/resources/ex.php4?item=c051/g_hotel.cpp

Because I need to include function / method prototypes into various files so that the comiler can check that calls are valid in isolation from the separate compiles, I have also provided separate header files. In theory it is possible to include these within the four source files above directly, but that is a TERRIBLE practice and you should load them through #includes ...

5. The header file defining the methods in the first used class
See http://www.wellho.net/resources/ex.php4?item=c051/starredhotel.h

6. The header file defining the methods in the second used class
See http://www.wellho.net/resources/ex.php4?item=c051/selfhotel.h

7. The header file defining the methods in the base class
See http://www.wellho.net/resources/ex.php4?item=c051/g_hotel.h

In essence, C++ is mostly about adding object orientation to C (thus meking it a completely different kettle of fish!), so I have loaded each of the course files above onto our web site so that you can see the complete example under the category "C++ in general". They illustrate a very large range of features - inheritance, overloading, polymorphism, virtual functions, etc ... all of which I'll explain to you on our C++ courses - in fact, this set of examples was written on the C++ course which ended yesterday, where I showed the delegate how we design and write object oriented programs in C++ from scratch.

We offer three public courses

Learning to program in C++ - 5 days, for delegates who have never programmed before in any programming language, or have done so VERY little.
See http://www.wellho.net/course/cffull.html

C and C++ programming - 4 days, for delegates who have programmed before, but not in C (on which C++ is based)
See http://www.wellho.net/course/cafull.html

C++ Programming - 2 days, for experienced C programmers who need to add the extras of C++ (and learn which parts of C they can gently retire!)
See http://www.wellho.net/course/cpfull.html




Update .... there's another full example too on our website - it's the one that's actually in the course notes and it comprises the following:

accom4.cpp - the main program
hotel.cpp - the base class for "hotel"
melkshamhotel.cpp - a derived class
regionhotel.cpp - another derived class
hotel.inc - header file for the base class
melkshamhotel.inc - header file for the first derived class
regionhotel.inc - header file for the second derived class
makefile - the build instruction file for Linux / Unix that ties the whole thing together.

One of the great things about good OO design is that you can reuse your low level code - your classes and objects - across a number of applications. Here are some further applications using all (or some) of those classes:

accom2.cpp, accomchooser.cpp and accom3.cpp



(written 2010-01-15, updated 2010-10-30)

 
Associated topics are indexed as below, or enter http://melksh.am/nnnn for individual articles
C233 - C and C based languages - OO in C++ - beyond the basics
  [798] References and Pointers in C++ - (2006-07-10)
  [801] Simple polymorphism example - C++ - (2006-07-14)
  [831] Comparison of Object Oriented Philosophy - Python, Java, C++, Perl - (2006-08-13)
  [925] C++ - just beyond the basics. More you can do - (2006-11-14)
  [1217] What are factory and singleton classes? - (2007-06-04)
  [1572] C - structs and unions, C++ classes and polymorphism - (2008-03-13)
  [1674] What a lot of files! (C++ / Polymorphism demo) - (2008-06-12)
  [1819] Calling base class constructors - (2008-10-03)
  [2845] Objects and Inheritance in C++ - an easy start - (2010-07-01)
  [3056] C++ - a complete example with polymorphism, and how to split it into project files - (2010-11-16)
  [3123] C++ objects - some short, single file demonstrations - (2011-01-07)
  [3124] C++ - putting the language elements together into a program - (2011-01-08)
  [3142] Private and Public - and things between - (2011-01-22)
  [3244] C and C++ - preprocess, compile, load, run - what each step is for - (2011-04-12)
  [3251] C++ - objects that are based on other objects, saving coding and adding robustness - (2011-04-17)
  [3508] Destructor methods in C++ - a primer - (2011-11-05)
  [3811] Associated Classes - using objects of one class within another - (2012-07-21)
  [3979] Extended and Associated objects - what is the difference - C++ example - (2013-01-18)
  [4356] Object factories in C++, Python, PHP and Perl - (2014-12-19)
  [4375] Final examples for 2014 - and a look at our 2015 training course options - (2014-12-31)
  [4377] Designing a base class and subclasses, and their extension, in C++ - (2015-01-01)
  [4559] When do I use the this keyword in C++? - (2015-10-29)
  [4560] Variables, Pointers and References - C and C++ - (2015-10-29)

C232 - C and C based languages - Defining and using classes in C++
  [1925] Introduction to Object Oriented Programming - (2008-12-06)
  [2578] Where are your objects stored in C++? - (2010-01-16)
  [2579] Creating, setting up and using objects in C++ - (2010-01-16)
  [3250] C++ - how we teach the language and the concepts behind the language - (2011-04-17)
  [3716] Learning C++ - a design pattern for your first class - (2012-05-02)
  [3721] Naming blocks of code, structures and Object Orientation - efficient coding in manageable chunks - (2012-05-06)
  [3810] Reading files, and using factories to create vectors of objects from the data in C++ - (2012-07-21)
  [3978] Teaching OO - how to avoid lots of window switching early on - (2013-01-17)
  [4129] Simple OO demonstration in C++, comparison to Python - (2013-07-01)
  [4372] Template / design pattern for C++ constructor and accessors - (2014-12-29)
  [4565] Allocation of memory for objects in C++ - Stack v Heap - (2015-10-31)

C051 - C and C based languages - C++ - General
  [2370] C++, Python, and other training - do we use an IDE - (2009-08-21)
  [2504] Learning to program in ... - (2009-11-15)
  [2536] All the Cs ... and Java too - (2009-12-13)
  [2763] Our C and C++ training course are on Open Source platforms - (2010-05-13)
  [2851] Further C++ material - view new or old - (2010-07-04)
  [3052] Getting your C++ program to run - (2010-11-15)
  [3067] Using C and C++ functions in the same program - how to do it - (2010-11-24)
  [3129] Extra courses - C and C++ - (2011-01-12)
  [3155] Rake - a build system using code written in Ruby - (2011-02-03)
  [3587] C++ Courses - do I get official certification at the end of my Well House course? - (2012-01-20)
  [3809] Dwarf Exception Unwind Info - (2012-07-20)
  [4335] Flexible public courses - residential or commuting, programming newcomer or experienced, C or C++ - (2014-11-30)
  [4355] C++ in 2 days - (2014-12-18)


Back to
What does const mean? C and C++
Previous and next
or
Horse's mouth home
Forward to
Where are your objects stored in C++?
Some other Articles
Snow scenes - and how snow effected our business
C course inspires new teaching examples
Complete teaching example - C++, inheritance, polymorphism
What does const mean? C and C++
Sharing variables between files of code in C - extern
Summary of Wiltshire Core Strategy responses
C Structs - what, how and why
The what and why of C pointers
4759 posts, page by page
Link to page ... 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96 at 50 posts per page


This is a page archived from The Horse's Mouth at http://www.wellho.net/horse/ - the diary and writings of Graham Ellis. Every attempt was made to provide current information at the time the page was written, but things do move forward in our business - new software releases, price changes, new techniques. Please check back via our main site for current courses, prices, versions, etc - any mention of a price in "The Horse's Mouth" cannot be taken as an offer to supply at that price.

Link to Ezine home page (for reading).
Link to Blogging home page (to add comments).

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2024: 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho

PAGE: http://www.wellho.net/mouth/2577_.html • PAGE BUILT: Sun Oct 11 16:07:41 2020 • BUILD SYSTEM: JelliaJamb