Professional Documents
Culture Documents
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()
{
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------------------------------------------------------