I need help defining two different classes in C++. One class is Term that repres
ID: 3573840 • Letter: I
Question
I need help defining two different classes in C++. One class is Term that represents an autocomplete term: (a query string and an associated integer weight). You can provide three member functions, which support comparing terms by three different orders respectively: lexicographic order by query string; in descending order by weight; and lexicographic order by query string but using only the first r characters. The last order may seem a bit odd, but you will use it in the other class to find all query strings that start with a given prefix (of length r). Each of these three comparing functions returns an integer value: 1, 0 or -1. When comparing two terms, if the first term and the second term are in the right order, it returns 1; if they are in the wrong order, it return -1; if they are the same, it returns 0.
The other class is Autocomplete, which provides autocomplete functionality for a given set of Term objects. For this assignment, use the binary search to efficiently find all query strings that start with a given prefix, and sort the matching terms in descending order by weight. To do so, you need to sort the terms in lexicographic order first, then use binary search to search a sorted array/vector with a given prefix. Since with a given prefix, the matching terms can be more than one, your program needs to get the first and the last such terms in the array/vector, you may implement a member function named search() as follows: void Search(string prefix, int& firstIndex, int& lastIndex); firstIndex and lastIndex are reference parameters, and they represent the index of the first query that equals the search prefix and the index of the last query that equals the search prefix respectively; or -1 if no such prefix can be found.
I have a template for what each class should be but I'm not sure how I should even begin starting.
class Term public: default constructor Term initialize with the given query string and weight Term (string query long weight) compares two terms in descending order by weight int by Reverseweightorder (Term that); compares two terms in lexicographic order by query int compareTo (Term that); ll compares two terms in lexicographic order but using only the first r characters of each query int by Prefixorder (Term that int r) ll displays the term in the following format the weight, followed by a tab key, followed by the query void print other member functions you need... friend class Autocomplete private: string query; long weight;Explanation / Answer
Hii there,Chec kout this code here
code
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.