Solved

C++ overloading functions- VERY URGENT

Posted on 2006-11-27
8
265 Views
Last Modified: 2010-04-16
I'm not really sure about how to overload a function or exactly what that means.  I have to write a program where I have to create a function that accepts two arguments of the same type and computes the arithmetic average.  My instructions say to overload the function to work with three arguments.  I know how to go about writing the program, but I'm not sure exactly how to write the whole overloading part.  Thank you.
0
Comment
Question by:alligarbage
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 18017881
Is this homework?
Just write one function with two arguments and one function with three arguments.
0
 
LVL 6

Expert Comment

by:_iskywalker_
ID: 18017894
Overloading means you use (declare,implement) the same function for diferent types like cout does:
int i;
char c;
cout << i;
cout << c;
will print both types and operate nice, and will not convert the char to int, or vice-versa. Overloading means so only loading a function name over.
So declare the function with 3 arguments and use the function once with 2 and with 3 and you will see, it compiles and do what it should.
0
 
LVL 45

Accepted Solution

by:
sunnycoder earned 500 total points
ID: 18017906
Hi alligarbage,

Simply delcare and define two functions with the same names ... One function would accept two arguments while second would accespt three arguments. Both functions would compute and return average value of the arguments aupplied.

Since this is homework question, we cannot give you code. Give it a shot and if you are still stuck, post back here with code and specific question.

Cheers!
sunnycoder
0
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 
LVL 6

Expert Comment

by:_iskywalker_
ID: 18017941
it doesnt work not only for different arguments number, if you use 2 different argument types it work also
0
 

Expert Comment

by:ManasiD
ID: 18018221
The following code snippets include declarations for two different overloaded Avg functions, with the ability to handle 2 and 3 parameters each.
Note: Where T is the data type of the argument and tParam1/2/3 are the arguments.
You can include your actually values and check.
<Code edited by sunnycoder, Page Editor>
0
 

Author Comment

by:alligarbage
ID: 18025064
Administrator- I didn't include any code in my post, so I'm not sure what you would have edited.  
0
 

Expert Comment

by:epernice
ID: 18033498
The Administrator was actually talking to ManasiD
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Starting up a Project

622 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question