/*********************************************************************
 * We define the class Edge with accessor functions and a modifier 
 * that edits an Edge to have a given pair of vertices if they are 
 * distinct, and returns false without making any changes if the 
 * vertices are equal. The main allows the user to enter potential 
 * vertices for an Edge, notifies the user of the new values of  
 * vertices of the Edge if the vertices were distinct, and otherwise 
 * notifies the user of the error.
 *
 * The only public constructor fails, issues a warning, and throws an 
 * exception if called with equal vertices.
 * *******************************************************************/ 
#include <iostream>
#include <vector>
#include<stdexcept>
using namespace std;
typedef int vertex;

class Edge{
	//private by default
	vertex a;
	vertex b;
	Edge();//The private designation prevents programmers using this 
	       //from using the 0-parameter constructor.
	
	public:
	Edge(vertex x, vertex y);
	bool set_Edge(vertex x, vertex y);
	
			
	vertex get_a()// Report the value of the 'a' member for the calling 
		//edge. Programmers no longer have direct access.
	{
		return a;
	}
	vertex get_b()
	{
		return b;
	}
	void print_edge()
	{
		cout<<"("<<a<<", "<<b<<")";
		return;
	}
	
};

int main()
{
	vertex a, b;
	Edge e(1,2);
	try
	{
	Edge temp(55,55);
	e=temp;
	}
	catch(domain_error d)
	{
		Edge temp(55, 66);
		e=temp;
	}

	cout<<endl<<"The edge: ";
	e.print_edge();
	cout<<endl;
	cout<<"Enter the edges, space separated: ";
	cin>>a>>b;
	
	if (e.set_Edge(a,b))
		cout<<"The new values of the vertices are "<<e.get_a()
		<<" and "<<e.get_b()<<".\n";
	else
		cout<<"Invalid. the values remain "<<e.get_a()
		<<" and "<<e.get_b()<<".\n";
	cout<<endl<<"The edge: ";
	e.print_edge();
	
	
	return 0;
}


	bool Edge::set_Edge(vertex x, vertex y)
	{
		if(x!=y)
		{
			a=x;
			b=y;
			return true;
		}
		else 
			return false;
	}	

Edge::Edge(vertex x, vertex y)
{
	if(x==y)
	{
		cerr<<"\nInvalid initialization of edge with equal vertices.";
		cerr<<endl;
		throw domain_error ("The vertices in an edge must be distinct");
	}
	a=x;
	b=y;
}






















