[試題] 104-2 張智星 資料結構與演算法 Quiz 1
課程名稱︰資料結構與演算法
課程性質︰必修
課程教師︰張智星、林軒田
開課學院:電資學院
開課系所︰資訊系
考試日期(年月日)︰20160308
考試時限(分鐘):約30分鐘
試題 :
1.Memory leak:(2 pts)
a.What is the definition of memory leak?
b.Give a code example of memory leak in C/C++.
2.Shallow copy:(4 pts)A program is used to record each student's quiz scores.
a.Class definition:class student {
public:
student(int n=3){count=n;score=new int[count]
~student(){delete[]score;};
void print(); //Print score
int *score,count;
string name;
}
b.Main program:int main(){
student a(3);
a.name="John";a.score[0]=70;a.score[1]=80;
student b=a;
b.name="Mary";b.score[2]=90;
}
Answer the following sub-questions:
a.What are the contents of variables a and b?
b.What are the two potential problems of this program?
3.STL vectors:(4 pts)Give 3 advantages and 1 disadvantage of STL vectors when
compared with the standard C/C++ arrays.
4.STL vectors:(3 pts)Given an STL vector x, answer the following sub-questions.
a.What does "x.resserve(25)" mean?
b.What is the difference between x[i] and x.at(i)?
c.What is the difference between x.size() and x.capacity()?
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 1.163.42.26
※ 文章網址: https://www.ptt.cc/bbs/NTU-Exam/M.1466947103.A.E82.html
推
06/27 00:33, , 1F
06/27 00:33, 1F