Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

need this is programing c 1 Overview In mathematics a mapping is generally considered as a relation between two values. We can say, for example,

need this is programing c

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

1 Overview In mathematics a mapping is generally considered as a relation between two values. We can say, for example, that 5 is related to false and denote it as 5 + false; we could think of this relation as "is even for the value 5. Mappings can be represented as key-value pairs, i.e. (5, false). Mappings define functions and we often consider sets of mappings. For example, the function is even for integers could be defined as is_even = = {...,(-2, true),(-1, false), (0, true), (1, false), (2, true), ...} where the domain consists of the set of all integers (Z) and the range is the set {true, false} (B). Note that for a mapping to represent a function it must represent a relation that associates each element in its domain set to a single value in the range set. This can also be referred to as the Cartesian product of sets Z and B, denoted as Zx B = {(a,b)|a ZABEB} where every value a is unique. In Computer Science a mapping with a finite set for the domain is often referred to as a finite mapping (or finite function; note that this definition is different than a finite function in math- ematics). Consider, for example, the following finite mapping/function for the first 8 Fibonacci numbers (which are 1,1,2,3,5,8,13,21): fib= {(1,1), (2, 1), (3, 2), (4,3), (5,5), (6,8), (7, 13), (8, 21)} We then say that fib(3) = 2, fib(7) = 13, etc. Note that this function returns no value, and is therefore undefined, for any domain value d such that d&{1,2,...,7,8}. Let's define a function called mappings that maps integers to integers. Given X,Y E ZA mappings C X XY, then Va e Z, VY EZ, VZ EZ, ((x, y) E mappings A (x, 2) mappings) 3y= 2 The primary objective for this project is to write an abstract data type (ADT) that implements the mappings type defined above. Essentially this will involve you writing code to define and maintain a list of pairs of integers where the first item in the pair is unique. To accomplish this you will also need to develop a simple ADT to represent and manipulate integer pairs. 2 intPair ADT The intPair ADT will be used to create and manipulate your ordered integer pairs. And whereas you will need to implement this module, you will not turn it in - I will use my own implementation to test your mappings module. The intPair.h specification file listed below is available for download off of the class Canvas pages. You will need to implement this module in file intPair.c. To aid you in your module development I have provided a Unity test file (intPairUnity.c) downloadable off of the class Canvas pages. #ifndef INTPAIR_H #define INTPAIR_H typedef struct { int left, right; } intPair; void createPair(intPair* p, int 1, int r); // returns pair (1,r) in p int getLeft(int Pair); // returns the left value in pair int getRight(intPair); // returns the right value in pair void setLeft(intPair* p, int); // sets the left value in pair p void setRight(intPair* p,int); // sets the right value in pair p char *toString(intPair); // returns a string representation of a pair; // the pair (1,2) would be represented by "(1,2)" #endif 3 mappings Specification Here is a listing of the specification file mappings.h (also downloadable off of the Canvas class pages). #include #include #ifndef MAPPINGS_H #define MAPPINGS_H typedef struct { intPair *data; int arraySize, listSize, expandSize; } mappings; our data array // the size of the array // number of mappings in list // size of each expansion of list as needed #define NOT_A_VALUE INT_MIN #define NOT_A_VALUE INT_MIN mappings *createMappings(); // returns a malloc'ed mappings value void destroyMappings (mappings*); // free's both the data array & mappings structure int addMapping (mappings*, intPair p); // adds p to end of list only if left value is unique; // returns index of value added, -1 if nothing is added; 2 1/ expands array as needed int removeMapping (mappings*, int n); // removes mapping where left == n; returns index of item // removed or -1 if item isn't found bool removeAt (mappings*, int i); // removes mapping at location i, returning true if item // is removed; does nothing and returns false if item // does not exist int funcCall(mappings* f,int 1); // calls function f with l; returns NOT_A_VALUE if i // is not in domain of f bool inDomain(mappings* f,int 1); // returns true if 1 in domain of f, false otherwise int size (mappings*); // returns number of pairs in list bool isEmpty(mappings*); // returns true if mapping is empty, false otherwise char *mappingsToString(mappings*); // returns a string representation of mapping; an empty // mapping: "[]"; mapping (1,2),(2,3), (3,4) would be // represented by s = "[(1,2),(2,3), (3,4))"; string returned 1/ should be the exact necessary size to store string, i.e. 1/ strlen(s) = 19 stored in returned char array with 20 cells #endif 4 Sample Driver A sample drive program, mappingsDrive.c, is given below. Note the command used on the com- mand line to compile the entire project. #include #include #include "intPair.h" #include "mappings.h" int main(void) { mappings *m = createMappings(); for(int i = 1; i #include #ifndef MAPPINGS_H #define MAPPINGS_H typedef struct { intPair *data; int arraySize, listSize, expandSize; } mappings; our data array // the size of the array // number of mappings in list // size of each expansion of list as needed #define NOT_A_VALUE INT_MIN #define NOT_A_VALUE INT_MIN mappings *createMappings(); // returns a malloc'ed mappings value void destroyMappings (mappings*); // free's both the data array & mappings structure int addMapping (mappings*, intPair p); // adds p to end of list only if left value is unique; // returns index of value added, -1 if nothing is added; 2 1/ expands array as needed int removeMapping (mappings*, int n); // removes mapping where left == n; returns index of item // removed or -1 if item isn't found bool removeAt (mappings*, int i); // removes mapping at location i, returning true if item // is removed; does nothing and returns false if item // does not exist int funcCall(mappings* f,int 1); // calls function f with l; returns NOT_A_VALUE if i // is not in domain of f bool inDomain(mappings* f,int 1); // returns true if 1 in domain of f, false otherwise int size (mappings*); // returns number of pairs in list bool isEmpty(mappings*); // returns true if mapping is empty, false otherwise char *mappingsToString(mappings*); // returns a string representation of mapping; an empty // mapping: "[]"; mapping (1,2),(2,3), (3,4) would be // represented by s = "[(1,2),(2,3), (3,4))"; string returned 1/ should be the exact necessary size to store string, i.e. 1/ strlen(s) = 19 stored in returned char array with 20 cells #endif 4 Sample Driver A sample drive program, mappingsDrive.c, is given below. Note the command used on the com- mand line to compile the entire project. #include #include #include "intPair.h" #include "mappings.h" int main(void) { mappings *m = createMappings(); for(int i = 1; i

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design And SQL For DB2

Authors: James Cooper

1st Edition

1583473572, 978-1583473573

More Books

Students also viewed these Databases questions

Question

Prepare a short profile of Lucy Clifford ?

Answered: 1 week ago

Question

Prepare a short profile of Rosa parks?

Answered: 1 week ago

Question

Prepare a short profile of victor marie hugo ?

Answered: 1 week ago