I am not looking for someone to write the whole program! Just need help with get
ID: 3639521 • Letter: I
Question
I am not looking for someone to write the whole program! Just need help with getting set input from the user represented as unsigned int. Thanks!
I need help understanding how to accept a set of values from a user and treat them as bit positions in an unsigned integer. I do not think I will need help getting the functions to work, I know I need to make use of the bit operators. I have tried to get this to work and simplified it to just entering one number and trying to get the program to print out the bit representation of the set. Instead I either get a segmentation fault or the same bit set regardless of input. I think it must have something to do with data types. Any tips would be greatly appreciated.
Right now I have:
#include int main(){
unsigned int set1;
int i, userVar;
//ask user which bit to set
printf("enter bit position for set1 (0-31): ");
scanf("%d", userVar);
//set bit set1 = set1 | (1 << userVar);
for (i = 31; i >= 0; i--)
printf("%d ", (set1&(1<> i);
printf(" ");
return 0; }
But that isn't working. Here is a full copy of the assignment:
INTRODUCTION
In this assignment, students will implement a common representation of sets. In completing the assignment students will demonstrate that they can
For our purposes, a set is an arbitrary collection of elements, which may be real or imaginary, physical or abstract. In mathematics, sets are usually composed of abstract things like numbers and points, but one can also talk about sets of trees, UNT students, cars, or television shows. In many applications, the elements are never defined, but are left as abstractions that could be represented in many different ways in the human brain, on a piece of paper, or in computer storage.
Set notation typically uses curly braces to enclose a set specification. For small, finite sets, the specification of a set can be an exhaustive list of all its elements:
{13, 87, 913, 47, 19}.
This specifies a set consisting of the five integers 13, 87, 913, 47 and 19. Since the order of listing the elements is immaterial, the following specification is equivalent to the one above:
{87, 47, 19, 193, 13}.
Some additional definitions of set operations are useful, namely:
To proceed we must first define an abstract data type for sets. An abstract data type consists of two things, a name of the data type and a list of operations defined for that data type. The name of our abstract data type will be set. The list of operations defined for our set abstract data type includes:
ASSIGNMENT SPECIFICS
1
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
1
0
0
0
0
1
0
0
0
1
0
0
0
Bits 31 … 0
SUBMIT
Turn in set.h, set.c and driver.c.
Set.h looks like this:
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
extern unsigned int setUnion(unsigned int set1, unsigned int set2);
extern unsigned int setIntersection(unsigned int set1, unsigned int set2);
extern void clearSet(unsigned int *set);extern void add2Set(unsigned int *set, int value);
extern void deleteFromSet(unsigned int *set, int value);
extern int isMember(unsigned int set, int element);
extern void printSet(unsigned int set);
1
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
1
0
0
0
0
1
0
0
0
1
0
0
0
Explanation / Answer
You are not supposed to read floats, just integers between 0, 31 int N; So use scanf("%d",&N); Read the integer, Consider the set to be an int say unsigned int Set_Value; Clearing Set : Set_Value = 0 Adding an element:(say i) Set_Value = Set_Value | 2Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.