#ifndef REPLACETYPECODEWITHCLASS_H_
#define REPLACETYPECODEWITHCLASS_H_
#include <string>
const static int SIZE_OF_BLOOD_TYPE = 4;
enum BloodType
{
O = 0,
A,
B,
AB,
};
class BloodGroup
{
public:
static std::string toString(BloodType type);
public:
BloodGroup(BloodType type);
std::string getBloodType();
private:
BloodType type;
};
class Person
{
public:
Person(std::string arg1, BloodGroup& arg2);
std::string getBloodType();
std::string getName();
private:
std::string name;
BloodGroup bloodGroup;
};
#endif /* REPLACETYPECODEWITHCLASS_H_ */
#include "ReplaceTypeCodeWithClass.h"
#include <iostream>
using namespace std;
Person::Person(string arg1, BloodGroup& arg2):name(arg1), bloodGroup(arg2)
{}
string Person::getBloodType()
{
return bloodGroup.getBloodType();
}
string Person::getName()
{
return name;
}
string BloodGroup::toString(BloodType type)
{
static string typeOfString[SIZE_OF_BLOOD_TYPE] = {"O","A","B","AB"};
return typeOfString[type];
}
BloodGroup::BloodGroup(BloodType type):type(type)
{}
string BloodGroup::getBloodType()
{
return toString(type);
}
void ReplaceTypeCodeWithClass()
{
BloodGroup o(O);
BloodGroup ab(AB);
Person p1("James",o);
Person p2("Jane", ab);
cout<<p1.getName()<<" BloodType is "<<p1.getBloodType()<<endl;
cout<<p2.getName()<<" BloodType is "<<p2.getBloodType()<<endl;
}