Professional Documents
Culture Documents
1
Problem 2: (20pts) Find the Big-Oh Notation of the following functions
Functions Big-Oh Short explanation
Notation
2n2logn + 4n2 - 3nlogn n2logn 2n2logn < Cn2logn for every
integer n > n0
C is constant.
2
void sumOfArray(int a[][], int m, int n) n There is 2 FOR loop with m and
{ n.
sum = 0;
for (int i = 0; i < m; i++)
{ for (int j = 0; j < n; j++)
{
sum += a[i][j];
}
}
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
wearingMask int
boundingBox Integer array
size of 4
face() -
Public face(string faceNewID, bool newGender, int -
2
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”
wearingMask = -1
boundingBox = [0,0,0,0]
Face::face()
{
faceID = “0000”;
wearingMask = -1;
for(int i = 0; i < 4; i++)
{
boundingBox[i] = 0;
}
3. (5pts) Write C++ code for a constructor of the class Face to initialize a new variable of
Face with the information of ID, wearing mask status and bounding box.
3
{
faceID = newID;
wearingMask = wearingMaskStatus;
for(int i = 0; i < 4; i++)
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 wearing mask on the screen.
void Face::faceGetAlert()
{
If (!wearingMask)
}
}
Problem 5: (25pts) Given a list Face_list which is described as follow to store the list of faces.
list<Face*> Face_list;
1. (10pts) Write C++ code to add 3 faces with the information as follow to the Face_list:
4
No. faceID wearingMask boundingBox
1 Face_0001 0 [40,30,455,535]
2 Face_0002 1 [40,120,256,256]
3 Face_0003 1 [150,400,128,140]
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”, 0, [290, 300, 350, 350]) into the Face_list.
Face_list.eraseBack();
int boundingBox4 [4] = {290, 300, 350, 350};
Face * Face4 = new Face (“Face_0004”, 0, 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 wearing mask 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------------------------------------------------------