Store Statistics Dept Average Above Below Performance ----------------------------------------------------------------------- 1 37.6 7 5 unsatisfied 2 38.6 8 4 satisfied 3 44.9 7 5 unsatisfied 4 51.1 8 4 satisfied 5 43.0 7 5 unsatisfied 6 57.6 11 1 satisfied 7 48.2 9 3 satisfied |
Store Statistics Dept Average Above Below Performance ======================================================================= 1 6.95262e-310 -1987484468 1987484480 2 6.95262e-310 -1987484468 1987484480 3 6.95262e-310 -1987484468 1987484480 4 6.95262e-310 -1987484468 1987484480 5 6.95262e-310 -1987484468 1987484480 6 6.95262e-310 -1987484468 1987484480 7 6.95262e-310 -1987484468 1987484480 Store Statistics Dept Average Above Below Performance ======================================================================= 2 6.95262e-310 -1987484468 1987484480 3 6.95262e-310 -1987484468 1987484480 4 6.95262e-310 -1987484468 1987484480 5 6.95262e-310 -1987484468 1987484480 6 6.95262e-310 -1987484468 1987484480 7 6.95262e-310 -1987484468 1987484480 8 6.95262e-310 -1987484468 1987484480 Store Statistics Dept Average Above Below Performance ======================================================================= 3 6.95262e-310 -1987484468 1987484480 4 6.95262e-310 -1987484468 1987484480 5 6.95262e-310 -1987484468 1987484480 6 6.95262e-310 -1987484468 1987484480 7 6.95262e-310 -1987484468 1987484480 8 6.95262e-310 -1987484468 1987484480 9 6.95262e-310 -1987484468 1987484480 Store Statistics Dept Average Above Below Performance ======================================================================= 4 6.95262e-310 -1987484468 1987484480 5 6.95262e-310 -1987484468 1987484480 6 6.95262e-310 -1987484468 1987484480 7 6.95262e-310 -1987484468 1987484480 8 6.95262e-310 -1987484468 1987484480 9 6.95262e-310 -1987484468 1987484480 10 6.95262e-310 -1987484468 1987484480 |
|
|
fp.open("sales.dat");
warning: no return statement in function returning non-void [-Wreturn-type] double average_Sales (double sales[], int size) In function ‘int above_below(bool*, int)’: 97,99 warning: suggest parentheses around assignment used as truth value [-Wparentheses] if (meet[i] = true) counter++; if (meet[i] = false) counter++; ^ warning: no return statement in function returning non-void [-Wreturn-type] int above_below (bool meet[], int size) |
Store Statistics Dept Average Above Below Performance ======================================================================= 1 31.8417 12 0 2 31.8417 12 0 3 31.8417 12 0 4 31.8417 12 0 5 31.8417 12 0 6 31.8417 12 0 7 31.8417 12 0 Store Statistics Dept Average Above Below Performance ======================================================================= 2 36.7833 12 0 3 36.7833 12 0 4 36.7833 12 0 5 36.7833 12 0 6 36.7833 12 0 7 36.7833 12 0 8 36.7833 12 0 |
#include <iostream> #include <fstream> #include <iomanip> using namespace std; //============================================================================= // Function prototypes double average_Sales(double [], int); void Standard_comparison(double [], double [], bool [], int); int above_below(bool [], int); void print_Result(int, double, int, int); //============================================================================= // Main function int main() { // Is this the parallel array???? int average; double standard[12]={23.0, 33.1, 21.0, 23.5, 54.0, 34.3, 35.0, 45.0, 56.3, 45.6, 34.0, 55.0}; double sales[12]; bool meet[12]; ifstream fp; int id=0; fp.open("sales.dat"); while(fp>>sales[0]) { // Assign value from 1-7 to each line of data id++; // Enter the values into the array for (int i=1; i<11; i++) { fp>>sales[i]; } // Get the average double average; average = average_Sales(sales, 12); // Compare sales and standard, populate the meet array Standard_comparison(sales, standard, meet, 12); //compute how many months meet the standard int above; above = above_below(meet, 12); //compute how many months are below standard int below = 12-above; //display the department stat in a single line //the performance can be displayed on the fly print_Result(id, average, above, below); } return 0; } //=============================================================================== // Calculates the annual average for a particular department double average_Sales(double sales[], int size) { double sum; for (int i=0; i<12; i++) { sum+=sales[i]; } double average; average = sum/12; return average; // NEW ADDITION } //================================================================================ // Compare sales figures with standard array and store stats in new (bool) array void Standard_comparison(double sales[], double standard[], bool meet[], int size) { for (int i=0; i<12; i++) { if (sales[i]>standard[i]) meet[i]=true; else meet[i]=false; } } //================================================================================== // Determine whether the monthly sales were above or below average int above_below(bool meet[], int size) { int counter =0; for (int i=0; i<12; i++) { if (meet[i]= true) counter ++; if (meet [i]= false) counter++; } return counter; // NEW ADDITION } //=================================================================================== void print_Result(int id, double average, int above, int below) { //cout << setprecision(2) << fixed; cout << "Store Statistics\n"; cout << "Dept " << "Average " << "Above " << "Below " << "Performance" << endl; cout << "=======================================================================\n"; for (int i=0; i<7; i++) { cout << id++ << " " << average << " "; cout << above << " " << below << endl; } } |
|
|
if( meet[i] )
else
to get the alternativecounter++
|
|
double sum=0;
|
|
#include <iostream> #include <fstream> #include <iomanip> using namespace std; //============================================================================= // Function prototypes double average_Sales(double [], int); void Standard_comparison(double [], double [], bool [], int); int above_below(bool [], int); void print_Result(int, double, int, int); //============================================================================= // Main function int main() { // Is this the parallel array???? int average; double standard[12]={23.0, 33.1, 21.0, 23.5, 54.0, 34.3, 35.0, 45.0, 56.3, 45.6, 34.0, 55.0}; double sales[12]; bool meet[12]; ifstream fp; int id=0; fp.open("sales.dat"); while(fp>>sales[0]) { // Assign value from 1-7 to each line of data id++; // Enter the values into the array for (int i=1; i<11; i++) { fp>>sales[i]; } // Get the average double average; average = average_Sales(sales, 12); // Compare sales and standard, populate the meet array Standard_comparison(sales, standard, meet, 12); //compute how many months meet the standard int above; above = above_below(meet, 12); //compute how many months are below standard int below = 12-above; //display the department stat in a single line //the performance can be displayed on the fly print_Result(id, average, above, below); } return 0; } //=============================================================================== // Calculates the annual average for a particular department double average_Sales(double sales[], int size) { double sum=0; for (int i=0; i<12; i++) { sum+=sales[i]; } double average; average = sum/12; return average; // NEW ADDITION } //================================================================================ // Compare sales figures with standard array and store stats in new (bool) array void Standard_comparison(double sales[], double standard[], bool meet[], int size) { for (int i=0; i<12; i++) { if (sales[i]>standard[i]) meet[i]=true; else meet[i]=false; } } //================================================================================== // Determine whether the monthly sales were above or below average int above_below(bool meet[], int size) { int counter =0; for (int i=0; i<12; i++) { if (meet[i]) counter ++; else (meet [i]) counter++; } return counter; // NEW ADDITION } //=================================================================================== void print_Result(int id, double average, int above, int below) { //cout << setprecision(2) << fixed; cout << "Store Statistics\n"; cout << "Dept " << "Average " << "Above " << "Below " << "Performance" << endl; cout << "=======================================================================\n"; for (int i=0; i<7; i++) { cout << id++ << " " << average << " "; cout << above << " " << below << endl; } } |
|
|
|
|
|
|