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

科目名稱:程式設計 開課系所:資訊工程 學系 任課教師
吳坤熹
系所別:
年級:
學號:
姓名:
日期: 2011.3.23 時間: 14:10-14:20
  1. (10%) Determine whether the following code has syntax erros 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;

    int gcd(int a, int b)
    {
    if (b == 0) return a;
    else return gcd(b, a % b);
    }

    class CRational
    {
    public:
    int numerator; // 分子
    int denominator; // 分母

    CRational(int p=0, int q=1) : numerator(p), denominator(q)
    { if (q==0)
    { cout << "Error! The denominator cannot be 0.\n";
    exit(1);
    }
    }

    void Print() const
    { cout << numerator;
    if (denominator != 1)
    cout << "/" << denominator;
    cout << endl;
    }

    void Reduce() const
    { int i = gcd(numerator, denominator);
    numerator /= i;
    denominator /=i;
    }
    };

    int main()
    {
    CRational a(12,8);
    CRational b(3,6);
    a.Print(); a.Reduce(); a.Print();
    b.Reduce(); b.Print();
    return 0;
    }


  2. (10%) According to Steve Jobs, what was the most interesting course which he took in Reed College?
    1. C++ Programming
    2. Calligraphy
    3. Calculus
    4. Computer Animation

  3. (10%) What does the words "Stay Hungry, Stay Foolish" mean, when Steve Jobs said that in his Stanford commencement speech?