Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Current Trends In Database Technology Edbt 2006 Edbt 2006 Workshops Phd Datax Iidb Iiha Icsnw Qlqp Pim Parma And Reactivity On The Web Munich Germany March 2006 Revised Selected Papers Lncs 4254

Authors: Torsten Grust ,Hagen Hopfner ,Arantza Illarramendi ,Stefan Jablonski ,Marco Mesiti ,Sascha Muller ,Paula-Lavinia Patranjan ,Kai-Uwe Sattler ,Myra Spiliopoulou ,Jef Wijsen

2006th Edition

3540467882, 978-3540467885

More Books

Students also viewed these Databases questions