Solved

C++ overloading functions- VERY URGENT

Posted on 2006-11-27
8
255 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
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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
A short article about a problem I had getting the GPS LocationListener working.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

707 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now