**Description**

In this final assignment, the students will demonstrate their ability to apply two major

constructs of the C programming language – Functions and Arrays – to solve computational

problems.

Arrays provide a convenient way to store ‘lists’ of homogeneous data. However, using arrays is

just one way to organize data; there are numerous other data structure types that are used for

computation. Unlike arrays, these data structures cannot be declared or used natively. Before

we can store data in a structure and perform operations specific to that structure, we must

implement them using “built-in” C constructs, possibly using C arrays.

One such example of data structure without C native support – is a set. In mathematics, a set is

a collection of distinct values with well-defined properties and operations. Using notations and

symbols from basic set theory, some common operations involving sets are the following:

Union: The union of any two given sets, A and B, is the set of all values that are members of

either A or B. The union operation is represented by the ∪ symbol.

A ∪ B = {x|x ∈ A or x ∈ B}**Example**: {1,2,3} ∪ {1,2, 4,5} = {1,2, 3, 4,5}

Intersection: The intersection of any two given sets, A and B, is the set of all values that are

common in both A and B. The intersection operation is represented by the ∩ symbol.

A ∩ B = {x|x ∈ A and x ∈ B}

Example: {1,2,3} ∪ {2,4,5} = {2}

{1,2} ∪ {4,5} = {} (empty set)

Subtraction: the subtraction of a set B, from another set A, is the set of values that are

member(s) of A, but not members of B.

A − B = {x|x ∈ A and x ∉ B}

Example: {1,2,3} − {2,4,5} = {1,3}

You are asked to perform an array implementation of sets to emulate input, output and

manipulation of set-like collections of data. You will write several c functions in a way such that

a main() function(or any other ‘user’ function) can call your implemented functions and pass

array type parameters to store and manipulate sets. Specifically, you have to define the

following functions.

1) void set_init(int set_arr[]);

When invoked, the set_init function will modify its integer array argument in a way

such that the array contents represent an empty set.

2) void set_input(int set_arr[]);

When invoked, the set_input() function will prompt the user for inputs into the

set(represented by the argument array). After each set input, the function will keep re-

prompting for further inputs until the user enters -1. After the -1 input, the function will

return successfully while the argument array will contain the user set inputs.

3) void set_output(const int set_arr[]);

When invoked, the set_output function will print the set members, comma-separated

and within braces. If the set corresponding the argument array is empty, the function will

simply print “{}”. DO NOT print any additional message or characters before or after the

braces(not even the newline character).

4) int set_cardinality(const int set_arr[]);

When invoked, the set_cardinality function returns the “cardinality”(the number of

items/members) of the argument set.

5) int set_contains(const int set_arr[], int value);

The function returns 1(true) if value is a member of the set set_arr, and 0 otherwise.

6) void set_union(const int set_A[], const int set_B[],

int set_union[]);

The set_union function calculates the “union” operation of two sets represented by

the first two array argument. The set resulting from the union operation will be populated into

the third argument.

7) void set_intersection(const int set_A[], const int set_B[],

int set_intersect[]);

The set_intersection function calculates the “intersection” operation of two sets

represented by the first two array argument. The set resulting from the intersection operation

will be populated into the third argument.

8) void set_subtraction (const int set_A[], const int set_B[],

int set_sub[]);

The set_subtraction function calculates the “subtraction” operation of two sets

represented by the first two array argument. The set resulting from the subtraction operation

will be populated into the third argument.

This may seem a lot of functions, but fortunately, some of the above functions have very

similar structures. Any of these functions may (and absolutely should) call or ‘use’ the

other functions in its definition, and thus, avoid redundancy in code.

A sample program that ‘uses’ the above functions is given below. You may use the

following main() function to test your program; however you are encouraged write your

own main() function differently in a way that comprehensively tests the correctness of

your implemented functions:

#include

void set_init(int []);

void set_input(int []);

void set_output(const int []);

int set_cardinality(const int []);

int set_contains(const int [], int);

void set_union(const int [], const int [],int []);

void set_intersection(const int [],const int [], int []);

void set_subtraction (const int [], const int [], int []);

#define MAX_SET_SIZE 1000

int main()

{

int A[MAX_SET_SIZE];

int B[MAX_SET_SIZE];

int uni[MAX_SET_SIZE];

int inter[MAX_SET_SIZE];

int sub1[MAX_SET_SIZE], sub2[MAX_SET_SIZE];

set_init(A);

set_init(B);

printf("This program will input data into two sets, perform some basic set");

printf(" operations over them, and output the result of sich operationsn");

printf("Printing the set contents. Both should be empty setsn");

printf("Set A: ");

set_output(A);

printf("t Set B: ");

set_output(B);

printf("n");

printf("Before input, cardinality of A and B is %d and %d respectively n",

set_cardinality(A),set_cardinality(B));

printf("Now reading inputs into set An");

set_input(A);

printf("Now reading inputs into set Bn");

set_input(A);

printf("Printing the set contents after input.n");

printf("Set A: ");

set_output(A);

printf("t Set B: ");

set_output(B);

printf("n");

printf("After input, cardinality of A and B is now %d and %d respectively n",

set_cardinality(A),set_cardinality(B));

// set_contains() not tested here.

//Write your own test cases for set_contains() and enter inputs accordingly

set_union(A,B,uni);

set_intersection(A,B,inter);

set_subtraction(A,B,sub1);

set_subtraction(B,A,sub2);

printf("nn A UNION B is: ");

set_output(uni);

printf("nn A INTERSECTION B is: ");

set_output(inter);

printf("nn A - B is: ");

set_output(sub1);

printf("nn B - A is: ");

set_output(sub2);

printf("That's all Folks!n");

return 0;

}

Assumptions:

We assume that the all sets and arrays will store non-negative integer type of data

We assume that all arrays passed as arguments to the above functions, will have sufficient

capacity(at least 1000) to store the sets

We further assume that while executing the set_input() function, the user will not input

duplicate values into the same set.

Submission instructions:

You will only turn in ONE source code file containing the implementation of the aforementioned six

function. DO NOT submit your main() function or any program executable file. Your source code must

have the name array_set.c . Make sure that the file containing your source code compiles successfully

at the SECS Linux servers without any compilation errors or warnings. Be sure to test the correctness of

your program by running the program with an appropriate main() function with different user inputs

and see it the output matches your expected results.

At the beginning of your source code, you will need to provide a comment block of the following format

/* Name:

Assignment:

Due Date:

Last Modified:

About this project: this project's goals are/what tasks it accomplishes>

Known Issues: your program>

*/

**Rules/Guidelines**:

You may not use global variables to complete this assignment

Each compilation warning in your program will cause 5% penalty to your total grade; and may be

accumulated up to 20% of your grade.

A submitted program that does not compile will incur heavy penalty worth up to 50% of your

total grade

Throughout your program, you should follow appropriate good programming practices. Failing to

maintain consistency and recommended style in coding will result in penalty to your grade.

o Identifiers(a.k.a variable names) should be meaningful and descriptive, but not too long

o Comments in the same section or on consecutive lines should be aligned with each

other(start from the same cursor position)

o Separate different "sections" of code with blank lines

All content inside a scope, bounded by a pair of curly braces, { and }, should always be indented

by a few spaces to the right. This maintains the structure and readability of your program. It also

helps to find program bugs caused by mismatched/missing braces

Path finding involves finding a path from A to B. Typically we want the path to have certain properties,such as being the shortest or to avoid going t

Develop a program to emulate a purchase transaction at a retail store. Thisprogram will have two classes, a LineItem class and a Transaction class. Th

1 Project 1 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of

1 Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of

1Project 1The first programming project involves writing a program that parses, using recursive descent, a GUIdefinition language defined in an input

(5/5)

Buy Now
$35 USD
Get Free Quote!

433 Experts Online