You are on page 1of 4

Ho Chi Minh City University of Technology

Department of Electrical and Electronics Engineering


MIDTERM EXAMINATION – Class TT01 ECE391: Computer System Engineering
Semester 3, 2016-2017, 18/7/2017 Duration: 60 minutes
Name: ID:
Score Students are allowed to use one A4 page with two sides for Examiner
signature
reference.
Books and other documents are not allowed to use.
This examination consists of 4 pages

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


char T[] = {‘s’, ‘t’, ‘u’ , ‘d’, ‘y’};
int *p = T;
What shows on the output screen after the following C++ codes. If an instruction makes error,
mark with a tick to the corresponding error box. Give short explanation for each C++ instruction.
No C++ codes Answer Error Short explanation
.
1 cout << *p; s p is the pointer of the first elemen

2 cout << *&*(p+3); d *&*(p+3) is the value of T[3]

3 cout <<*&**p; x error, it should be *&*p

4 cout << **&*&(p+4); y **&*&(p+4) is value of T[4]

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


a. (2n2 + 3)2 is O( n4 )
Explain
(2n2 + 3)2 = 4n4 + 12n2 + 9 < Cn4 for every integer n > n0

b. 2nlogn + 15n2logn + 3n2 is O( n2logn )


Explain
2nlogn + 15n2logn + 3n2 < Cn2logn for every integer n > n0

c. 3/(logn) + 5n/(logn) + 2/n is O( n/logn )

Page 1/4
Explain
3/(logn) + 5n/(logn) + 2/n < Cn/logn for every integer n > n0

d. n (2i2 + 9) is O( n3 )
Explain

n (2i2 + 9)< n (2i2 + 9) di = 2n3/3 + 9n < Cn3 for every integer n > n0

Problem 3: (20pts)

1. (10pts) Fill in the following table of the ADT Stack operations.


No. Operation Output Stack contents -> top
1 push(2) - {2}
2 push(14) - {2,14}
3 push(8) - {2, 14, 8}
4 pop() - {2, 14}
5 push(5) - {2, 14, 5}
6 top() 5 {2, 14, 5}
7 push(7) - {2, 14, 5, 7}
8 pop() - {2, 14, 5}
9 isEmpty() 0 {2, 14, 5}
10 size() 3 {2, 14, 5}

2. (10pts) Write the C++ code to perform the following operations of the deque Q1:
insertFirst(5), insertLast(2), insertLast(7), insertFirst(3), removeFirst(), removeLast(),
insertLast(1), removeFirst(), removeLast().
Q1.push_front(5);
Q1.push_back(2);
Q1.push_back(7);
Q1.push_front(3);
Q1.pop_front();
Q1.pop_back();
Q1.push_back(1);
Q1.pop_front();
Q1.pop_back();

Problem 4: (20pts) Given a database Contacts with the following information:


 Contact_name
 Contact_email

Page 2/4
 Contact_phone_number

1. (5pts) Declare the class Contacts


class Contacts {
private:
string Contact_name;
string Contact_email;
unsigned int Contact_phone_number;
public:
Contacts();
Contacts(string new_name, string new_email, unsigned int new_phone_number);
};

2. (5pts) Write C++ code for a constructor of the class Contacts to initialize a new variable of
Contacts with the default information as below:
Contact _name = “NO NAME”
Contact _email = “NO EMAIL”
Contact _phone_number = 0
Books::Contacts()
{
Contact_name = "NO NAME";
Contact_email = "NO EMAIL";
Contact_phone_number = 0;
}

3. (5pts) Write C++ code for a constructor of the class Contacts to initialize a new variable of
Contacts with the information of name, email, and phone number.
Books:: Contacts(string new_name, string new_email, unsigned int new_phone_number)
{
Contact_name = new_name;
Contact_email = new_email;
Contact_phone_number = new_phone_number;

4. (5pts) Write an operator overloading of the class Contacts that compares two contacts and
return true if two contacts have the same phone number.
bool Contacts::operator==(Contacts a)
{
return (Contact_phone_number == a. Contact_phone_number);
}

Page 3/4
Problem 5: (20pts) Give the C++ program below:
#include <iostream>
#include <list>
using namespace std;
void main() {
list <char> L1;
list <char>::iterator p;

1. (10pts) Write C+ code to push the following characters into the list L1: ‘s’, ‘t’, ‘u’, ‘d’,
‘e’, ‘n’, ‘t’.
L1.push_back('s');
L1.push_back('t');
L1.push_ back ('u');
L1.push_ back ('d');
L1.push_back('e');
L1.push_ back ('n');
L1.push_ back ('t');

2. (5pts) Write C++ instructions to insert the character ‘z’ at the position of the character ‘u’
in the list L1.
p=L1.begin();
p++;
p++;
L1.insert(p, ‘z’);

3. (5pts) Write C++ code to show all members of the list L! on the screen by using the
Iterator p.
for (p = L1.begin( ); p != L1.end( ); p++ )
cout << " " << *Iter;

Lecturer

Dr. Truong Quang Vinh

Page 4/4

You might also like