#include<iostream>
#include <string>
using namespace std;
enum eTStyle
{
T_STYLE1=0,
T_STYLE2,
T_STYLE3
};
class CTshirt
{
private:
string m_scolor;
int m_nsize;
eTStyle m_estyle;
public:
CTshirt(string color, int size, eTStyle style)
{
m_scolor = color;
m_nsize = size;
m_estyle = style;
}
string GetColor()
{
return m_scolor;
}
int GetSize()
{
return m_nsize;
}
eTStyle GetStyle()
{
return m_estyle;
}
};
class CPants
{
private:
string m_scolor;
int m_nsize;
eTStyle m_estyle;
public:
CPants(string color, int size, eTStyle style)
{
m_scolor = color;
m_nsize = size;
m_estyle = style;
}
string GetColor()
{
return m_scolor;
}
int GetSize()
{
return m_nsize;
}
eTStyle GetStyle()
{
return m_estyle;
}
};
class CShoes
{
private:
string m_scolor;
int m_nsize;
eTStyle m_estyle;
public:
CShoes(string color, int size, eTStyle style)
{
m_scolor = color;
m_nsize = size;
m_estyle = style;
}
string GetColor()
{
return m_scolor;
}
int GetSize()
{
return m_nsize;
}
eTStyle GetStyle()
{
return m_estyle;
}
};
class CSuits
{
private:
CTshirt *m_pshirt;
CPants *m_ppants;
CShoes *m_pshoes;
public:
CSuits(CTshirt *pshirt, CPants *ppants, CShoes *pshoes)
{
m_pshirt = pshirt;
m_ppants = ppants;
m_pshoes = pshoes;
}
CTshirt* GetShirt()
{
cout << "-------------------Shirt-----------------" << endl;
cout << "Color is : " << m_pshirt->GetColor() << endl;
cout << "Size is : " << m_pshirt->GetSize() << endl;
cout << "Style is: " << m_pshirt->GetStyle() << endl;
return m_pshirt;
}
CPants* GetPants()
{
cout << "-------------------Pants-----------------" << endl;
cout << "Color is : " << m_ppants->GetColor() << endl;
cout << "Size is : " << m_ppants->GetSize() << endl;
cout << "Style is: " << m_ppants->GetStyle() << endl;
return m_ppants;
}
CShoes* GetShoes()
{
cout << "-------------------Shoes-----------------" << endl;
cout << "Color is : " << m_pshoes->GetColor() << endl;
cout << "Size is : " << m_pshoes->GetSize() << endl;
cout << "Style is: " << m_pshoes->GetStyle() << endl;
return m_pshoes;
}
void GetAll()
{
GetShirt();
GetPants();
GetShoes();
}
};
int main()
{
CTshirt *pshirt = new CTshirt("red", 165, T_STYLE1);
CPants *ppants = new CPants("white", 165, T_STYLE1);
CShoes *pshoes = new CShoes("black", 37, T_STYLE1);
CSuits *psuit = new CSuits(pshirt, ppants, pshoes);
psuit->GetAll();
return 0;
}
运行结果
-------------------Shirt-----------------
Color is : red
Size is : 165
Style is: 0
-------------------Pants-----------------
Color is : white
Size is : 165
Style is: 0
-------------------Shoes-----------------
Color is : black
Size is : 37
Style is: 0
请按任意键继续. . .