User defined functions

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Sep 2008
Posts: 65
Reputation: grisha83 is an unknown quantity at this point 
Solved Threads: 0
grisha83's Avatar
grisha83 grisha83 is offline Offline
Junior Poster in Training

User defined functions

 
0
  #1
Sep 8th, 2008
Hello everyone,
Could you please explain to me how to write the user defined functions with multiple arguments? (specifically with 2 or 3 input arguments). And also, how to make one function to manipulate different data each time it is called? (for example area of bigger circle minus area of the smaller circle with one findArea function) To be specific, can you show me Prototype, function definition, and function call?
My C++ book doesn't explain it clearly.
Thank you very much
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,622
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 714
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: User defined functions

 
0
  #2
Sep 8th, 2008
>Could you please explain to me how to write the
>user defined functions with multiple arguments?
There are three patterns for function parameters. First is a function with no parameters:
  1. void foo();
No parameters is described in code using parentheses where there's nothing between them. Next is a single parameter, which is described in code using a variable declaration between the parentheses:
  1. void foo(int bar);
The third pattern applies to all other numbers or parameters, just keep adding variable declarations and separate them with a comma:
  1. void foo(int bar, double baz, string meep);
>how to make one function to manipulate different data each time it is called?
Pass in different values with each call. Those values will be copied into the variables you declare in the parameter list:
  1. #include <iostream>
  2.  
  3. int add_all ( int a, int b, int c )
  4. {
  5. return a + b + c;
  6. }
  7.  
  8. int main()
  9. {
  10. std::cout<< add_all ( 0, 1, 2 ) <<'\n';
  11. std::cout<< add_all ( 3, 4, 5 ) <<'\n';
  12. }
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,358
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1464
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: User defined functions

 
0
  #3
Sep 8th, 2008
There is lots of information on the web that explains those things for you. Just search google
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 65
Reputation: grisha83 is an unknown quantity at this point 
Solved Threads: 0
grisha83's Avatar
grisha83 grisha83 is offline Offline
Junior Poster in Training

Re: User defined functions

 
0
  #4
Sep 8th, 2008
thank you
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 65
Reputation: grisha83 is an unknown quantity at this point 
Solved Threads: 0
grisha83's Avatar
grisha83 grisha83 is offline Offline
Junior Poster in Training

Re: User defined functions

 
0
  #5
Sep 8th, 2008
Thank you
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC