Professional Documents
Culture Documents
Midterm Semester 2 2019 2020
Midterm Semester 2 2019 2020
Midterm Semester 2 2019 2020
1
c) Use the pointer p to take the product of
Arr[1] and Arr[3]. int temp, product;
temp = *(p+1);
2
Problem 3: (10pts) Fill in the following table of the Stack operations.
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 Face_ID string
Gender bool
Bounding_box Integer array
size of 4
Face() -
Public Face(string faceNewID, bool newGender, int -
newBoundingBox[4])
operator = = (Face face) bool
face_getPosition() void
class Face
{
private:
string Face_ID;
bool Genfer;
3
int Bounding_box[4];
public:
Face();
Face(string faceNewId, bool newGender, int newBoundingBox[4]);
bool operator ==(const Face& face1);
void face_getPosition();
}
int main()
{
return 0;
}
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:
Face_ID = “Unknown ID”
Gender = 0
Bounding_box = [0,0,0,0]
Face :: Face()
{
this->Face_ID = "Unkown ID";
this->Gender = 0;
int i;
3. (5pts) Write C++ code for a constructor of the class Face to initialize a new variable of
Face with the information of ID, gender and bounding box.
4
{
this->Bounding_box[i] = newBoudingBox[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::getPosition() to show 4 corners of the
bounding box of the face on the screen.
void Face::face_getPosition()
{
Face a;
}
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:
5
No. Face_ID Gender Bounding box
1 Face_0001 0 [60,45,378,516]
2 Face_0002 1 [400,112,655,493]
3 Face_0003 1 [150,80,200,130]
#include <iostream>
#include <cstdlib>
#include <string>
#include <list>
class Face
{
private:
string Face_ID;
bool Gender;
int Bounding_box[4];
public:
Face();
Face(string newFace_ID, bool newGender, int newBounding_box[4]);
~Face()
{
cout << "Finished !!!";
}
};
Face:: Face()
{
int i;
this->Face_ID = "Unknow";
this->Gender = 0;
for (i = 0; i < 4; i++)
{
this->Bounding_box[i] = 0;
}
}
6
{
int i;
this->Face_ID = newFace_ID;
this->Gender = newGender;
for(i = 0 ; i < 4 ; i++)
{
this->Bounding_box[i] = newBounding_box[i];
}
}
int main()
{
int arr_a[4] = {60,45,378,516};
int arr_b[4] = {400,112,655,493};
int arr_c[4] = {150,80,200,130};
Face a;
Face *b = new Face("Face_0001", 0, arr_a);
Face *c = new Face("Face_0002", 1, arr_b);
Face *d = new Face("Face_0003", 1, arr_c);
list<Face*>Face_list;
Face_list.push_front(b);
Face_list.push_back(c);
Face_list.push_back(d);
return 0;
}
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, [ 190, 100, 320, 240]) into the Face_list.
Face_list.pop_back();
int arr_d[4] = {190, 100, 320, 240};
Face e("Face_0004", 0, arr_d);
Face_list.push_back(&e);
3. (5pts) Write C++ code to check the number of faces in the Face_list, and show on the
screen.
cout <<"The number of elements in list: "<< Face_list.size()<<endl;
7
4. (5pts) Write C++ code to show all position of the faces in Face_list on the screen by
using the Iterator p.
--------------------------------------------------------END------------------------------------------------------