Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

2. (40pts) Relation: Prompt users to input 3 integers a, b and c. Define the rel

ID: 3605076 • Letter: 2

Question

2. (40pts) Relation: Prompt users to input 3 integers a, b and c. Define the relation R as "less than or equal" (a) Print out all valid relations among a, b and c. Just print out like aRc, if aRc is valid (b) Print out using graph representation of relations. That is, if aRc is valid, you can connect a and c with an arrow pointing from a to c. For the program, simply print out all valid relations with each one being like a->c in the console. NOTE: For example, a = 1, c = 2, then 1 R2 is valid, represented as a-x (basically, this is an edge of the graph from a to c); also, a is less than or equal to itself, then a->a, which corresponds to an edge from a to itself. You don't need to print out like a graph, this part is used to simply help you remember that a relation can be represented by a directed graph.

Explanation / Answer

#include<iostream>

using namespace std;

int main(){

   int a,b,c;
   cout << "Enter a,b,c numbers : ";
   cin >> a >> b >> c;
  
   cout << "a = " << a << endl;
   cout << "b = " << b << endl;
   cout << "c = " << c << endl;
   cout << "a<->a"<< endl;
   cout << "b<->b"<< endl;
   cout << "c<->c"<< endl;
   if (a <= b) {
      cout << "a->b"<< endl;
   }
   else{
      cout << "b->a"<< endl;
   }
   if (a <= c) {
      cout << "a->c"<< endl;
   }
   else {
      cout << "c->a"<< endl;
   }
   if (b <= c) {
      cout << "b->c"<< endl;
   }
   else {
      cout << "c->b"<< endl;
   }
   return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at drjack9650@gmail.com
Chat Now And Get Quote