Solved

C++ overloading functions- VERY URGENT

Posted on 2006-11-27
8
261 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

RIA (Rich Internet Application) tools are interactive internet applications which have many of the characteristics of desktop applications. The RIA tools typically deliver output either by the way of a site-specific browser or via browser plug-in. T…
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 …
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 …
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…

910 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

24 Experts available now in Live!

Get 1:1 Help Now