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

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

(考試時間: 8:20-8:45)

  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>
    class Complex
    {
    double Re; // real part
    double Im; // imaginary part
    };

    void main()
    {
    Complex a;
    a.Re = 1.0;
    a.Im = 2.0;
    std::cout << a.Im << std::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>
    using std::cout;

    class Node
    {
    public:
    int data;
    Node* left;
    Node* right;

    void Print()
    {
    if (this->left)
    this->left->Print();
    cout << data;
    if (this->right)
    this->right->Print();
    }

    Node(int i)
    {
    data = i;
    left = 0;
    right = 0;
    }

    };

    void main()
    {
    Node one(1);
    Node two(2);
    Node three(3);
    one.left = &two;
    one.right = &three;
    one.Print();
    }