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
|
#include <string>
using namespace std;
class Unit
{
double value;
string abbreviation;
double siFactor;
string siAbbreviation;
public:
Unit(double v, string a, double sif, string sia) : value(v), abbreviation(a), siFactor(sif), siAbbreviation(sia) {}
};
class UnitOfLength : public Unit
{
public:
//constructor for scenario 1, comment out for scenarios 2 and 3
UnitOfLength(double v, string a, double sif, string sia = "m") : Unit(v, a, sif, sia) {}
//constructor for scenario 2, uncomment for scenario 2
//UnitOfLength(double v, string a = "", double sif= 0.0, string sia = "m") : Unit(v, a, sif, sia) {}
//constructor for scenario 3, uncomment for scenario 3
//UnitOfLength() : Unit(0.0, "", 0.0, "") {}
};
class Meter : public UnitOfLength
{
public:
Meter(double m = 0.0) : UnitOfLength(m, "", 0.0) {} // comment out for scenarios 2 and 3
//Meter(double m = 0.0) : UnitOfLength(m) {} // uncomment for scenario 2
//Meter(double m = 0.0) {} // uncomment for scenario 3
};
int main()
{
Meter m(2.5);
return 0;
}
|