Question

Program already solved, but I need to put function documentation headers for each and every function...

Program already solved, but I need to put function documentation headers for each and every function in your program (for the ones you write, and keep the function header I give you for the main() function). Also make sure you keep the file block header at the top of the file, and fill in the information correctly. Secondly this week you must get your indentation correct. All indentation must use 2 spaces, and you should not have embedded tabs in your program files. (I JUST NEED HELP ON GETTING THE RIGHT FORMAT of the program)

#include
#include
#include

using namespace std;

double calculateMean(int n, int x[])
{
    double sum = 0;
    for(int i=0; i {
    sum += x[i];
}
    return sum/n;
}

double calculateStandardDeviation(int n, int x[]) {
        double avg = calculateMean(n, x);

        double sum = 0;
        for(int i=0; i                 sum += pow(x[i] - avg, 2);
        }

        return sqrt(sum/n);
}

/** main
* The main entry point for this program. Execution of this program
* will begin with this main function.
*
* @param argc The command line argument count which is the number of
*     command line arguments provided by user when they started
*     the program.
* @param argv The command line arguments, an array of character
*     arrays.
*
* @returns An int value indicating program exit status. Usually 0
*     is returned to indicate normal exit and a non-zero value
*     is returned to indicate an error condition.
*/
int main(int argc, char** argv)
{
int n = 22;
int x[] = {5, 8, 3, 7, 9, 2, 7, 5, 4, 5, 2, 1, 9, 8, 9, 3, 5, 2, 5, 8, 8, 9};
double xbar;
double std;

// calculate and display mean of values
xbar = calculateMean(n, x);
cout << "The calculated mean is: " << setprecision(8) << xbar << endl;

// calculate and display standard deviation of values
std = calculateStandardDeviation(n, x);
cout << "The calculated standard deviation is: " << setprecision(8) << std << endl;

// return 0 to indicate successful completion
return 0;
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <iostream> // for functions that do input/output operations eg. cout
#include <cmath> //for functions that do mathematical operations eg. sqrt()
#include <iomanip> // for functions that manipulate values eg. setprecision()

using namespace std;


/** calculateMean
* computes average of elements of an array given the array size.
*
* @param x The array of integers for which mean is to be computed.
* @param n The array size
*
* @returns A double value equaling to average of the array elements
*
*/

double calculateMean(int n, int x[])
{
double sum = 0;
for(int i=0; i<n; i++) {
sum += x[i];
}
return sum/n;
}


/** calculateStandardDeviation
* computes standard deviation of elements of an array given the array size.
* First calls calculateMean function to compute the average to be used to compute standard deviation
*
* @param x The array of integers for which mean is to be computed.
* @param n The array size
*
* @returns A double value equaling to standard deviation of the array elements
*
*/
double calculateStandardDeviation(int n, int x[]) {
double avg = calculateMean(n, x);

double sum = 0;
for(int i=0; i<n ; i++){
sum += pow(x[i] - avg, 2);
}

return sqrt(sum/n);
}

/** main
* The main entry point for this program. Execution of this program
* will begin with this main function.
*
* @param argc The command line argument count which is the number of
* command line arguments provided by user when they started
* the program.
* @param argv The command line arguments, an array of character
* arrays.
*
* @returns An int value indicating program exit status. Usually 0
* is returned to indicate normal exit and a non-zero value
* is returned to indicate an error condition.
*/
int main(int argc, char** argv)
{
int n = 22;
int x[] = {5, 8, 3, 7, 9, 2, 7, 5, 4, 5, 2, 1, 9, 8, 9, 3, 5, 2, 5, 8, 8, 9};
double xbar;
double stdev;

// calculate and display mean of values
xbar = calculateMean(n, x);
cout << "The calculated mean is: " << setprecision(8) << xbar << endl;

// calculate and display standard deviation of values
stdev = calculateStandardDeviation(n, x);
cout << "The calculated standard deviation is: " << setprecision(8) << stdev << endl;

// return 0 to indicate successful completion
return 0;
}

OUTPUT

The calculated mean is: 5.6363636 The calculated standard deviation is: 2.6206428

PLEASE PLEASE GIVE A THUMBS UP

COMMENT DOWN FOR ANY QUERY

Add a comment
Know the answer?
Add Answer to:
Program already solved, but I need to put function documentation headers for each and every function...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Question 19 4 pts Using the program below, please complete the program by adding 2 functions...

    Question 19 4 pts Using the program below, please complete the program by adding 2 functions as follow: 1. A function named getAverage that calculates and returns the Average. 2. A function named getMaximum that returns the maximum of the three numbers. Make sure to use the proper data types for all variables and functions. #include <iostream> using namespace std; //function getAverage //function getMaximum int main(int argc, char** argv) { int x, y, z; cout << "Enter three whole numbers:...

  • C++ code for CIS054 Create a program that uses a function to determine the length of...

    C++ code for CIS054 Create a program that uses a function to determine the length of a line by inputting the X,Y coordinates of the line endpoints. Show the result with a precision of four decimal places. The function prototype is to be specified as follows:     double LengthOfLine (double X1, double Y1, double X2, double Y2); // returns length of line by using this code: #include <iostream> #include <iomanip> #include <cmath> using namespace std; int main(int argc, char* argv[])...

  • When I run this code use ./main How to fix it when program reminds segmentation fault...

    When I run this code use ./main How to fix it when program reminds segmentation fault (core dumped)? #include <iostream> void set_num(int* i_prt, int num) { *i_prt = num; } int main(int argc, char** argv) { int x; set_num(&x, 13); std::cout << "x: " << x << std::endl; int* y; set_num(y, 4); std::cout << "*y:" << *y << std::endl; }

  • 1. In ANSII standard C++, there is no library function to convert an integer to a...

    1. In ANSII standard C++, there is no library function to convert an integer to a string. Your program should develop such a function. In other words complete the following program using your itos function. (Use of other C functions is prohibitted) // this program will read in an integer and convert it to a string #include <iostream> #include <cstdlib> #include <string> using namespace std; string itos(int n) { } int main(int argc, char* argv[]){ int n = atoi(argv[1]); cout...

  • You are given a Q1.h file with overloaded function prototypes for isOrdered. Implement this overloaded function...

    You are given a Q1.h file with overloaded function prototypes for isOrdered. Implement this overloaded function into a file named Q1.cpp. Q1.cpp should only include your function implementation, the necessary #include directives if needed, and should not contain anything else such as the main function or global variable declarations. Test your code using a separate main.cpp file where you implement a sufficient number of test cases. You should use Q1.h as a header file and Q1main.cpp as a main function...

  • Help with C++ reverse program with leading zeros. I need to put the line from the...

    Help with C++ reverse program with leading zeros. I need to put the line from the function that display the zeros in main not in the function. So how can I move the display with leading zeros in main. Thanks. Here is my code. #include <iostream> #include <cstdlib> #include <iostream> using std::cout; using std::cin; using std::endl; //function templates int reverseNum(int); int main() { //variables char buf[100]; int num; while (true) { //prompt user for input cout << "Enter the number...

  • what is the output for the following code? explain the steps. /*#include <iostream> using namespace std;...

    what is the output for the following code? explain the steps. /*#include <iostream> using namespace std; int f(int &i) { i = 10; return(5 * i); } int main() { int n = 5; f(n); cout << n << "\n"; return 0; } #include <iostream> using namespace std; int sub1(int n) { n--; return n; } int main() { int m = 10; for(int j = 0; j < 10; j++) m -= sub1(j); cout << m << "\n"; return...

  • How do can I update this code (Code A): Code (A) #include using namespace std; int fibonacci(int n) { int a = 0,...

    How do can I update this code (Code A): Code (A) #include using namespace std; int fibonacci(int n) { int a = 0, b = 1, c; if (n <= 1) return n; for (int i = 2; i <= n; i++) { c = a + b; a = b; b = c; } return b; } int fibonacciRecursive(int n) { if (n <= 1) { return n; } return fibonacciRecursive(n-1) + fibonacciRecursive(n-2); } int main() { int n;...

  • Hello, I have written a code that I now need to make changes so that arrays...

    Hello, I have written a code that I now need to make changes so that arrays are transferred to the functions as pointer variable. Below is my code I already have. #include<iostream> #include<string> #include<iomanip> using namespace std; //functions prototypes void getData(string id[], int correct[], int NUM_STUDENT); void calculate(int correct[], int incorrect[], int score[], int NUM_STUDENT); double average(int score[], int NUM_STUDENT); void Display(string id[], int correct[], int incorrect[], int score[], double average, int NUM_STUDENT); int findHigh(string id[], int score[], int NUM_STUDENT);...

  • Need help with a C++ program. I have been getting the error "this function or variable...

    Need help with a C++ program. I have been getting the error "this function or variable may be unsafe" as well as one that says I must "return a value" any help we be greatly appreciated. I have been working on this project for about 2 hours. #include <iostream> #include <string> using namespace std; int average(int a[]) {    // average function , declaring variable    int i;    char str[40];    float avg = 0;    // iterating in...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT