Midterm Semester 1 2020-2021 - Answer - Sheet2
Midterm Semester 1 2020-2021 - Answer - Sheet2
Midterm Semester 1 2020-2021 - Answer - Sheet2
1
Problem 2: (20pts) Find the Big-Oh Notation of the following functions
1 enqueue(200) - {200}
2 enqueue(-70) - {200,-70}
6 dequeue() - {30}
7 dequeue() - {}
8 dequeue() error {}
9 isEmpty() 1 {}
10 size() 0 {}
2
Problem 4: (25pts) Consider the class Face in the mobile app for face recognition:
1. (5pts) Write C++ code to declare the class Face with the default information as below:
Members Variable Type
Private faceID string
focusOnLesson int
boundingBox Integer array
size of 4
face() -
Public face(string faceNewID, bool newGender, int -
newBoundingBox[4])
operator = = (Face face) bool
faceGetAlert() void
2. (5pts) Write C++ code for a constructor of the class Face to initialize a new variable of
Face with the default information as below:
faceID = “0000”
focusOnLesson = -1
boundingBox = [0,0,0,0]
Face::face()
{
faceID = “0000”;
focusOnLesson = -1;
for(int i = 0; i < 4; i++)
boundingBox[i] = 0;
3
3. (5pts) Write C++ code for a constructor of the class Face to initialize a new variable of
Face with the information of ID, focusing status and bounding box.
boundingBox[i] = newBoundingBox[i];
4. (5pts) Write C++ code for the operator of the class Face to compare the two faces and
return true if two faces have the same ID and bounding box.
5. (5pts) Write C++ code for the function Face::getFaceAlert() to show faceID of the face
not focusing the lesson on the screen.
void Face::faceGetAlert()
{
if (!focusOnLesson)
}
}
Problem 5: (25pts) Given a list Face_list which is described as follow to store the list of faces.
list<Face*> Face_list;
4
1. (10pts) Write C++ code to add 3 faces with the information as follow to the Face_list:
No. faceID focusOnLesson boundingBox
1 Face_0001 0 [60,80,357,652]
2 Face_0002 0 [30,70,510,512]
3 Face_0003 1 [225,250,143,156]
Face_list.push_back(Face1);
Face_list.push_back(Face2);
Face_list.push_back(Face3);
2. (5pts) Write a C++ code to remove the Face “Face_0003” out of the Face_list, and add a
new Face (“Face_0004”, 1, [420, 500, 128, 128]) into the Face_list.
Face_list.eraseBack();
int boundingBox4 [4] = {420, 500, 128, 128};
Face * Face4 = new Face (“Face_0004”, 1, boundingBox4);
Face_list.insert(++++Face_list.begin(), Face4);
3. (5pts) Write C++ code to check the number of faces in the Face_list, and show on the
screen.
4. (5pts) Write C++ code to show all the faces not focusing on lesson in Face_list on the
screen by using the Iterator p.
list < Face*>::iterator p;
for (p = Face_list.begin(); p != Face_list.end(); p++)
{
(*p) -> faceGetAlert();
}
--------------------------------------------------------END------------------------------------------------------