Problem Solving: Introduction to Sets (Using Functions)

Learn to read sets from a file and sort and display sets using functions. The main focus of this lesson is reusability.

Now that we know how to pass arrays to functions, let’s practice sets and their operations with functions. This lesson will guide you on how the two implementations (with and without functions) differ. We will especially learn how our code gets reduced in length with the use of functions.

Reading sets from a file

Task: Load the two sets, A and B, from the file.

To load a set from the file, we need to write a function, loadSet(), which we can call whenever we need to load a set from the file (expecting the ifstream rdr will be pointing toward the file from where the size and the values of a set should be loaded).

Get hands-on with 1200+ tech skills courses.