## Beginner C/C++

Moderators: None (Apply to moderate this forum)
Number of posts: 16951

This Forum Only

help Posted by kook on 10 Nov 2008 at 8:54 PM
this is the question
6. Create a class called Statistic. This class will contain a function called printStatistics that accepts a single integer parameter and returns nothing. Function printStatistics will use the value that was passed to it in order to calculate and print the average, sum, highest and lowest of several integers (the number of integers will be determined by the value of the parameter). For example, if we did something like this:
printStatistics(5), this means that our function needs to find the average, sum, highest and lowest of 5 numbers. To do this, it is advisable to use a loop of some kind that runs 5 times (since the parameter is 5). If the parameter was some other value, then your loop would run that many times. Inside your loop you will need to keep asking the user for a value. You will need to keep track of these values so you can find the sum, average etc. As a hint towards finding the largest and smallest values, you can create two variables, min and max and then assign them both the first value that the user enters. However, you must do this before you enter the loop’s body. Also, since you have gotten the first value from the user, your loop will run one less time. Now, once you are in the body of the loop, ask for a new value and then compare it against both min and max. If the value you just input is larger than max, then max will be assigned this new value. If the value you just input is smaller than min, then min will be assigned this new value. No than Then, run your loop one less time. Of course, you will need to also figure out how to determine sum and average.

this is what i have

{
int sum;
int average;
int maximum;
int minimum;
int i = 0;

cout << "The maximum number is: " << endl;
maximum = i;

for (i = 1; i++)
{
if (i > maximum)
maximum = i;
}
cout << maximum << endl;

cout << "The minimum number is: " << endl;
minimum = i;

for (i = 1; i--)
{
if (i < minimum)
minimum = i;
}
cout << minimum << endl;

sum = ()
cout<<"sum is"<<sum<<endl;
average = ()
cout<<"average is" average<<endl;
}

Re: help Posted by phillcahill on 11 Nov 2008 at 1:04 AM
: this is the question
: 6. Create a class called Statistic. This class will contain a
: function called printStatistics that accepts a single integer
: parameter and returns nothing. Function printStatistics will use
: the value that was passed to it in order to calculate and print the
: average, sum, highest and lowest of several integers (the number of
: integers will be determined by the value of the parameter). For
: example, if we did something like this:
: printStatistics(5), this means that our function needs to find the
: average, sum, highest and lowest of 5 numbers. To do this, it is
: advisable to use a loop of some kind that runs 5 times (since the
: parameter is 5). If the parameter was some other value, then your
: loop would run that many times. Inside your loop you will need to
: keep asking the user for a value. You will need to keep track of
: these values so you can find the sum, average etc. As a hint
: towards finding the largest and smallest values, you can create two
: variables, min and max and then assign them both the first value
: that the user enters. However, you must do this before you enter
: the loop’s body. Also, since you have gotten the first value from
: the user, your loop will run one less time. Now, once you are in
: the body of the loop, ask for a new value and then compare it
: against both min and max. If the value you just input is larger
: than max, then max will be assigned this new value. If the value
: you just input is smaller than min, then min will be assigned this
: new value. No than Then, run your loop one less time. Of course,
: you will need to also figure out how to determine sum and average.
:
:
: this is what i have
:
:
: {
: int sum;
: int average;
: int maximum;
: int minimum;
: int i = 0;
:
: cout << "The maximum number is: " << endl;
: maximum = i;
:
: for (i = 1; i++)
: {
: if (i > maximum)
: maximum = i;
: }
: cout << maximum << endl;
:
: cout << "The minimum number is: " << endl;
: minimum = i;
:
: for (i = 1; i--)
: {
: if (i < minimum)
: minimum = i;
: }
: cout << minimum << endl;
:
: sum = ()
: cout<<"sum is"<<sum<<endl;
: average = ()
: cout<<"average is" average<<endl;
: }
:
:

Hello

I don't see much in the way of a class defintition or function use? The question appears to be asking you to show you are capable of creating a class, a function, and some kind of loop so you should make sure you use all three at least once.

As for an answer i feel it would be wrong to give am actual answer.

Phill.

## Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic