/* C++ Classes and Objects Demo
Copyright © Robin Broad 2018
Free software published under GNU GPL
http://www.robinbroad.co.uk/
April 2018
*/
//Preprocessor instructions to the C++ compiler
//Include the standard C input/ output library
#include
//Use the standard names in namespace std for the functions in the iostream library (e.g. cout). Without this, the compiler would not recognise the function cout, which we are using in this program
using namespace std;
//Include the standard C maths library. We need it to calculate the square root sqrt() in the lenSpaceDiag() member function of the Cuboid class
#include
class Cuboid
/*Class name Cuboid. This class represents the three dimensional mathematical shape rectangular cuboid. It has six rectangular faces, 12 edges and 8 vertices. We will provide member functions for surface area, volume and the length of the space diagonal.
This code is heavily commented to assist students of C++
Author: Robin Broad
C++ Examples
http://www.robinbroad.co.uk/
April 2018
*/
{
//*** Members ***
private:
/*private means accessible only within the class (or by friends of the class); not publicly accessible.
(This is also known as data hiding. This is part of the process of encapsulation; information hiding, data and methods)*/
//Declaring the class members a, b and c.
int a, b, c;
/*Using the standard mathematical notation of a, b and c for the lengths of the sides of the cuboid
int means "of type integer"*/
//***Constructor ***
/*The constructor is a member function with the same name as the class.
It is called whenever an object (class instance) is created*/
public:
//public means these members or member functions can be accessed anywhere, including from outside the class
//The Cuboid class constructor member function. This is passed the cuboid dimensions a, b and c.
Cuboid(int fpa, int fpb, int fpc)
//fpa=function parameter a etc.
{
/*Notifying us that the constructor has been called
The insertion operator << specifies the string to be written to the console by cout
The \n is the newline character*/
cout << "Constructing a cuboid object of dimensions "<