Assignment 5
Assignment 5
Programming Fundamentals
CS - 1002
Assignment 05
Due Date: Nov 09, 2022, before 11.59 PM
Submit zip folder containing the .cpp file in google classroom.
Note:
Late submissions will not be accepted in any case.
This is an individual assignment, so in case of plagiarism, your marks will be ZERO in this
assignment.
In this homework, you are to write a single program that performs a number of tasks. You will
submit a single .cpp file containing your program. Basically, the program will implement the
basic functionalities of sets. Since you’re all familiar with the concept of a set from
mathematics, I will not explain it here.
Following is a description of the various tasks the program should perform (in this sequence).
You will define one separate function for each task and then define a main function to check
the functionality of all these functions.
Task 1
Ask the user to enter two sets (of integers). First ask them to enter the size of each set (i.e. the
number of elements in each set), then input these elements. As you know, a set cannot contain
duplicate elements. If the user, while entering the numbers, repeats a number, tell them it’s
already been entered and ask for a different number. By the end of this process, you will have
two sets, say s1 and s2, both containing numbers without repetitions. The numbers can be both
positive and negative.
You may assume that neither set will contain more than 500 elements. So you can create
arrays of capacity 500 each.
Task 2
Print s1 and s2 on the screen in the standard way of writing sets. For example, if s1 contains 1,
5 and 11, and s2 contains -3, 0, 5 and 9, the program should display:
s1 = {1, 5, 11}
s2 = {-3, 0, 5, 9}
For an empty set, print { }
Task 3
Report if s1 is a subset of s2, or s2 is a subset of s1, or neither.
Task 4
Print the union of s1 and s2 on the screen. You should first store this union in a third set and
then print it. For example, for the sets s1 and s2 given above, the program should print:
s1 U s2 = {-3, 0, 1, 5, 9, 11}
Task 5
Print the intersection of s1 and s2 on the screen. You should first store this intersection in a
third set and then print it. For example, for the sets s1 and s2 given above, the program should
print:
s1 ^ s2 = {5}
Task 6
Print the set-differences between s1 and s2 (s1-s2 and s2-s1) on the screen. You should first
store this difference in a third set and then print it. For example, for the sets s1 and s2 given
above, the program should print:
s1 – s2 = {1, 11}
s2 – s1 = {-3, 0, 9}
Task 7
Print the cartesian product of s1 and s2. You should first store the cartesian product in two
separate arrays and then print it. For example, for the sets s1 and s2 given above, the program
should print:
s1 x s2 = {(1, -3), (1, 0), (1, 5), (1, 9), (5, -3), (5, 0), (5, 5), (5,9), (11, -3), (11, 0), (11, 5),
(11, 9)}
Note: the result should first be stored in two separate arrays containing the first entry and
second entry of each pair in the product respectively and then printed in the format above.