Advertisement
BladeMechanics

TestCode

Feb 8th, 2018
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.15 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<conio.h>
  3.  
  4. typedef struct point
  5. {
  6.     int x; int y;
  7. }POINT;
  8.  
  9. int noduplicates(POINT *data, POINT input, int count);
  10. int validPair(POINT input);
  11. void display(POINT input);
  12. POINT getpoint();
  13. void domain(POINT *, int *, int count);
  14. void range(POINT *, int *, int count);
  15. int isReflexive(POINT *data, int *domain, int *range, int count); //if each of the combined values of the domain and range have reflexive pairs
  16. int isSymmetric(POINT *, int count); //if each pair has a symmetric pair
  17. int isTransitive(POINT *data, int count);
  18. int isEq(POINT *, int *);
  19.  
  20.  
  21. void main()
  22. {
  23.     POINT input[81];
  24.     int index = 0; //base count from the initial index
  25.     int domain[9], range[9];
  26.     char selection;
  27.     do
  28.     {
  29.         printf("\n\n\t\tBeginning values SET={1,2,3,4,5,6,7,8,9}");
  30.         printf("\nPlease enter values for ordered pair #%d (x,y)", index + 1);
  31.         input[index] = getpoint();
  32.         if (!validPair(input[index]))
  33.         {
  34.             printf("\n\nInvalid input. An element of the pair does not exist in the original set. Press any key to continue input.");
  35.             _getch();
  36.             continue;
  37.         }
  38.         if (!noduplicates(input, input[index], index))
  39.         {
  40.             printf("\n\nOrdered pair already exists. Press any key to continue input.");
  41.             _getch();
  42.             continue;
  43.         }      
  44.         printf("\n\nDo you want to add more pairs? [Y]es or any other key to continue");
  45.         selection = getchar();
  46.         if ((selection != 'Y') || (selection != 'y')) break;
  47.         index++;
  48.     } while (1);
  49.  
  50. }
  51.  
  52. void domain(POINT *input, int *output, int count)
  53. {
  54.     int temp[9] = { 0 };
  55.     for (int i = 0; i < count + 1; i++)
  56.     {
  57.         temp[input[i].x - 1] = input[i].x;
  58.     }
  59.     for (int i = 0; i < count + 1; i++)
  60.     {
  61.         int j = 0;
  62.         if (temp[i])
  63.         {
  64.             output[j] = temp[i];
  65.             j++;
  66.         }
  67.     }
  68. }
  69. void range(POINT *input, int *output, int count)
  70. {
  71.     int temp[9] = { 0 };
  72.     for (int i = 0; i < count + 1; i++)
  73.     {
  74.         temp[input[i].y - 1] = input[i].y;
  75.     }
  76.     for (int i = 0; i < count + 1; i++)
  77.     {
  78.         int j = 0;
  79.         if (temp[i])
  80.         {
  81.             output[j] = temp[i];
  82.             j++;
  83.         }
  84.     }
  85. }
  86.  
  87. int isReflexive(POINT *data, int *domain, int *range, int count)
  88. {
  89.     int temp[9] = { 0 }, i, j, propertypoints = 0, entrycount = 0;
  90.     for (i = 0; i < 9; i++)
  91.     {
  92.         if (domain[i]) temp[domain[i] - 1] = domain[i];
  93.         if (range[i]) temp[range[i] - 1] = range[i];
  94.     }
  95.     //combines domain and range into a single array with no duplicates, blanks are 0.
  96.     for (i = 0; i < 9; i++)
  97.     {
  98.         //if the array cell has content other than 0
  99.         if (temp[i])
  100.             //add to the count of possible reflex pairs
  101.             entrycount++;
  102.             //compare with the points if a reflex pair exists
  103.             for (j = 0; j < count + 1; j++)
  104.                 //if a pair (temp[i],temp[i]) exists add a point to the property
  105.                 if (data[j].x == temp[i] && data[j].y == temp[i])
  106.                 {
  107.                     entrycount++;
  108.                     break;
  109.                 }
  110.     }
  111.     if (propertypoints == entrycount) return 1;
  112.     else return 0;
  113. }
  114.  
  115. int isSymmetric(POINT *data, int count)
  116. {
  117.     int i, j, propertypoints=0;
  118.     for (i = 0; i < count + 1; i++)
  119.     {
  120.         for (j = 0; j < count + 1; j++)
  121.             if ((data[i].x == data[j].y) && (data[i].y == data[j].x)) propertypoints++;
  122.     }
  123.     if (propertypoints == count + 1) return 1;
  124.     else return 0;
  125. }
  126. int isTransitive(POINT *data, int count)
  127. {
  128.     int a, b, c, propertypoints = 0;
  129.     for (a = 0; a < count + 1; a++)
  130.         for (b = 0; b < count + 1; b++)
  131.             for (c = 0; c < count + 1; c++)
  132.                 if (data[a].y == data[b].x)
  133.                     if (((data[a].x == data[c].x) && (data[a].y == data[c].y)) || ((data[b].x == data[c].x) && (data[a].y == data[c].y)))
  134.                         propertypoints++;
  135.    
  136.     if
  137. }
  138.  
  139. int isEq(POINT *input, int *size)
  140. {
  141. }
  142.  
  143. POINT getpoint()
  144. {
  145.     POINT input;
  146.     printf("\nX = ");  scanf_s("%d", &input.x);
  147.     printf("\nY = ");  scanf_s("%d", &input.y);
  148.     return input;
  149. }
  150.  
  151. void display(POINT input)
  152. {
  153.     printf("(%d,%d)", input.x, input.y);
  154. }
  155.  
  156. int validPair(POINT input)
  157. {
  158.     int control = 0;
  159.     for (int i = 1; i <= 9; i++)
  160.     {
  161.         if (input.x == i) control++;
  162.         if (input.y == i) control++;
  163.         if (control == 2) break;
  164.     }
  165.     if (control == 2) return 1;
  166.     else return 0;
  167. }
  168.  
  169. int noduplicates(POINT *data, POINT input, int count)
  170. {
  171.     for (int i = 0; i < count + 1; i++)
  172.         if ((input.x == data[i].x) && (input.y == data[i].y)) return 1;
  173.         else return 0;
  174. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement