Write a C++ program that works with relations as arrays of Pairs of integers. Ha
ID: 3670623 • Letter: W
Question
Write a C++ program that works with relations as arrays of Pairs of integers. Have a Pair struct as:
With Pair setup this way you can easily test Pairs for equality and input and print them. Get the file relation.dat or copy it down from .. on cs. This file has 3 relations in it, each one starts with an int which is the number of pairs in that relation, then that many pairs follows. Then (if not eof) read another int and that many pairs again, and so on. For each such array of Pairs, print it out and announce whether it is
Write a bool function for each of 1-4 above that takes an array of Pairs and an int n for how many, and returns true or false for each one.
Explanation / Answer
#include #include #include #include #include using namespace std; struct Pair { int x,y; friend bool operator==(Pair a, Pair b) { return a.x == b.x && a.y == b.y; } friend istream& operator>>(istream& is, Pair& a) { is >> a.x >> a.y; return is; } friend ostream& operatorRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.