subject

No documentation (commenting) is required on this assignment. convert the orderedpair class, which is provided below, into a templated class. note that it will only work with types that have the operators + and < and < < overloaded. but you should be able to try your templated class out with types string, mystring, double, feetinches, and fraction. also, create a programmer-defined exception class named "duplicatemembererror" and add an if statement to each of the two mutators to throw this exception if the precondition has not been met. the precondition is given as a comment in the header file. notice that you can test your exception handling by entering the same number twice when prompted for two numbers. put your class in a namespace named "cs_pairs"finally, to show that your class will work with different types, and also to show that you know how to use a templated class as a client, modify the given client file so that it uses your class using int as the type parameter, and then, in the same repeat the code again with a few changes necessary to make it use ordered pairs of strings instead of ordered pairs of ints. one of the things you'll have to change is the generation of the random values for the ordered pairs. here's what i used: string empty = ""; mylist2[i].setfirst(empty + char('a' + rand() % 26)); mylist2[i].setsecond(empty + char('a' + rand() % 26)); here is the header file, orderedpair. h. the syntax for declaring a constant in a class may look mysterious. to use constants in a class, we have to declare it inside the class, then assign it a value outside the class, as you'll see below. (that's actually not true for int constants -- they can be assigned inside the class -- but we want our code to be flexible enough to handle different types.)#include /* precondition for setfirst and setsecond: the values of first and second cannot be equal, except when they are both equal to default_value.*/namespace cs_pairs { class orderedpair { public: // use the first of the following two lines to make the non-templated version work. // use the second one when you begin converting to a templated version. static const int default_value = int(); // static const int default_value; orderedpair(int newfirst = default_value, int newsecond = default_value); void setfirst(int newfirst); void setsecond(int newsecond); int getfirst() const; int getsecond() const; orderedpair operator+(const orderedpair& right) const; bool operator< (const orderedpair& right) const; void print() const; private: int first; int second; }; // leave the following const declaration commented out when you are testing the non-templated version. // uncomment it when you begin converting to a templated version. // to convert to a templated version you will need a template prefix here above this declaration // const int orderedpair: : default_value = int(); }here is the implementation file, orderedpair. cpp#include "orderedpair. h"#include using namespace std; namespace cs_pairs { orderedpair: : orderedpair(int newfirst, int newsecond) { setfirst(newfirst); setsecond(newsecond); } void orderedpair: : setfirst(int newfirst) { // if statement to throw an exception if precondition not met goes here. first = newfirst; } void orderedpair: : setsecond(int newsecond) { // if statement to throw an exception if precondition not met goes here. second = newsecond; } int orderedpair: : getfirst() const { return first; } int orderedpair: : getsecond() const { return second; } orderedpair orderedpair: : operator+(const orderedpair& right) const { return orderedpair(first + right. first, second + right. second); } bool orderedpair: : operator< (const orderedpair& right) const { return first + second < right. first + right. second; } void orderedpair: : print() const { cout < < "(" < < first < < ", " < < second < < ")"; }}here is the client file.#include #include #include #include "orderedpair. h"using namespace std; using namespace cs_pairs; int main() { int num1, num2; orderedpair mylist[10]; srand(static_cast(time(; cout < < "default value: "; mylist[0].print(); cout < < endl; for (int i = 0; i < 10; i++) { mylist[i].setfirst(rand() % 50); mylist[i].setsecond(rand() % 50 + 50); } mylist[2] = mylist[0] + mylist[1]; if (mylist[0] < mylist[1]) { mylist[0].print(); cout < < " is less than "; mylist[1].print(); cout < < endl; } for (int i = 0; i < 10; i++) { mylist[i].print(); cout < < endl; } cout < < "enter two numbers to use in an orderedpair. make sure they are different numbers: "; cin > > num1 > > num2; orderedpair x; /* use this before you've implemented the exception handling in the class: */ x. setfirst(num1); x. setsecond(num2); /* use this after you've implemented the exception handling in the class: try { x. setfirst(num1); x. setsecond(num2); } catch (orderedpair: : duplicatemembererror e) { x. setfirst(0); x. setsecond(0); } */ cout < < "the resulting orderedpair: "; x. print(); cout < < endl; }

ansver
Answers: 1

Another question on Computers and Technology

question
Computers and Technology, 23.06.2019 12:40
Curriculum exam to process a resident's payment, you must click on onesite payments home page. from the a. reports b. my settings o c.transactions o d. rent tab
Answers: 1
question
Computers and Technology, 23.06.2019 13:30
Stops: using the information learned in this course, explain three things you will not do when driving. a. b. c. explain why you will not do these things when driving. starts: using the information learned in this course, explain three things you will do when driving. a. b. c. explain why you will do these particular things when driving. explain one thing you will stop doing as a passenger. explain one thing you will start doing as a passenger.
Answers: 3
question
Computers and Technology, 23.06.2019 17:00
The camera still is bad even with the new iphone xr and especially in low light it is even worst because you can see the pixels more if its in low light. if all you apple customers want apple to fix this then lets fill there feedback with complaints about the can apple do to fix this issue?
Answers: 1
question
Computers and Technology, 24.06.2019 16:50
How many types of string types does python support?
Answers: 1
You know the right answer?
No documentation (commenting) is required on this assignment. convert the orderedpair class, which i...
Questions
question
Mathematics, 02.08.2019 03:30
question
Mathematics, 02.08.2019 03:30
question
Mathematics, 02.08.2019 03:30
Questions on the website: 13722359