📄 meanmedianmode.cpp
字号:
// Exercise 13.16: MeanMedianMode.cpp
// Application that asks a user to enter 10 numeric survey responses,
// then calculates and displays the mean, median and mode for that
// set of values.
#include <iostream> // required to perform C++ stream I/O
#include <iomanip> // required for parameterized stream manipulators
using namespace std; // for accessing C++ Standard Library members
// function prototypes
void sortArray( int [], int ); // sorts the array of responses
void displayMean( int [], int ); // calculates and displays mean
void displayMedian( int [], int ); // calculates and displays median
void displayMode( int [], int ); // calculates and displays mode
// function main begins program execution
int main()
{
// define variables and declare arrays
// prompt user for and input response
cout << "\nEnter survey response (1-" << MAX_VALUE << "): ";
cin >> response;
while ( responseCounter <= MAX_RESPONSES )
{
// display error message if input is out of range
if ( response < 1 || response > MAX_VALUE )
{
cout << "\nError: Specify a number within the valid range."
<< endl;
} // end if
// otherwise, update arrays
else
{
} // else
// prompt user for and input next response
cout << "\nEnter survey response (1-" << MAX_VALUE << "): ";
cin >> response;
} // end while
return 0; // indicates successful termination
} // end function main
void sortArray( int unsortedArray[], int arraySize)
{
int temporaryValue; // temporary location used to swap elements
// loop to apply the algorithm arraySize times
for ( int pass = 1; pass <= arraySize; pass++ )
{
// loop to perform arraySize comparisons on each pass
for ( int index = 1; index <= arraySize - 1; index++ )
{
// swap elements if they are out of order
if ( unsortedArray[ index ] > unsortedArray[ index + 1 ] )
{
temporaryValue = unsortedArray[ index ];
unsortedArray[ index ] = unsortedArray[ index + 1 ];
unsortedArray[ index + 1 ] = temporaryValue;
} // end if
} // end inner for
} // end outer for
} // end function sortArray
void displayMean( int responseArray[], int arraySize )
{
} // end function displayMean
void displayMedian( int responseArray[], int arraySize )
{
} // end function displayMedian
void displayMode( int frequencyArray[], int arraySize )
{
} // end function displayMode
/**************************************************************************
* (C) Copyright 1992-2005 by Deitel & Associates, Inc. and *
* Pearson Education, Inc. All Rights Reserved. *
* DISCLAIMER: The authors and publisher of this book have used their *
* best efforts in preparing the book. These efforts include the *
* development, research, and testing of the theories and programs *
* to determine their effectiveness. The authors and publisher make *
* no warranty of any kind, expressed or implied, with regard to these *
* programs or to the documentation contained in these books. The authors *
* and publisher shall not be liable in any event for incidental or *
* consequential damages in connection with, or arising out of, the *
* furnishing, performance, or use of these programs. *
**************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -