473,394 Members | 1,709 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Function Program

41
Hello,

I need to write a Function program that will check if a function is valid or not and also if the function is onto as well.
Kind of getting started right now, so any ideas will be great.

Thank you!
Sep 9 '07 #1
7 1595
Nepomuk
3,112 Expert 2GB
Hello,

I need to write a Function program that will check if a function is valid or not and also if the function is onto as well.
Kind of getting started right now, so any ideas will be great.

Thank you!
In what form will the function, which should be checked, be given to the checker function and what type of functions should they be? Should the syntax be checked or the result? Can the functions have side effects and if so, should those be checked too? We'll need some more information, to be able to help you.

Greetings,
Nepomuk
Sep 9 '07 #2
d0ugg
41
Hi,

Thanks for the quick answer.

For example,

Given the function f, from {1 2 3 4 5}, to itself. Than I have to check if it is a one-to-one function and also if it is a onto function.
The program will test the following functions:
f(1) = 4
f(2) = 3
f(3) = 1
f(5) = 2

Thank you
Sep 9 '07 #3
Nepomuk
3,112 Expert 2GB
Hi,

Thanks for the quick answer.

For example,

Given the function f, from {1 2 3 4 5}, to itself. Than I have to check if it is a one-to-one function and also if it is a onto function.
The program will test the following functions:
f(1) = 4
f(2) = 3
f(3) = 1
f(5) = 2

Thank you
OK, you're talking about a mathematical function f: X -> Y, where X = {1,2,3,4,5} and you want to know, if its injective and/or surjective?

I guess, it depends. If you only have relatively small sets (X and Y), you could use a for-loop to check every single value, create a set from the results and check, if the elements are equal or whatever you want to know. If however you have a big set (e.g. a set with infinite elements), you'll have to somehow code a method, which will prove or disprove that the given function is one-to-one/onto.

I guess, these sites will help:
Proving Functions are One-to-One
Proving Functions are Onto
Thank's to Google for those. :-)

Greetings,
Nepomuk
Sep 9 '07 #4
d0ugg
41
Okay,

I like the idea of the for loop.

Thank you,

Doug
Sep 10 '07 #5
d0ugg
41
Hey,

So I started the code, and I'm getting 2 errors from the compile that I can't figure it out..
The errors are in those lines
Expand|Select|Wrap|Line Numbers
  1.  
  2. if (testA == 1 || testA == 2 || testA== 3 || testA == 4 || testA == 5)
  3.         {
  4.             if(testB == 2 || testB == 3 || testB = 4 || testB == 5)
  5.             {
  6.                 if(testC == 3 || testC == 4 || testC == 5)
  7.                 {
  8.                     if(testD== 4 || testD ==5)
  9.                     {
  10.                         if(testE ==5)
  11.                                                 {
  12.     System.out.print("\nThat's really good");
  13.                                                }
  14.                     }
  15.                 }
  16.             }                
  17.         }
  18.  
Well I guess I can't do that, the compile says:

function.java:55: operator || cannot be applied to boolean,int
if(testB == 2 || testB == 3 || testB = 4 || testB == 5)


Any ideas?

Thank you,

Doug
Sep 10 '07 #6
r035198x
13,262 8TB
Hey,

So I started the code, and I'm getting 2 errors from the compile that I can't figure it out..
The errors are in those lines
Expand|Select|Wrap|Line Numbers
  1.  
  2. if (testA == 1 || testA == 2 || testA== 3 || testA == 4 || testA == 5)
  3.         {
  4.             if(testB == 2 || testB == 3 || testB = 4 || testB == 5)
  5.             {
  6.                 if(testC == 3 || testC == 4 || testC == 5)
  7.                 {
  8.                     if(testD== 4 || testD ==5)
  9.                     {
  10.                         if(testE ==5)
  11.                                                 {
  12.     System.out.print("\nThat's really good");
  13.                                                }
  14.                     }
  15.                 }
  16.             }                
  17.         }
  18.  
Well I guess I can't do that, the compile says:

function.java:55: operator || cannot be applied to boolean,int
if(testB == 2 || testB == 3 || testB = 4 || testB == 5)


Any ideas?

Thank you,

Doug
Ever heard of a switch?
Sep 10 '07 #7
Nepomuk
3,112 Expert 2GB
Hey,

So I started the code, and I'm getting 2 errors from the compile that I can't figure it out..
The errors are in those lines
Expand|Select|Wrap|Line Numbers
  1.  
  2. if (testA == 1 || testA == 2 || testA== 3 || testA == 4 || testA == 5)
  3.         {
  4.             if(testB == 2 || testB == 3 || testB = 4 || testB == 5)
  5.             {
  6.                 if(testC == 3 || testC == 4 || testC == 5)
  7.                 {
  8.                     if(testD== 4 || testD ==5)
  9.                     {
  10.                         if(testE ==5)
  11.                                                 {
  12.     System.out.print("\nThat's really good");
  13.                                                }
  14.                     }
  15.                 }
  16.             }                
  17.         }
  18.  
Well I guess I can't do that, the compile says:

function.java:55: operator || cannot be applied to boolean,int
if(testB == 2 || testB == 3 || testB = 4 || testB == 5)


Any ideas?

Thank you,

Doug
You've left out a "=":

function.java:55: operator || cannot be applied to boolean,int
if(testB == 2 || testB == 3 || testB = 4 || testB == 5)

But as r035198x said, use switch for that part - it will be much easier.

Greetings,
Nepomuk
Sep 10 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

35
by: wired | last post by:
Hi, I've just taught myself C++, so I haven't learnt much about style or the like from any single source, and I'm quite styleless as a result. But at the same time, I really want nice code and I...
5
by: phil_gg04 | last post by:
Dear Javascript Experts, Opera seems to have different ideas about the visibility of Javascript functions than other browsers. For example, if I have this code: if (1==2) { function...
5
by: pembed2003 | last post by:
Hi all, I need to write a function to search and replace part of a char* passed in to the function. I came up with the following: char* search_and_replace(char* source,char search,char*...
16
by: junky_fellow | last post by:
I was reading the various posts in this newsgroup, and found that main function should be declared as int main(void) // if no arguments are passed to main i wanted to know whats the purpose of...
38
by: maadhuu | last post by:
does it make sense to find the size of a function ??? something like sizeof(main) ??? thanking you ranjan.
13
by: Bern McCarty | last post by:
I have run an experiment to try to learn some things about floating point performance in managed C++. I am using Visual Studio 2003. I was hoping to get a feel for whether or not it would make...
89
by: Cuthbert | last post by:
After compiling the source code with gcc v.4.1.1, I got a warning message: "/tmp/ccixzSIL.o: In function 'main';ex.c: (.text+0x9a): warning: the 'gets' function is dangerous and should not be...
2
by: f rom | last post by:
----- Forwarded Message ---- From: Josiah Carlson <jcarlson@uci.edu> To: f rom <etaoinbe@yahoo.com>; wxpython-users@lists.wxwidgets.org Sent: Monday, December 4, 2006 10:03:28 PM Subject: Re: ...
28
by: Bill | last post by:
Hello All, I am trying to pass a struct to a function. How would that best be accomplished? Thanks, Bill
3
by: linarin | last post by:
#include <iostream> using namespace std; typedef bool (*CallableFunction)(int argc,char* argv); void DefineMyFunction(const char* name,CallableFunction func){ //here do the define action. }...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.