Starting from:

$30

Lab: Functions

CS 278 Lab: Functions
Your task is to generate all possible functions from X={a, b, c} to a set Y. Set Y contains integers
1, …, n for some integer n≥1. The value of n is provided by the user. To define a function you
need to specify what it outputs for each element of X. For instance, if Y= {1, 2}, then f(a)=1,
f(b)=2, f(c)=2 defines function f from X to Y.
Write a program that prompts the user to enter the size of Y, then generates, enumerates, and
prints out in a neat format all possible functions from X to Y. Your program should number
generated functions f1, f2, f3, f4, etc. For each generated function, output whether or not it is
one-to-one, onto, or a bijection. Compute total number of functions generated, how many of
them are one-to-one, how many of them are onto, and how many of them are bijections.
Sample dialog with the user may look like the following (user input is in green):
The program will generate all functions from X={a,b,c} to Y={1,…,n}.
Please enter the value of n: 2
f1(a)=1 f1(b)=1 f1(c)=1
 f1 is not one-to-one, not onto, and not a bijection.
f2(a)=1 f2(b)=1 f2(c)=2
 f2 is not one-to-one, onto, and not a bijection.
f3(a)=1 f3(b)=2 f3(c)=1
 f3 is not one-to-one, onto, and not a bijection.
f4(a)=1 f4(b)=2 f4(c)=2
 f4 is not one-to-one, onto, and not a bijection.
f5(a)=2 f5(b)=1 f5(c)=1
 f5 is not one-to-one, onto, and not a bijection.
f6(a)=2 f6(b)=1 f6(c)=2
 f6 is not one-to-one, onto, and not a bijection.
f7(a)=2 f7(b)=2 f7(c)=1
 f7 is not one-to-one, onto, and not a bijection.
f8(a)=2 f8(b)=2 f8(c)=2
 f8 is not one-to-one, not onto, and not a bijection.
There are 8 functions total.
0 of them are one-to-one.
6 of them are onto.
0 of them are bijections.
Implementation details:
All possible functions must be automatically generated by your program (e.g., use nested
loops to do it). Your program must work for any value of n (n≥1) entered by the user (you may
assume that n is no more than 10).
What to submit:
 Submit the source code of your program using Canvas.
 If you write your program in a programming language other than Java, then submit
instructions on how to compile and run your program on CS machines.

More products