國立暨南國際大學 96 學年度第二學期小考試卷

 
科目名稱:資訊系統 與網路導論 開課系所:資訊工程 學系 任課教師
吳坤熹
系所別:
年級:
學號:
姓名:
考試日期
2008.3.27

(考試時間: 10:40-11:00)

  1. (10%) Determine whether the following code is correct or not.  If it is correct, predict its output.  If it is incorrect, point out the mistake(s).
    #include <iostream>
    using std::cout;
    using std::endl;

    class Sample
    {
    public:
    int i;
    int j;
    char* sPtr;
    }

    int main()
    {
    Sample a, b;
    a.i = 1;
    a.j = 2;
    a.sPtr = "Hello, World!";
    b = a;
    cout << b.sPtr << endl;
    }
  2. (10%) Determine whether the following code is correct or not.  If it is correct, predict its output.  If it is incorrect, point out the mistake(s).

    #include <iostream>
    #include <windows.h>

    struct ListElement
    {
    int value;
    ListElement* pNext;
    };

    int main()
    {
    ListElement L1 = { 1 };
    ListElement L2 = { 2 };
    ListElement L3 = { 3 };
    L1.pNext = NULL;
    L2.pNext = &L1;
    L3.pNext = &L2;
    ListElement* p = &L2;
    while (p != NULL)
    {
    std::cout << p->value << std::endl;
    p = p->pNext;
    }
    }