Question: My assignment: Define a template class for a generic triplet. The private data member for the triplet is a generic array with three elements. The

My assignment:

Define a template class for a generic triplet. The private data member for the triplet is a generic array with three elements. The triplet ADT has the following functions:

default constructor

explicit constructor: initialize the data member using parameters

three accessors (three get functions) which will return the value of each individual element of the array data member

one mutator (set function) which will assign values to the data member using paramenters

find_max function which will find the maximum value of the array and return it

find_min function which will find the minimum value of the array and return it

sort_ascending function which will sort the array data member into ascending order

sort_descending function which will sort the array data member into descending order

an overloaded comparison operator == which will compare if two triplets are exactly the same

an overloaded output operator to output items in the triplet.

Write a driver to test your class. It should test each function for

o a triplet of strings

o a triplet of integers

For credit: Show your code and execute the test program.

Here is what I have so far:

Header.h

#include #include using namespace std; template class triplet { public: T A, B, C; triplet() //Purpose: default constructor //Precondition: array //Postcondition: array is declared as empty { T a = 0; T b = 0; T c = 0; }; triplet(T a, T b, T c) //Purpose: explicit constructor //Precondition: array //Postcondition: initalizes the data member with parameters { A = a; B = b; C = c; }; void get_A() //Purpose: returns A value //Precondition: A value //Postcondition: returns A to array { return A; }; void get_B() //Purpose: returns B value //Precondition: B value //Postcondition: returns B to array { return B; }; void get_C() //Purpose: returns C value //Precondition: C value //Postcondition: returns C to array { return C; }; void set(T a, T b, T c) //Purpose: assigns values to the data member //Precondition: data members //Postcondition: values are assigned to the data member { A = a; B = b; C = c; }; T find_max() //Purpose: finds maximum number //Precondition: filled array //Postcondition: returns max number { return max(A, max(B, C)); }; T find_min() //Purpose: finds minimum number //Precondition: filled array //Postcondition: returns min number { return min(A, min(B, C)); }; void sort_ascending() //Purpose: sorts the array in ascending order //Precondition: filled array //Postcondition: returns array in ascending order { for (i = 0; i <= n; i++) { for (j = 0; j <= n - i; j++) { if (a[j]>a[j + 1]) { temp = Arr[j]; Arr[j] = Arr[j + 1]; Arr[j + 1] = temp; } } } cout << " Data after sorting: "; for (j = 0; ja&&t.b == this->b&&t.c == this->c) return true; return false; }; ostream&operator<<(ostream&out, const triplet& list) //Purpose: overloaded output operator //Precondition: filled array //Postcondition: outputs items in the triplet { output << "A B C are: " << list.A << " " << list.B << " " << list.C << endl; return output; } };

Main.cpp

#include "Header.h" #include #include using namespace std; int main() { triplet one(12, 9, 16); cout << one << endl; cout << "Maximum is: " << one.find_max() << endl; cout << "Minimum is: " << one.find_min() << endl; triplet two(hello, hi, bye); cout << two << endl; return 0; }

Am I on the right path?

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!