A set of integers may be implemented using an array of integers. Since the array is only partially filled, it is important to store the number of elements contained in the array. The program contains the array itself and another integer to store the actual number of elements in the set. To illustrate, given a set s =(3, 8, 15, 20) 0 1 2 3 elements 3 8 15 20 4 count - 4 Implement the following functions given the definition: typedef int Set [MAX); void initialise (int *count); simply set count to 0 5 6 - A //Set is just an alias for int [MAX] //Set means an array of integers void display (Set s, int count); display on the screen all valid elements of the array, from 0..count-1 void add (Set s, int *count, int elem); - simply store elem in the array indexed by count then increment count int contains (Set s, int count, int elem); search the array elements for the value elem void getUnion (Set result, int *count, Set sl, int countl, count2); store in the array result the set resulting from the union of s1 and 52 x is an element of s1 union s2 if x is an element of s1 or x is an element of s2 void intersection (Set result, int *count, Set sl, int countl, Set 52, int count2); Set s2, int store in the array result the set resulting from the intersection of s1 and s2 x is an element of s1 intersection s2 if x is an element of s1 and x is an element of s2 void difference (Set result, int *count, Set sl, int countl, count2); Set 52, int store in the array result the set resulting from the difference of s1 and s2 x is an element of s1 - 52 if x is an element of s1 and x is not an element of s2 void symmetricdifference (Set result, int *count, Set sl, int countl, Set 2, int count2); store in the array result the set resulting from the symmetric difference of s1 and s2 x is an element of s1 - s2 if x is an element of s1 and x is not an element of s2 and vice versa int subset (Set sl, int countl, Set 52, int count2); s1 is a subset of s2 if all elements of s1 are in s2 int disjoint (Set sl, int countl, Set 52, int count2);

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter7: Arrays
Section: Chapter Questions
Problem 3PP: (Numerical) Given a one-dimensional array of integer numbers, write and test a function that...
icon
Related questions
Question
A
set of integers may be implemented using an array of integers. Since the array is only partially filled,
it is important to store the number of elements contained in the array. The program contains the array
itself and another integer to store the actual number of elements in the set.
To illustrate, given a set s =(3, 8, 15, 20)
0
1
2 3
elements 3 8
15 20
4
count
-
Implement the following functions given the definition:
typedef int Set [MAX);
void initialise (int *count);
simply set count to 0
4
-
5
void display (Set s, int count);
display on the screen all valid elements of the array, from 0..count-1
void add (Set s, int *count, int elem);
-
6
simply store elem in the array indexed by count then increment count
int contains (Set s, int count, int elem);
search the array elements for the value elem
void getUnion (Set result, int *count, Set sl, int countl,
count2);
-
A
//Set is just an alias for int [MAX]
//Set means an array of integers
store in the array result the set resulting from the union of s1 and 52
x is an element of s1 union s2 if x is an element of s1 or x is an element of s2
void intersection (Set result, int *count, Set sl, int countl, Set 52, int
count2);
-
store in the array result the set resulting from the intersection of s1 and s2
x is an element of s1 intersection s2 if x is an element of s1 and x is an element of s2
void difference (Set result, int *count, Set sl, int countl,
count2);
Project name: SetArray
store in the array result the set resulting from the difference of s1 and s2
x is an element of s1 - 52 if x is an element of s1 and x is not an element of s2
void symmetricdifference (Set result, int *count, Set sl, int countl, Set
s2, int count2);
store in the array result the set resulting from the symmetric difference of s1 and 52
x is an element of s1 - 52 if x is an element of s1 and x is not an element of s2 and vice versa
int subset (Set sl, int countl, Set s2, int count2);
s1 is a subset of s2 if all elements of s1 are in s2
int disjoint (Set sl, int countl, Set s2, int count2);
two sets are disjoint if the intersection is empty
int equal (Set sl, int countl, Set s2, int count 2);
Set s2, int
two sets are equal if they have exactly the same elements
Filenames: set.h, set.c, main.c
Set 52, int
Transcribed Image Text:A set of integers may be implemented using an array of integers. Since the array is only partially filled, it is important to store the number of elements contained in the array. The program contains the array itself and another integer to store the actual number of elements in the set. To illustrate, given a set s =(3, 8, 15, 20) 0 1 2 3 elements 3 8 15 20 4 count - Implement the following functions given the definition: typedef int Set [MAX); void initialise (int *count); simply set count to 0 4 - 5 void display (Set s, int count); display on the screen all valid elements of the array, from 0..count-1 void add (Set s, int *count, int elem); - 6 simply store elem in the array indexed by count then increment count int contains (Set s, int count, int elem); search the array elements for the value elem void getUnion (Set result, int *count, Set sl, int countl, count2); - A //Set is just an alias for int [MAX] //Set means an array of integers store in the array result the set resulting from the union of s1 and 52 x is an element of s1 union s2 if x is an element of s1 or x is an element of s2 void intersection (Set result, int *count, Set sl, int countl, Set 52, int count2); - store in the array result the set resulting from the intersection of s1 and s2 x is an element of s1 intersection s2 if x is an element of s1 and x is an element of s2 void difference (Set result, int *count, Set sl, int countl, count2); Project name: SetArray store in the array result the set resulting from the difference of s1 and s2 x is an element of s1 - 52 if x is an element of s1 and x is not an element of s2 void symmetricdifference (Set result, int *count, Set sl, int countl, Set s2, int count2); store in the array result the set resulting from the symmetric difference of s1 and 52 x is an element of s1 - 52 if x is an element of s1 and x is not an element of s2 and vice versa int subset (Set sl, int countl, Set s2, int count2); s1 is a subset of s2 if all elements of s1 are in s2 int disjoint (Set sl, int countl, Set s2, int count2); two sets are disjoint if the intersection is empty int equal (Set sl, int countl, Set s2, int count 2); Set s2, int two sets are equal if they have exactly the same elements Filenames: set.h, set.c, main.c Set 52, int
Expert Solution
steps

Step by step

Solved in 4 steps with 11 images

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning