You are on page 1of 5

Ho Chi Minh City University of Technology

Department of Electrical and Electronics Engineering


MIDTERM EXAMINATION – Class TT0 ECE391: Computer System Engineering
Semester 1, 2020-2021 Duration: 60 minutes
Score Students are allowed to use one A4 page with two sides for Lecturer
reference.
Books and other documents are not allowed to use.

This examination consists of 5 pages Trương Quang


Vinh

Student name: ID:

Problem 1: (20pts) Given a following C++ declaration


int Arr[] = {100, 200, 300, 400, 500, 600, 700};
int *p = &Arr[0];
Write C++ code to do the following tasks. Answers
Declare additional variables if needed.
Write “Error” if the code is wrong.
a) If the following code is executed, what 600
shows on the output screen?
cout << *&*(p+5);

b) Use the pointer p and FOR loop to print


out all elements in the array Arr. for (int i=0; i < 7; i++)
{
cout << *(p+i) << ‘\t’;
}

c) Use the pointer p to take the product of


Arr[2] and Arr[6]. int product = *(p+2) * *(p+6);

d) Write C++ program using pointer p to


calculate the sum of all elements in the S = 0;
array Arr[]. for (int i=0;i<7;i++)
{
S += *(p+i);
}

1
Problem 2: (20pts) Find the Big-Oh Notation of the following functions

Functions Big-Oh Short explanation


Notation

(6n2 +2n+150)2 n4 (6n2 +2n+150)2 = 36 n4 + 24 n3 + 1804 n2 + 600n +


22500 < Cn4 for every integer n > n0

400n + n an 400n + n < Can for every integer n > n0

C and a are constants.

n (100+ 50i) n2 n (100+50i)< n (100+50i) di = 100n + 25n2 < Cn2


for every integer n > n0

n (10i2 + 6i + 4) n3 n (10i2 + 6i + 4)< n (10i2 + 6i + 4) di = 10n3/3 + 3n2


+ 4n < Cn3 for every integer n > n0

Problem 3: (10pts) Fill in the following table of the Queue operations.

No. Operation Output Front <- Queue -> rear

1 enqueue(200) - {200}

2 enqueue(-70) - {200,-70}

3 enqueue(30) - {200, -70, 30}

4 dequeue() - {-70, 30}

5 front() -70 {-70, 30}

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

Write your C++ code here:


class Face {
private:
string faceID;
int focusOnLesson;
int boundingBox[4];
public:
face();
face(string newID, bool focusOnLessonStatus, int newBoundingBox[4]);
bool operator==(Face face);
void faceGetAlert();
};

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.

Face::face(string newID, bool focusOnLessonStatus, int newBoundingBox[4])


{
faceID = newID;
focusOnLesson = focusOnLessonStatus;
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.

bool Face::operator = = (Face face)


{
return (Face_ID == face.Face_ID
&& Bounding_box[0]== face.Bounding_box[0]
&& Bounding_box[1]== face.Bounding_box[1]
&& Bounding_box[2]== face.Bounding_box[2]
&& Bounding_box[3]== face.Bounding_box[3]);
}

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)

cout << faceID << ‘\n’;

}
}

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]

int boundingBox1 [4] = {60,80,357,652};


int boundingBox2 [4] = {30,70,510,512};
int boundingBox3 [4] = {225,250,143,156};

Face * Face1 = new Face (“Face_0001”, 0, boundingBox1);


Face * Face2 = new Face (“Face_0002”, 0, boundingBox2);
Face * Face3 = new Face (“Face_0003”, 1, boundingBox3);

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.

cout << “The number of face:” << Face_list.size();

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------------------------------------------------------

You might also like