Below is posted a program as assigned halfway through my C++ class. I do not need any help doing the project itself, I just need help trying to get through the typographical errors and vagueness! Can someone give a shot at possibly trying to rewrite what he is asking for?

In my opinion one aspect of what he is asking for is conflicted 3 times!


Write a program with overloaded function for computing the average of integers, or appending characters (same name average for both functions). The integer unction should allow between 1 and 5 arguments, the character function between 0 and 5 - all these should be handled with default arguments. Test in an application, program looping until the user says no more (end of the file). Every time through the loop, the program will ask whether integers or characters are being given and how many (1 to 5 or 0 to 5), check the entry, and then will ask for the proper number of inputs separated by spaces. You may assume correct data type and a match beween the number of arguments stated and actually supplied. For characters, the function should produce a dynamically allocated NTS string by appending all the characters, returned by a pointer. Make sure not to leak memory. For integers, the average will be produced (as a float), returned by copy. If the call is made with no arguments, an exception message (string) should be thrown and handled by catching it, displaying "Error: " followed by the actual message thrown, and going on for another iteration of the loop.
Note: there will be different function calls for different number of arguments, thus for example if the user enters 2 characters a and b, the call should be average(a,b) and if the user entered no arguments the call should be average().
Make sure to put the functions in fun.cpp (with fun.h) and the application in app.cpp
For example, this is how the program should run (follow closely, user input in italic):
Welcome to my average program...
What data you have and how many: 1=integers 2=chars: 1 2
Enter 2 integers: 10 20
The result is 15

What data you have and how many: 1=integers 2=chars: 2 2
Enter 2 characters: a b
The result is ab

What data you have and how many: 1=integers 2=chars: ^D

Thank you.

Seems straight forward to me. This is more academic than anything. You wouldn't do it in real life.

You will wind up with 11 functions like

string somefunc()
float somefinc(int a)
float somefunc(int a,b)
...
string somefunc(char a)
string soemfunc(char ab)

The only vague part is returning a float sorta makes no sense, because integer division is taking place, unless your result value is a float like x = a / b; where float x; If x were an int, you would lose the decimals.

Dont get thrown off by the way it should be done rather than the work that needs to be done. You definitely need an array of ints and chars to capture the input. Otherwise your code would be big, but maybe that is what the prof is looking for. Either way you'll get a passing grade. It is much easier to do

if data_type = integer
then *int ary
else *char ary

//ask for datainput
if data_type = integer
//message reads "Enter data_len integers
else
//message reads "Enter data_len characters

case datalen
0: somefunc; break;
1: somefunc(ary[0]);
2: somefunc(ary[0], ary[1]);
...
then repeating all that code over and over. The above code will definitely not compile, but then again you said you didn't need help with the coding :-)

I would throw two additional funcs in there that passes an integer pointer and a char pointer just to show that you know the right way to do things. Do your range checking in there.

float somefunc(*int a)
string somefunc(*char a)

Surely the best person to ask would be your instructor?

Thanks for the responces,

First, my professor does not speak english as clear as he should, so asking questions tends to complicate things. I did that on my last project.

Second, here are the prototypes I assumed he wanted before I posted :

char* average(char a='\0', char b='\0', char c='\0', char d='\0', char e='\0');

float average(int i, int j=0, int k=0, int l=0, int m=0);

One of my problems is trying to understand what he wants me to do with average(); - he has 3 partially contradicting statments in my opinion.

Another problem is how to implement a try, catch, and where to put the throw.

The only person who knows what your instructor wants you to do with average() is your instructor. You need to work through your communications difficulties ;-)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.