For faster services, inquiry about  new assignments submission or  follow ups on your assignments please text us/call us on +1 (251) 265-5102

WhatsApp Widget

CPSC 2600 Winter 2022 Homework Assignment #3 Due date: Feb 9, 2022 11:59pm Write and use a C++ class called IntFunc that models a function that maps inputs in its domain to outputs in its codomain. The universal set for domain and codomain is natural numbers (i.e., ℕ). Requirements and reminders: • The use of STL, templates, and operator overloading is not permitted in any form. • Programs that fail to compile will receive a grade o

CPSC 2600 Winter 2022 Homework Assignment #3

Due date: Feb 9, 2022 11:59pm

Write and use a C++ class called IntFunc that models a function that maps inputs in its domain to outputs in its codomain. The universal set for domain and codomain is natural numbers (i.e., ℕ).
Requirements and reminders:

• The use of STL, templates, and operator overloading is not permitted in any form.

• Programs that fail to compile will receive a grade of 0. You are allowed to re-submit your program before the due date and time, but only the last submission submitted before the due date and time will be graded. Late submissions are not accepted and result in a zero.

Class structure

IntFunc should have the following data members:
• int maxX: the maximum input value. The domain will be {0, 1, … maxX}.

• int maxY: the maximum output value. The codomain will be {0, 1, … maxY}.

• int* outputs: an array that stores outputs.

f(x) = y is represented by setting outputs[x] to y.

For example, f(x) = x2 for x < 5 is represented as
maxX = 4, maxY = 16

outputs = [0, 1, 4, 9, 16]

• You should have another data member called range to keep track of the range of the function. You can either use an array or a linked list.
• You can also use other data members as needed.

Class Functions

Implement the class by creating the following public member functions.

• A parameterized constructor (maxX, maxY).

Ex. IntFunc(4,10) sets the domain = {0, 1, …, 4} and codomain = {0, 1, 2, …, 10}.
• void addPair(int x, int y): Adds (x,y) to the function. If the input already exists, keep the original output and print a warning that an input cannot be mapped to two outputs.
• bool onto() const: Returns true if the function is onto. Returns false otherwise.

• bool oneToOne() const: Returns true if the function is one-to-one. Returns false otherwise.
• void printFx() const: Displays the function to the screen in the format: f(x0) = y0

f(x1) = y1 f(x2) = y2

f(xmaxX) = ymaxX

Refer to the sample execution at the end of the file for more detail.

• void printRange() const: Displays the range of the function.

Note: The elements must appear in a comma separated list in ascending order and there should not be a trailing comma after the last entry. Ex. range={0,3,4,7,9}
• IntFunc inverse() const: If the function is a bijection, returns the inverse function. If not, prints a warning and returns an IntFunc where maxX and maxY are set to 0.

Input File Format

IntFunc will be created in the driver (hw3.cpp) file by reading in a test file corresponding to a function (ex. test1.csv). Check the HW 3 instructions on Canvas for more information on file I/O. The format is as follows:
• The first line contains two integers separated by a comma. The first integer is maxX and the second integer is maxY. Pass these numbers to the parameterized constructure to initialize the
IntFunc object.

• All remaining lines contain two integers separated by a comma that indicate an ordered pair of input and output.

o The first integer is the input and the second integer is the corresponding output. o Add all the pairs to the function until you reach the end of the file.

• Do not make any assumptions about the values. You should check for all edge cases (ex. dealing with duplicate inputs, handling outputs outside the codomain, etc.)

• You can assume that test files test1.csv and test2.csv exist. Do not consider these two files as adequate testing of your class. You should write additional tests to make sure your class is working correctly.

Code Organization

You will use three files for this assignment

• The class definition must be stored in a file called ‘intFunc.h’.

• The class implementation must be stored in a file called ‘intFunc.cpp’.

• The code from part 2 (which includes main) must be stored in a file called ‘hw3.cpp’ .

You can copy starting versions of these files by running:

cp /home/fac/hkong/cpsc2600/hw3/* .

The file intFunc.h contains the class definition and the member function interfaces. Do NOT alter the member function interfaces. You can add data members and additional private member functions if appropriate.

The file intFunc.cpp contains the function implementations. You can also add additional private member functions.

Write all the tests in the hw3.cpp file.

To compile the program (creating executable file called hw3), use:

g++ hw3.cpp intSet.cpp -o hw3

Submitting your Program

On cs1, run the following script in the directory with your program:

/home/fac/hkong/submit/cpsc2600/hw3_submit

Sample Execution on test1.csv and test2.csv

[HW3]./hw3

TESTING FROM test1.csv
f(0) = 5
f(1) = 3

f(2) = 6
f(3) = 7

f(4) = 10
range = {3, 5, 6, 7, 10}
f(x) is not onto.

f(x) is one-to-one.

The inverse function:

This function is not a bijection. f(0) = 0

TESTING FROM test2.csv

f(0) = 5

f(1) = 3
f(2) = 4

f(3) = 0
f(4) = 2
f(5) = 1

range = {0, 1, 2, 3, 4, 5}
f(x) is onto.

f(x) is one-to-one.

The inverse function:

f(0) = 3
f(1) = 5

f(2) = 4
f(3) = 1
f(4) = 2

f(5) = 0

WhatsApp
Hello! Need help with your assignments?

For faster services, inquiry about  new assignments submission or  follow ups on your assignments please text us/call us on +1 (251) 265-5102

We accept Cash App, Zelle, Apple Pay, Google Pay, and Stripe. Contact support for more info!Submit Your Questions to Writers for FREE!!

X
GET YOUR PAPER DONE