HardwareHeaven.com

HardwareHeaven.com

Looking for the skin chooser?
 
 
  • Home

  • Hardware reviews

  • Articles

  • News

  • Tools

  • Gaming at HardwareHeaven

  • Forums

 

Go Back   HardwareHeaven.com > Forums > Software / Tools > Programming, Coding, (Web)Design


Programming, Coding, (Web)Design Discuss all your programming or design needs with likeminded people.

Reply
 
Thread Tools
Old Oct 1, 2003, 03:00 AM   #1
HardwareHeaven Extreme Member
 
Join Date: Jul 2002
Location: Gurnee Illinois
Posts: 4,677
Rep Power: 0
DriveEuro is on a distinguished road

Donator
C++ help again, damn class.....

Write a function that computes the average and standard deviation of four scores. The standard deviation is defined to be the square root of the average of the four values: (si - a)2 where a is the average of the four scores s1, s2, s3, and s4. The function will have six parameters and will call two other functions. Embed the function in a driver program that allows you to test the function again and again until you tell the program you are finished.

Hint: Look carefully at the function declarations. You will write the definitions of the three functions computeStats,average, and standardDeviation.

OK, i know i have to write these three functions..... but what the hell do I write in the computeStats one??? I dunno and I have NO CLUE..... I mean, the average and standard deviation are kinda self explanitory.... But what code actually goes into the compute stats?

Code:
#include <iostream>
#include <cmath>

using namespace std;

void inputScores (double& s1, double& s2, double& s3, double& s4);
// Precondition: The user is ready to enter four numbers. 
// Postcondition: The values of s1, s2, s3, and s4 are set to the 
// four numbers entered by the user.


void computeStats (double s1, double s2, double s3, double s4,
                   double& avg, double& stdev);
// Precondition: The parameters s1, s2, s3, and s4 contain four numbers.
// Postcondition: The parameters avg and stdev have been set to
// the average and standard deviation, respectively, of the four numbers.


double average (double s1, double s2, double s3, double s4);
// Precondition: The parameters s1, s2, s3, and s4 contain four numbers.
// Returns the average of s1, s2, s3, and s4.


double standardDeviation (double s1, double s2, double s3, double s4, double avg);
// Precondition: The parameters s1, s2, s3, and s4 contain four real numbers 
// and the parameter avg contains the average of the four numbers.
// Returns the standard deviation of s1, s2, s3, and s4.

void printStats (double s1, double s2, double s3, double s4, 
		 double avg, double stdev);
// Precondition: The parameters avg and stdev contain the average
// and standard deviation of the four numbers s1, s2, s3, s4.
// Postcondition: The four numbers along with their average and
// standard deviation have been printed to the screen.



int main ()
{

  double score1, score2, score3, score4;
  double avg, stdev;
  char ans;    // answer to "four more numbers?" question


  do {


    inputScores (score1, score2, score3, score4);
    computeStats (score1, score2, score3, score4, avg, stdev);
    printStats (score1, score2, score3, score4, avg, stdev);


    cout << endl;
    cout << "Try four more numbers (y or n)? ";
    cin >> ans;
    cout << endl;
  }
  while (ans == 'y' || ans == 'Y');

  return 0;
}


void inputScores (double& s1, double& s2, double& s3, double& s4)
{
  cout << "Enter four scores, separated by blank spaces: ";
  cin >> s1 >> s2 >> s3 >> s4;
  cout << endl;
}


	// --------------------------------
	// ----- ENTER YOUR CODE HERE -----
	// --------------------------------


	// --------------------------------
	// --------- END USER CODE --------
	// --------------------------------


void printStats (double s1, double s2, double s3, double s4, 
		 double avg, double stdev)
{
  cout << "The average of " << s1 << ", " << s2 << ", " << s3
       << ", and " << s4 << " is " << avg 
       << " and the standard deviation is " << stdev << endl;

}
Thanks in advance to all of you. This is greatly appreciated.
__________________
[color=orange]ASUS P4P800 Deluxe [color=black]-[/color] 2.4C --> 3300mhz [color=black]-[/color] Mushkin PC3200 at 220 5-2-2-2 (cpu limited) [color=black]-[/color] BBAti 9800Pro at 430/375 [/color]
[color=black]3[/color][color=gray]D[/color]M[color=black]a[/color][color=gray]r[/color]k[color=yellow]01[/color] [color=black]3[/color][color=gray]D[/color]M[color=black]a[/color][color=gray]r[/color]k[color=yellow]03[/color] 1600*1200 1280*1024
DriveEuro is offline   Reply With Quote


Old Oct 1, 2003, 04:26 AM Threadstarter Thread Starter   #2
HardwareHeaven Extreme Member
 
Join Date: Jul 2002
Location: Gurnee Illinois
Posts: 4,677
Rep Power: 0
DriveEuro is on a distinguished road

Donator
No one???
__________________
[color=orange]ASUS P4P800 Deluxe [color=black]-[/color] 2.4C --> 3300mhz [color=black]-[/color] Mushkin PC3200 at 220 5-2-2-2 (cpu limited) [color=black]-[/color] BBAti 9800Pro at 430/375 [/color]
[color=black]3[/color][color=gray]D[/color]M[color=black]a[/color][color=gray]r[/color]k[color=yellow]01[/color] [color=black]3[/color][color=gray]D[/color]M[color=black]a[/color][color=gray]r[/color]k[color=yellow]03[/color] 1600*1200 1280*1024
DriveEuro is offline   Reply With Quote
Old Oct 1, 2003, 07:04 AM   #3
Unbiased.
 
Join Date: Jun 2002
Posts: 4,812
Rep Power: 0
ToshiroOC is on a distinguished road

Sorry, not sure I understand what the assignment is trying to get you to do either. Programming isn't a science where you must have a function like computestats in order to "do it right", but unfortunately your assignment is. If I figure it out I'll post again, but don't hold out hope for me
__________________
[img][/img]
[color=White]Peace be with you, Joe.[/color]
Driverheaven Staff Member (Supermoderator)
ToshiroOC is offline   Reply With Quote
Old Oct 1, 2003, 07:31 AM Threadstarter Thread Starter   #4
HardwareHeaven Extreme Member
 
Join Date: Jul 2002
Location: Gurnee Illinois
Posts: 4,677
Rep Power: 0
DriveEuro is on a distinguished road

Donator
What you need is a function called computeStats (lord knows why...... that's what the online help hinted at)
and you need a function to do average, and another for standard deviation....
__________________
[color=orange]ASUS P4P800 Deluxe [color=black]-[/color] 2.4C --> 3300mhz [color=black]-[/color] Mushkin PC3200 at 220 5-2-2-2 (cpu limited) [color=black]-[/color] BBAti 9800Pro at 430/375 [/color]
[color=black]3[/color][color=gray]D[/color]M[color=black]a[/color][color=gray]r[/color]k[color=yellow]01[/color] [color=black]3[/color][color=gray]D[/color]M[color=black]a[/color][color=gray]r[/color]k[color=yellow]03[/color] 1600*1200 1280*1024
DriveEuro is offline   Reply With Quote
Old Oct 1, 2003, 10:01 AM   #5
confutatis maledictis
 
Vampyromaniac's Avatar
 
Join Date: May 2002
Location: somewhere dark
Posts: 5,974
Rep Power: 77
Vampyromaniac is just really niceVampyromaniac is just really niceVampyromaniac is just really niceVampyromaniac is just really niceVampyromaniac is just really nice
System Specs

Dude can you please stop expecting replies so quickly . . . especially in this section of the forum.
Being pushy won't help your cause.
Thanks



As for your assingnment, I think the computestats function is basically just supposed to call the other two functions. I think it's there just for neatness and/or to make things look structured.
Code:
void computeStats (double s1, double s2, double s3, double s4, double& avg, double& stdev)
{
   avg = average(s1,s2,s3,s4);
   stdev = standardDeviation(s1,s2,s3,s4,avg);
}
Note: consider this as pseudo-code, as I don't really know C++
__________________
Digitalis 3.3
Athlon 64 3000 // ASUS K8V SE Deluxe // 1024MB PC3200 (2-2-2-10 1T)
ATI All-In-Wonder 9700 Pro // 20" Dell 2005FPW (DVI)
M-Audio Revo 7.1 + Philips Acoustic Edge // Klipsch ProMedia 2.1
320/16 Western Digital WD3200KS + 120/8 Seagate 7200.7
NEC ND-3550A 16x DVD±RW + Lite-On 52x24x CD-RW
Antec Sonata case // 480W Antec TruePower

personal bests || Aq'3: 46796 | 3D'01: 20461 | 3D'03: 6336 | 3D'05: 2677 | PC'04: 4605 | PC'02: 7691,9092,1250

Vampyromaniac is offline   Reply With Quote
Old Oct 1, 2003, 02:02 PM Threadstarter Thread Starter   #6
HardwareHeaven Extreme Member
 
Join Date: Jul 2002
Location: Gurnee Illinois
Posts: 4,677
Rep Power: 0
DriveEuro is on a distinguished road

Donator
Vampy, I am not expecting replies so quickly. I only stated "no one" cuz at that point I decided to start studying for anthropology. You know how hard it is to leave something that isn't figured out cuz then it bugs you.

Thanks for your help both of you. Thanks.
__________________
[color=orange]ASUS P4P800 Deluxe [color=black]-[/color] 2.4C --> 3300mhz [color=black]-[/color] Mushkin PC3200 at 220 5-2-2-2 (cpu limited) [color=black]-[/color] BBAti 9800Pro at 430/375 [/color]
[color=black]3[/color][color=gray]D[/color]M[color=black]a[/color][color=gray]r[/color]k[color=yellow]01[/color] [color=black]3[/color][color=gray]D[/color]M[color=black]a[/color][color=gray]r[/color]k[color=yellow]03[/color] 1600*1200 1280*1024
DriveEuro is offline   Reply With Quote
Reply

Thread Tools