📄 array.cpp
字号:
/*
array.cpp -- Initializing array of class with multiple
arguments in the constructor.
*/
#include <stdio.h>
#include <string.h>
class CEmployee
{
public:
CEmployee (int ID, char *First, char *Last)
{
m_EmployeeID = ID;
strcpy (m_EmployeeFirst, First);
strcpy (m_EmployeeLast, Last);
}
int GetID () {return (m_EmployeeID);}
char *GetFirstName () {return (m_EmployeeFirst);}
char *GetLastName () {return (m_EmployeeLast);}
private:
int m_EmployeeID;
char m_EmployeeFirst[24];
char m_EmployeeLast[24];
};
int main ()
{
CEmployee emp[] = {
CEmployee (1641, "Thomas", "Jefferson"),
CEmployee (1802, "George", "Washington"),
CEmployee (1732, "John", "Adams"),
CEmployee (1752, "Andrew", "Jackson"),
CEmployee (2401, "Elsie", "Smith")
};
for (int x = 0; x < sizeof(emp)/sizeof (CEmployee); ++x)
printf ("%s %s's Employee ID is %d\n",
emp[x].GetFirstName(),
emp[x].GetLastName(),
emp[x].GetID());
return (0);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -