// Santa.h
#ifndef __SANTA_H
#define __SANTA_H
#include <iostream>
namespace SantaClaus {
class Vehicle {
protected:
static const double basePrice;
public:
virtual double getPrice() const = 0;
virtual void print() const = 0;
};
class ReindeerSleigh: public Vehicle {
static const double reindeerFactor;
public:
double getPrice() const {
return basePrice * reindeerFactor;
}
void print() const {
std::cout << "The price of the reindeer sleigh is $" << getPrice() << std::endl;
}
};
class HuskySledge: public Vehicle {
static const double huskyFactor;
public:
double getPrice() const {
return basePrice * huskyFactor;
}
void print() const {
std::cout << "The price of the husky sledge is $" << getPrice() << std::endl;
}
};
class HorseSledge: public Vehicle {
static const double horseFactor;
public:
double getPrice() const {
return basePrice * horseFactor;
}
void print() const {
std::cout << "The price of the horse sledge is $" << getPrice() << std::endl;
}
};
}
#endif // __SANTA_H
// Santa.cpp
#include "Santa.h"
namespace SantaClaus {
const double Vehicle::basePrice = 50;
const double ReindeerSleigh::reindeerFactor = 1000;
const double HuskySledge::huskyFactor = 50;
const double HorseSledge::horseFactor = 60;
}
// Main.cpp
#include <iostream>
#include "Santa.h"
using namespace std;
using namespace SantaClaus;
int main() {
Vehicle *P[3];
P[0] = new ReindeerSleigh();
P[1] = new HuskySledge();
P[2] = new HorseSledge();
for (int i = 0; i < 3; i++) {
P[i]->print();
delete P[i];
}
return 0;
}