Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

COMPLETE FULL REQUUIREMENTS THANKS The sets of possessions must be read in from

ID: 3740701 • Letter: C

Question

COMPLETE FULL REQUUIREMENTS THANKS

The sets of possessions must be read in from a user defined file. The first set will be a comma-delimited list of all possible possessions. All subsequent sets will start with the name of the person followed by a colon, and then a comma-delimited list of possessions owned by that person. Example input files are provided on Canvas.

The initial sets, as well as any resulting sets, must be stored in a bit vector implementation. Each set may be stored in its own bit vector. Remember, a bit vector only stores 1’s and 0’s

Resulting sets, such as the set of total possessions, must be generated via set operations.

You may not use any of the set containers or set operations/algorithms provided by C or C++. o Examples: bitsets, sets, multisets, set_union, set_intersection, set_difference.

Your system must output the initial sets followed by a total set of possessions, a set what items are missing, and a set of what duplicate items you two possess.

The output should be provided to the user in an easy to read and understand format. Outputting a string of only 1’s and 0’s without any description of what each 1 and 0 means, is not easy to read or understand for users unfamiliar with your system.

Your program must provide appropriate error checking for input files that may be malformed, i.e. contains items not in the universal set, or possession list not formed correctly.

Your code must be well commented.

You must provide a short README file which includes your name and explains how to compile and run your program.

Additionally, you may write a makefile if you want your code to compile with additional flags.

Explanation / Answer

ANS:-

  

1. First read the file containing all the possible possessions. Assuming the file will be a text file, you can open the file in read mode and create a list of all the unique items present. let's say we have the following possible possessions(text file 2 example):

PP = [microwave,lamp,guitar,couch,bed,dog,cat,fish,toaster,

clock,table,chair,bookcase,computer,Nintendo Switch,pot,pan]

so, this will be our possession list. Now based on this list we will create our bit vectors for each person's list of possessions.

if we go by given example 2, P1 has bit vector as [1,0,0,1,1,1,0,1,0,0,0,1,1,0,0,0,0] where 1 represents the item is present in PP list(index wise) and 0 means not present.

Similary P2 has [0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0] and [0,1,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0].

2. Therefore, the subsequents sets will be

P1 : [1,0,0,1,1,1,0,1,0,0,0,1,1,0,0,0,0]

P2 : [0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0]

P2 : [0,1,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0]

3. Now to get the resilting sets you can perform set operations. However, as stated in questions you can't use existing C/C++ set operations/algorithms, we can create our own.

4. To get total set of possessions: take all the lists of possessions for a person using person's name. let's take P2 for our example.

P2 has two lists of possessions. first create three empty list.

set_of_possessions = []

set_of_missing_ones = []

set_of_duplicate_ones = []

Now we will iterate from 1 to length of first bit vector(which is 17). And inside loop we will check whether at the given index there are two ones or single one or two zeros present, based on this we will add 1 or 0 to corresponding list.

if both lists have 0 at an index - add 1 to set_of_missing_ones at same index

if at least one list have 1 at an index - add 1 to set_of_possessions at same index

Using above logic, for P2 we will have these lists.

set_of_possessions = [0,1,1,1,1,0,0,0,1,1,1,0,0,0,0,0,0]

set_of_missing_ones = [1,0,0,0,0,1,1,1,0,0,0,1,1,1,1,1,1]

and for P1.

set_of_possessions = [1,0,0,1,1,1,0,1,0,0,0,1,1,0,0,0,0]

set_of_missing_ones = [0,1,1,0,0,0,1,0,1,1,1,0,0,1,1,1,1]

Now, to get the duplicate items P1 and P2 possess, again iterate through set_of_possessions lists for both the persons index wise and add a 1 if both the lists have 1 at the same index.

as a result,

P1 - [1,0,0,1,1,1,0,1,0,0,0,1,1,0,0,0,0]

P2 - [0,1,1,1,1,0,0,0,1,1,1,0,0,0,0,0,0]

set_of_duplicate_ones = [0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0]

5. finally, using indexwise looping on PP and the sets available, you can print them in a better understandable forms like,

P1 has

set_of_possessions = [microwave,couch,bed,dog,fish,chair,bookcase]

set_of_missing_ones = [lamp,guitar,cat,toaster,clock,table,computer,Nintendo Switch,pot,pan]

P2 has

set_of_possessions = [lamp,guitar,couch,bed,toaster,clock,table]

set_of_missing_ones = [microwave,dog,cat,fish,chair,bookcase,computer,Nintendo Switch,pot,pan]

Both P1 and P2 have

set_of_duplicate_ones = [couch,bed]

6. After getting above information, you can print them in a user friendly output.

7. For error handling, while reading ou can check whether an item in a persions possession is in PP or not. if not, display error message like enter a correct item. you can think of other possible use cases similar to this.

8. create a README file including your name and explaination on compiling and running the program(commands for compiling and running a C/C++ program).

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote