國立暨南國際大學 100 學年度第一學期小考試卷
(考試時間: 08:10-08:30)
科目名稱:資訊系統
與網路導論 |
開課系所:資訊工程
學系 |
任課教師
|
吳坤熹
|
系所別:
|
年級:
|
學號:
|
姓名:
|
考試日期
|
2011.12.16
|
-
(10%) Determine
whether the following code has syntax errors or not. If
it is correct, predict its output. If it is incorrect, point out
the mistake(s).
// Ex7_01.cpp
#include <iostream>
using std::cout;
using std::endl;
// Definition of a struct to represent rectangles
struct RECTANGLE
{
int
Left;
// Top-left point
int
Top;
// coordinate pair
int
Right;
// Bottom-right point
int
Bottom;
// coordinate pair
};
bool EqualAreaRect(RECTANGLE aRect, RECTANGLE bRect);
int main(void)
{
RECTANGLE Hut1 = ( 10, 50, 40, 90 );
RECTANGLE Hut2 = ( 30, 20, 50, 80 );
RECTANGLE Hut3 = ( 20, 30, 50, 80 );
cout << (EqualAreaRect(Hut1, Hut2)?"Same Area":"Different Area") << endl;
cout << (EqualAreaRect(Hut1, Hut3)?"Same Area":"Different Area") << endl;
return 0;
}
// Function to calculate the area of a rectangle
long Area(const RECTANGLE& aRect)
{
return (aRect.Right - aRect.Left)*(aRect.Bottom - aRect.Top);
}
bool EqualAreaRect(RECTANGLE aRect, RECTANGLE bRect)
{
if (Area(aRect) == Area(bRect))
return true;
else
return false;
}
- (10%)
Determine whether the following code has syntax errors or not. If
it is correct, predict its output. If it is incorrect, point out
the mistake(s).
// default value of parameters
#include <iostream>
using std::cout;
using std::endl;
// Definition of a struct to represent rectangles
struct RECTANGLE
{
int
Left;
// Top-left point
int
Top;
// coordinate pair
int
Right;
// Bottom-right point
int
Bottom;
// coordinate pair
};
void MoveRect(RECTANGLE& aRect, int x = 0, int y = 0)
{
int length(aRect.Right - aRect.Left); // Get length of rectangle
int width(aRect.Bottom - aRect.Top); // Get width of rectangle
aRect.Left =
x;
// Set top-left point
aRect.Top =
y;
// to new position
aRect.Right = x +
length;
// Get bottom-right point as
aRect.Bottom = y +
width;
// increment from new position
return;
}
int main(void)
{
RECTANGLE Hut1;
Hut1.Left = 70;
Hut1.Top = 10;
Hut1.Right = Hut1.Left + 25;
Hut1.Bottom = 30;
MoveRect(Hut1, 30);
cout << Hut1.Right << ',' << Hut1.Bottom << endl;
return 0;
}