Assignment 1.1 and 1.2

1 answer below »
Answered Same DayAug 20, 2021

Answer To: Assignment 1.1 and 1.2

Karthi answered on Aug 21 2021
152 Votes
89947/pairsclient.cpp
#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
(0)));
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;

try
{
x.setFirst(num1);
x.setSecond(num2);
} catch (OrderedPair::DuplicateMemberError e)
{
x.setFirst(OrderedPair::DEFAULT_VALUE);
x.setSecond(OrderedPair::DEFAULT_VALUE);
}

cout << "The resulting OrderedPair: ";
x.print();
cout << endl;
// String Version
cout << endl << "-------------Strings---------------" << endl;
string s1, s2;
OrderedPair myList2[10];

srand(static_cast(time(0)));
cout << "default value: ";
myList2[0].print();
cout << endl;

for (int i = 0; i < 10; i++)
{
string empty = "";
myList2[i].setFirst(empty + char('a' + rand() % 26));
myList2[i].setSecond(empty + char('A' + rand() % 26));
}

myList2[2] = myList2[0] + myList2[1];

if (myList2[0] < myList2[1])
{
myList2[0].print();
cout << " is less than ";
myList2[1].print();
cout << endl;
}

for (int i = 0; i < 10; i++)
{
myList2[i].print();
cout << endl;
}

cout << "Enter two strings to use in an OrderedPair. Make sure they are different: ";
cin >> s1 >> s2;
OrderedPair s;

try
{
s.setFirst(s1);
s.setSecond(s2);
}
catch (OrderedPair::DuplicateMemberError e)
{
s.setFirst(OrderedPair::DEFAULT_VALUE);
s.setSecond(OrderedPair::DEFAULT_VALUE);
}
cout << "The resulting OrderedPair: ";
s.print();
cout << endl;
}
89947/orderedpair.cpp
#include "orderedpair.h"
#include
using namespace std;
namespace...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here