l need help

hello gyz i really need your help!

My professor asked me to write a program of calculating average using class.

A class must have four function,naming "avg2,avg6,avg8,avg10.
now user wants option to select which functions he wants to run.For Example, if user select "avg2" the functions runs in which user can enter only 2 numbers and function returns the average value, if user try to enter more than 2 numbers in "avg2" function than he'll get error.

please help me.

ps: Sorry for bad English>
Hello daimkhalid07,

The people who could help you are not in the habit of writing the program for you.

Post what you have do so far and point what parts you are having a problem with then you will receive help on what is wrong and how to fix it.

Put some code together and post it and that will be a good start.

Your English seems good, much better than my typing.

Andy
not going to do your program for you, ¿what issues are you having?

It seems a waste to code four function that do basically the same, you may just do one function that takes the limit as a parameter.

> if user try to enter more than 2 numbers
¿how does the user say when they are done?
Thank you both of you for your positive response, actually l don't know how to make logic of this program i will thankful if any of you help me out with the logic.

>ne555 actually our professor gave us this assignment at very first day of OOP, thats why facing this problem.
here's a pseudocode
1
2
3
4
5
6
7
8
9
10
11
12
13
while user input //¿how do you determine this?
   increment counter
   if counter > limit
      error 'Too many numbers'
   value.at(counter) := input //¿do you know about arrays?

//computing the sum
sum := 0
for x in value
   sum := sum + x

//computing the mean
avg <- sum/counter
I would save myself some aggravation and write type avg(data, number_of_values) and get_data(num_values)
and then make the others via something like..

type avg2(data)
{
data = get_data(2);
return avg(data,2);
}

Last edited on
Topic archived. No new replies allowed.