Question: 1. (Extra) Write and test a program that instantiates a function template that implements a binary search of a sorted array of objects. 2. (Extra)

1. (Extra) Write and test a program that instantiates a function template that implements a binary search

of a sorted array of objects.

2. (Extra) Implement and test a template for generating Queue classes. A queue works like a stack,

except that insertions are made at one end of the linear structure and removed from the other end.

3. Enhance the Vector class below

a. Overload operator string() to return a string of all items.

b. Overload operator<<() to print out the content of each item in the items.

c. Add T& findMax() to return the biggest item

d. Add T& findMax() to return the smallest item

4. Implement a Book class that can be used to create a template of instance of Vector. It may

have other member functions if needed. The Book class has at least data members: title and price.

a. Overload operator<<() to print out the contents of book.

5. Implement a Student class that can be used to create a template of instance of Vector. And

the Student class has at least these data members id, name, gpa, and Vector. It should have a

get function Vector& GetBooks(). It may have other member functions if needed.

a. Overload operator<<() to print out the contents of student.

b. Overload operator>() to check if this students GPA is bigger than others.

c. Overload operator<() to check if this students GPA is smaller than others.

6. Implement a Course class that can be used to create a template of instance of Vector. It has

data members: course title and Vector. It should have a get function Vector&

GetStudents(); It may have other member functions if needed.

a. Add Student& getBestStudent() to return the student who has the highest GPA.

b. Add Student& getWeakestStudent() to return the student who has the lowest GPA.

7. Write a main function that simulates a school model. The school has 2 courses, each course has 2 to

10 students, and each student has 1 to 5 books. So, you can create an instance of Vector to

represent the school, e.g.. Vector school(2);

8. Fill the school object with some sample data (i.e. Since the school object has 2 courses, you will need

to assign data for these two courses, and each course should have 10 students data and their books).

Call the print function that you created in step 3a to print out the entire the school object information.

#include using namespace std;

template class Vector {

protected: T* items;

unsigned int size;

void copy(const Vector& v)

{

int minSize = (size < v.size)? size : v.size; for (int i = 0; i < minSize; i++)

items[i] = v.items[i];

}

public:

Vector(unsigned int n = 10) : size(n) { items = new T[size];

}

Vector(const Vector& v) : size(v.size), items(new T[v.size]) { copy(v);

}

Vector& operator=(const Vector& v) { size = v.size;

items = new T[size]; copy(v);

return *this;

}

T& operator[] (unsigned int i) const { return items[i];

}

unsigned int getsize() { return size;

}

~Vector() { delete [] items;

}

};

int main()

{

Vector v;

for (int i = 0; i < v.getsize(); i++)

{

v[i] = rand() % 100;

}

for (int i = 0; i < v.getsize(); i++)

{

cout << v[i] << '\t';

}

cout << endl; return 0;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!