---
tags: 2023 OOP
---
# 2023 OOP - 期中考答案 & 評分標準
## Part I.
> Choose the best answer to the following questions. (If you answer a question correctly,you obtain 3 points; if you got the wrong answer, you are deducted (倒扣) 3 points.)
####
選擇題的答案不多做說明,有問題可以詢問教授。
#### Ans
:::info
1-5: acbdb
6-8: cba
:::
## Part II.
> Discussion problems (申論題).
### 1. (10%)
Determine whether the following program segment contain errors. If you believe there is an error, explain how it can be corrected and what is the output in the screen. [Note: For a particular program segment, it is possible that no errors are present in the segment.]
```=c
#include <iostream>
using namespace std;
int main()
{
int a, b, c;
a = 5000;
cout << setfill('!') << setw(6) << a;
}
```
#### Ans:
:::info
(1) There is an error. To fix it, one must add the following before “int main()” ``` #include <iomanip> ``` (5%)
(2) After doing the step above, the output on the screen should be ```!!5000``` (5%)
```=c
#include <iostream>
#include <iomanip> /// ans(1)
using namespace std;
int main()
{
int a, b, c;
a = 5000;
cout << setfill('!') << setw(6) << a; //ans(2) Output: !!5000
}
```
:::
### 2. (8%)
Given the class definition:
```=c
class CreateAndDestroy
{
public:
CreateAndDestroy() { cout << "constructor called, "; }
~CreateAndDestroy() { cout << "destructor called, "; }
};
```
What will the following program output?
```=c
int main()
{
for ( int i = 0; i <= 2; i++ )
CreateAndDestroy x;
return 0;
}
```
#### Ans
:::info
```"constructor called, destructor called, constructor called, destructor called, constructor called, destructor called,."```(No "\n")(8%)
:::
### 3. (8%)
Determine whether the following program segment contain errors. If you believe there is an error, explain how it can be corrected.
```=c
#include <iostream>
using namespace std;
T opt( T x, T y)
{
T a = x;
if ( y < a )
a = y;
}
int main()
{
int int1, int2;
cout << "Input two integer values: ";
cin >> int1 >> int2;
cout << "The optimum value is: "
<< opt( int1, int2);
}
```
#### Ans
:::info
(1). Add ```“template < class T >”``` before “T maximum( T x, T y)” (5%)
(2). Under “a = y;” add ```“return a;”``` (5%)
```=c
#include <iostream>
using namespace std;
template < class T > // ans(1)
T opt( T x, T y)
{
T a = x;
if ( y < a )
a = y;
return a; // ans(2)
}
int main()
{
int int1, int2;
cout << "Input two integer values: ";
cin >> int1 >> int2;
cout << "The optimum value is: "
<< opt( int1, int2);
}
```
:::
## Part III
> Bonus points: Please write down your suggestions about this course. (5 extra points)
## Part IV:
> The programing exam.
### 1. (15%)
:::info
基本上有寫到對應的就有分數
1. namespace: 5%
2. template: 5%
3. pass by reference/value: 5%
:::
### 2. (20%)
:::info
共10個,每個 2%
* 3個constructor
1. constructor of the class department
2. constructor of the class course
3. constructor of the class student
* 7個function
1. "add_course()"
2. "remove_course()"
3. "search_course()"
4. "list_all_course()"
5. "list_course_all_student()"
6. "add_course_new_student()"
7. "search_course_studentName_byId()"
:::
### 3. (15%)
:::info
由於寫出來的人較少,會根據實作內容比例評分。
1. 撰寫 class node (5%)
2. 撰寫 class huffman_tree (10%)
:::