Consider the following code:
#include <iostream>
using std::cout;
using std::endl;
class CStudent
{
public:
CStudent(const char* firstname, const char* surname, const char* lang)
{
strcpy(fn, firstname);
strcpy(sn, surname);
strcpy(language, lang);
}
void Print()
{
if (strcmp(language, "Chinese") == 0)
cout << sn << fn << endl;
else
cout << fn << ' ' << sn << endl;
}
private:
char fn[20];
char sn[20];
char language[10];
};
int main()
{
CStudent group[] = {
CStudent("東坡", "蘇", "Chinese"),
CStudent("宗元", "柳", "Chinese"),
CStudent("Sandra", "Bullock", "English"),
CStudent("Julia", "Roberts", "English")
};
for (int i=0; i < sizeof(group) / sizeof(CStudent); i++)
group[i].Print();
}