You are on page 1of 5

Ho Chi Minh City University of Technology

Department of Electrical and Electronics Engineering


MIDTERM EXAMINATION – Class TT01 ECE391: Computer System Engineering
Semester 2, 2018-2019, 01/04/2018 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 4 pages Trương Quang


Vinh

Student name: ID:

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


string A[] = {"Bach", "Khoa","office","international","study","program"};
string *p = A;
Questions Answers

a) Use the pointer p to print the element “office” of the


array A, and show it on the screen.
b) Declare a pointer q, and copy the address of the
element A[4] to the pointer q, and show this address on
the screen.
c) Combine words from the array A and show the
phrase “international study program” on the screen.
d) Use the pointer p to exchange the values of A[0] and
A[5].

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


Functions Big-Oh Short explanation
Notation
(6n+3n2)2

4n3logn + 7n3 - 5n2logn

n (2+ 6i)

n (i2 – 8i + 7)
Problem 3: (10pts) Find the Big-Oh Notation of the following functions
Functions Big-Oh Short explanation
Notation
bool x_in_array(int A[],int n,int x)
{
int middle,first = 0,last= n-1;
middle = (first+last)/2;
while(first<=last)
{
if(A[middle] < x)
first = middle + 1;
else if(A[middle] == x)
break;
else
last = middle - 1;
middle = (last+first)/2;
}
if (first >last)
return false;
else return true;}
Problem 4: (10pts) Fill in the following table of the Queue operations.
No. Operation Output Rear -> Queue -> Front
1 enqueue(10)
2 enqueue(7)
3 enqueue(3)
4 dequeue()
5 front()
6 dequeue()
7 dequeue()
8 dequeue()
9 isEmpty()
10 size()
Problem 5: (20pts) Given a class Footwear as follows:

class Footwear {
private:
string type;
string brand_name;
string date_of_manufacture;
unsigned int size;
public:
Footwear();
Footwear (unsigned int new_type, string brand_name, string date_of_manufacture,
unsigned int size);
bool operator==(Footwear a);
void show_info(); };
1. (5pts) Write C++ code for a constructor of the class Footwear to initialize a new variable of
Footwear with the default information as below:
type = “NULL”
brand_name = “NULL”
date_of_manufacture= 000000
size = 0
Footwear::Footwear ()
{
this->type=”Null”
This->brand_name=”NULL”
this->date_of_manufacture=”000000”
This->size=0}

2. (5pts) Write C++ code for a constructor of the class Footwear to initialize a new variable of
Footwear with the information of name and size.
Footwear::Footwear(string new_type, string new_brand_name, string new_date_of_manufacture,
unsigned int new_size)
{
this->type=new_type
this->brand_name=new_brand_name
this->date_of_manufacture=new_day_of_manufacture
this->size=newsize}

3. (5pts) Write C++ code for the operator of the class Footwear to compare the two footwears
and return true if two footwears have the same size.
bool Footwear::operator==(Footwear a)
{
if (this->Footwear==Footwear a)
return True;
else return False;
}

4. (5pts) Write C++ code for the function show_info to show all information of the footwear.
void Footwear::show_info()
{

Problem 6: (20pts) Given a vector Footwear_series which is described as follow:


list<Footwear*> Footwear_series;

1. (5pts) Write C++ code to declare three pointers of footwears with the information as
follow:
F1 F2 F3
Type: Lifestyle
Type: Running Type: Sandal
Brand: Saucony
Class Footwear Brand: NB Brand: Bitis
Size: 39
Size: 38 Size: 40

2. (5pts) Write C++ instructions to push three pointers above into the list Product_series

3. (5pts) Write a C++ code to declare the Footwear F4 with the information (“Boxing”,
“Everlast”, 43), insert the Footwear F4 before the F3 and delete F3.

4. (5pts) Write C++ code to show all elements of the list Footwear _series on the screen by
using the Iterator p. (Assume that type, brand, and size are public variables)
--------------------------------------------------------END------------------------------------------------------

You might also like