///simple use of classes and objects#include<iostream>using namespacestd;///overloading of constructors, calculating volumeclassBox { Public: Box (); ///constructor with no arguments to initialize theBox (intHintWintL): Height (h), Width (w), Length (l) {};///initializing with parameter list intVolume ();///Find VolumePrivate: intheight; intwidth; intlength;}; Box::box () {Height=Ten; Width=Ten; Length=Ten;}intBox::volume () {return This->height* This->width* This-length;}intMain () {Box box1; Box Box2 (Ten, One, A); cout<<box1.volume () <<Endl; cout<<box2.volume () <<Endl; return 0;}
View Code
///simple use of classes and objects#include<iostream>using namespacestd;///constructors that use default parameters, which are equivalent to multiple constructorsclassBox { Public: Box (intH=Ten,intw=Ten,intL=Ten): Height (h), Width (w), Length (l) {};///initializing with parameter list intVolume ();///Find VolumePrivate: intheight; intwidth; intlength;};intBox::volume () {return This->height* This->width* This-length;}intMain () {Box box1; Box Box2 (Ten, One, A); cout<<box1.volume () <<Endl; cout<<box2.volume () <<Endl; return 0;}
View Code
///simple use of classes and objects#include<iostream>using namespacestd;///initialization of an array of objectsclassBox { Public: Box (intH=Ten,intw=Ten,intL=Ten): Height (h), Width (w), Length (l) {};///initializing with parameter list intVolume ();///Find VolumePrivate: intheight; intwidth; intlength;};intBox::volume () {return This->height* This->width* This-length;}intMain () {Box box[4]={Box (Ten,Ten,Ten), Box (Ten, One,Ten), Box (Ten, One, A), Box ( One, A, -), }; cout<<box[0].volume () <<Endl; cout<<box[1].volume () <<Endl; cout<<box[2].volume () <<Endl; cout<<box[3].volume () <<Endl; return 0;}
View Code
Simple use of classes and objects (constructor initialization)