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, 22.06.2019 10:30
Dave has to create animations for a game. which tool can dave use?
Answers: 3
question
Computers and Technology, 22.06.2019 18:30
What is outfitting a workplace with video in a technology
Answers: 2
question
Computers and Technology, 23.06.2019 06:30
To become an audio technician, the most successful tactics might include the following. (select all that apply). learning how to persuade other people gaining different types of experience in audio technology learning as much as possible about art history establishing a reputation as a reliable professional
Answers: 1
question
Computers and Technology, 25.06.2019 00:30
Which email writing etiquette should ariel follow to let people know that she received their message? a. reply to their messages immediately b. use formal language c. specify the email's intent in the subject field d. be direct when writing the reply
Answers: 1
You know the right answer?
No documentation (commenting) is required on this assignment. convert the orderedpair class, which i...
Questions
question
Mathematics, 06.11.2020 18:30
question
Social Studies, 06.11.2020 18:30
question
Mathematics, 06.11.2020 18:30
question
Mathematics, 06.11.2020 18:30
question
Mathematics, 06.11.2020 18:30
Questions on the website: 13722359