Write it in C++ 1. Declare two arrays to store set 1 and set 2, both with maximu
ID: 3664982 • Letter: W
Question
Write it in C++ 1. Declare two arrays to store set 1 and set 2, both with maximum capacity of 20 elements. Assign the values of {”A”,”B”,”C”,”D”} and {”C”,”D”,”E”} to the arrays. Write a computer program to compute the union of the sets. The result should be {”A”,”B”,”C”,”D”,”E”}.
2. Implement an algorithm to compute the intersection of the sets. The result should be {”C”,”D”}
3. Solve the following exercises using your program.
Let A = {0, 1, 2, 3, 4, 5, 6, 7}, B = {0, 2, 4, 6, 8, 10, 12}, and C = {0, 3, 5, 6, 9}.
Find (a) (A B) C.
(b) (A B) C.
(c) A (B C) and (A B) (A C). Are the results equal?
(d) A0 B0
(e) (A B) 0 B
Explanation / Answer
/* * C Program to Find Union & Intersection of 2 Arrays */ #include #define SIZE 5 void get_value(int arr[]); void print_value(int arr[], int n); void function_sort(int arr[]); int find_intersection(int array1[], int array2[], int intersection_array[]); int find_union(int array1[], int array2[], int union_array[]); void main() { int array1[SIZE], array2[SIZE], intersection_array[SIZE], union_array[SIZE*2]; int num_elements; //input elements of Array1 printf(" Enter the elements of Array 1: n"); get_value(array1); printf(" Elements of Array 1: "); print_value(array1, SIZE); //Sort array 1 function_sort(array1); printf("nnSorted elements of Array 1: "); print_value(array1, SIZE); //input elements of Array2 printf("nnEnter the elements of Array 2: n"); get_value(array2); printf(" Elements of Array 2: "); print_value(array2, SIZE); //Sort array 2 function_sort(array2); printf(" Sorted elements of Array 2: "); print_value(array2, SIZE); //Find Intersection num_elements = find_intersection(array1, array2, intersection_array); printf(" Intersection is: "); print_value(intersection_array, num_elements); //Find Union num_elements = find_union(array1, array2, union_array); printf(" Union is: "); print_value(union_array, num_elements); } void get_value(int arr[]) { int i, j; for (i = 0; iRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.