array.cpp

来自「c++的一些源代码」· C++ 代码 · 共 43 行

CPP
43
字号
/*
    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 + =
减小字号Ctrl + -
显示快捷键?