Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<conio.h>
- typedef struct point
- {
- int x; int y;
- }POINT;
- int noduplicates(POINT *data, POINT input, int count);
- int validPair(POINT input);
- void display(POINT input);
- POINT getpoint();
- void domain(POINT *, int *, int count);
- void range(POINT *, int *, int count);
- int isReflexive(POINT *data, int *domain, int *range, int count); //if each of the combined values of the domain and range have reflexive pairs
- int isSymmetric(POINT *, int count); //if each pair has a symmetric pair
- int isTransitive(POINT *data, int count);
- int isEq(POINT *, int *);
- void main()
- {
- POINT input[81];
- int index = 0; //base count from the initial index
- int domain[9], range[9];
- char selection;
- do
- {
- printf("\n\n\t\tBeginning values SET={1,2,3,4,5,6,7,8,9}");
- printf("\nPlease enter values for ordered pair #%d (x,y)", index + 1);
- input[index] = getpoint();
- if (!validPair(input[index]))
- {
- printf("\n\nInvalid input. An element of the pair does not exist in the original set. Press any key to continue input.");
- _getch();
- continue;
- }
- if (!noduplicates(input, input[index], index))
- {
- printf("\n\nOrdered pair already exists. Press any key to continue input.");
- _getch();
- continue;
- }
- printf("\n\nDo you want to add more pairs? [Y]es or any other key to continue");
- selection = getchar();
- if ((selection != 'Y') || (selection != 'y')) break;
- index++;
- } while (1);
- }
- void domain(POINT *input, int *output, int count)
- {
- int temp[9] = { 0 };
- for (int i = 0; i < count + 1; i++)
- {
- temp[input[i].x - 1] = input[i].x;
- }
- for (int i = 0; i < count + 1; i++)
- {
- int j = 0;
- if (temp[i])
- {
- output[j] = temp[i];
- j++;
- }
- }
- }
- void range(POINT *input, int *output, int count)
- {
- int temp[9] = { 0 };
- for (int i = 0; i < count + 1; i++)
- {
- temp[input[i].y - 1] = input[i].y;
- }
- for (int i = 0; i < count + 1; i++)
- {
- int j = 0;
- if (temp[i])
- {
- output[j] = temp[i];
- j++;
- }
- }
- }
- int isReflexive(POINT *data, int *domain, int *range, int count)
- {
- int temp[9] = { 0 }, i, j, propertypoints = 0, entrycount = 0;
- for (i = 0; i < 9; i++)
- {
- if (domain[i]) temp[domain[i] - 1] = domain[i];
- if (range[i]) temp[range[i] - 1] = range[i];
- }
- //combines domain and range into a single array with no duplicates, blanks are 0.
- for (i = 0; i < 9; i++)
- {
- //if the array cell has content other than 0
- if (temp[i])
- //add to the count of possible reflex pairs
- entrycount++;
- //compare with the points if a reflex pair exists
- for (j = 0; j < count + 1; j++)
- //if a pair (temp[i],temp[i]) exists add a point to the property
- if (data[j].x == temp[i] && data[j].y == temp[i])
- {
- entrycount++;
- break;
- }
- }
- if (propertypoints == entrycount) return 1;
- else return 0;
- }
- int isSymmetric(POINT *data, int count)
- {
- int i, j, propertypoints=0;
- for (i = 0; i < count + 1; i++)
- {
- for (j = 0; j < count + 1; j++)
- if ((data[i].x == data[j].y) && (data[i].y == data[j].x)) propertypoints++;
- }
- if (propertypoints == count + 1) return 1;
- else return 0;
- }
- int isTransitive(POINT *data, int count)
- {
- int a, b, c, propertypoints = 0;
- for (a = 0; a < count + 1; a++)
- for (b = 0; b < count + 1; b++)
- for (c = 0; c < count + 1; c++)
- if (data[a].y == data[b].x)
- 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)))
- propertypoints++;
- if
- }
- int isEq(POINT *input, int *size)
- {
- }
- POINT getpoint()
- {
- POINT input;
- printf("\nX = "); scanf_s("%d", &input.x);
- printf("\nY = "); scanf_s("%d", &input.y);
- return input;
- }
- void display(POINT input)
- {
- printf("(%d,%d)", input.x, input.y);
- }
- int validPair(POINT input)
- {
- int control = 0;
- for (int i = 1; i <= 9; i++)
- {
- if (input.x == i) control++;
- if (input.y == i) control++;
- if (control == 2) break;
- }
- if (control == 2) return 1;
- else return 0;
- }
- int noduplicates(POINT *data, POINT input, int count)
- {
- for (int i = 0; i < count + 1; i++)
- if ((input.x == data[i].x) && (input.y == data[i].y)) return 1;
- else return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement