國立暨南國際大學 101 學年度第一學期小考試卷

科目名稱:計算機概 論 開課系所:資訊工程 學系 考試日期 2013.1.4
系所別:
年級:
學號:
姓名:
考試時間 08:10-08:20

  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).
    // Definition of a struct to represent rectangles
    #include <iostream>

    struct RECTANGLE
    {
      int Left;                            // Top-left point
      int Top;                             // coordinate pair

      int Right;                           // Bottom-right point
      int Bottom;                          // coordinate pair
    }

    long Area(const RECTANGLE aRect)       // Pass by value
    { return (aRect.Right - aRect.Left)*(aRect.Bottom - aRect.Top); }

    int main()
    {
        RECTANGLE Hut = { 10, 20, 30, 40 };
        std::cout << Area(Hut) << std::endl;
        return 0;
    }


  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).
    // Rational Numbers
    #include <iostream>

    struct Rational
    {
      unsigned char numerator;
      unsigned char denominator;
    };

    int main()
    {
        Rational p = {1, 3}, q = {5, 7};
        std::cout << sizeof(p) << '\t'
            << sizeof(q.denominator) << std::endl;
        return 0;
    }