Question

Hi. Could you help me write the below program? Please don't use any header other than...

Hi. Could you help me write the below program? Please don't use any header other than iostream, no Chegg class, no argc/argv. Nothing too advanced. Thank you!

For this assignment you are implement a program that can be used to compute the variance and standard deviation of a set of values. In addition your solution should use the functions specified below that you must also implement. These functions should be used wherever appropriate in your solution. With the exception of main(), you may not use any additional functions, unless they are functions that you also implement.

Functions: void GetData(double list[], int& count); This function is responsible for prompting for and reading data from the user. The function should be begin by asking the user how many values are to be processed. Once this value has been input, the program should then prompt for and read that number of values, placing these values in the first parameter. There should be one prompt for each of the values that are to be input. The second parameter is used to convey back to the calling function the number of values that were input.

double Variance(double list[], int count); This function returns the variance that computed from the values contained in the array specified by the first parameter. The second parameter specifies to the function the number of values contained in the first parameter array.

double StandardDev(double list[], int count); This function returns the standard deviation computed from the values contained in the array specified by the first parameter. The second parameter specifies the number of values contained in the first parameter array.

void Sort(double list[], int count); This function sorts in ascending order the values contained in the first parameter. The second parameter specifies the number of values contained in the first parameter array.

double SqRoot(double value); This function returns the square root of the value specified by the first parameter.

The square root of a number N can be approximated with an iterative process using the expression

new_value = 0.5(old_value + N / old_value)


Each time the loop executes the value of old_value that is used should be gotten from the value of new_value that was obtained during the previous execution of the loop.To begin the iteration you should start off with some initial (seed) value. For example, the value 1 could be used. Iterating through the above expression will cause new_value and old_value to converge to the square root of N.

Because of the way decimal floating point values are typically represented in a computer you may find that new_value and old_value do not always reach the same value. For this reason you should terminate the iteration when (the absolute value of) their difference is less than a predetermined value, which for this assignment should be 0.005.


Using the above functions, you are to implement an application that reads a sequence of up to 100 values from a user. After the values have been input, the program should output the values, one per line, in ascending sorted order, followed by their variance and standard deviation.

For this assignment, you may only use the functions specified above, or other functions that you may choose to implement. You may not use any of the functions available in C++. Also, iostream is the only header file that you can use.

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

Code:

#include <iostream>

using namespace std;

void GetData(double list[], int& count);

double Variance(double list[], int count);

double StandardDev(double list[], int count);

void Sort(double list[], int count);

double SqRoot(double value);

int main(){

double list[100];

int n;

GetData(list, n);

Sort(list, n);

cout << "\nSorted values are:" << endl;

for(int i = 0; i < n; i++)

    cout << list[i] << " ";

cout << "\n\nVariance = " << Variance(list, n) << endl;

cout << "\nStandard Deviation = " << StandardDev(list, n) << endl;

}

void GetData(double list[], int& count){

cout << "Enter sample size: ";

cin >> count;

cout << "Enter the numbers:\n";

for(int i = 0; i < count; i++){

    cin >> list[i];

}

}

double Variance(double list[], int count){

double mean = 0;

for(int i = 0; i < count; i++)

    mean += list[i];

mean /= count;

double var = 0;

for(int i = 0; i < count; i++)

    var += (list[i] - mean) * (list[i] - mean);

var /= count;

return var;

}

double StandardDev(double list[], int count){

double std;

std = SqRoot(Variance(list, count));

return std;

}

void Sort(double list[], int count){

for(int i = 0; i < count - 1; i++){

    for(int j = 0; j < count - i - 1; j++){

      if(list[j] > list[j+1]){

        double temp = list[j];

        list[j] = list[j+1];

        list[j+1] = temp;

      }

    }

}

}

double SqRoot(double value){

double old_value = value;

double new_value = 1;

double e = 0.0000001;

while(old_value - new_value > e){

    old_value = 0.5*(old_value + new_value);

    new_value = value / old_value;

}

return new_value;

}

Output:


Add a comment
Know the answer?
Add Answer to:
Hi. Could you help me write the below program? Please don't use any header other than...
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
  • Write a program that dynamically allocates an array in the freestore large enough to hold a...

    Write a program that dynamically allocates an array in the freestore large enough to hold a user defined number of test scores as doubles. Once all the scores are entered, the array should be passed to a function that finds the highest score. Another function the array should be passed to a function that finds the lowest score. Another function should be called that calculates the average score. The program should show the highest, lowest and average scores. Must use...

  • Write a program that dynamically allocates an array in the freestore large enough to hold a...

    Write a program that dynamically allocates an array in the freestore large enough to hold a user defined number of test scores as doubles. Once all the scores are entered, the array should be passed to a function that finds the highest score. Another function the array should be passed to a function that finds the lowest score. Another function should be called that calculates the average score. The program should show the highest, lowest and average scores. Must use...

  • PLEASE HELP ME WITH THIS TASK 3.1 (FLOWCHART) AND TASK 3.2 (SOURCE PROGRAM). THANK YOU! Hint:...

    PLEASE HELP ME WITH THIS TASK 3.1 (FLOWCHART) AND TASK 3.2 (SOURCE PROGRAM). THANK YOU! Hint: the number array in task 2 is work for task 3 in figure 1.   Given below is a partially completed C program, which you will use as a start to complete the given tasks. #define SIZE 9 #include <stdio.h> int compareAndCount (int[], int[]); double averageDifference (int[], int[]); void main() { } int compareAndCount(int arr1[SIZE], int arr2[SIZE]) { int count = 0; for (int i...

  • Program in C++! Thank you in advance! Write a menu based program implementing the following functions: (1) Write a funct...

    Program in C++! Thank you in advance! Write a menu based program implementing the following functions: (1) Write a function that prompts the user for the name of a file to output as a text file that will hold a two dimensional array of the long double data type. Have the user specify the number of rows and the number of columns for the two dimensional array. Have the user enter the values for each row and column element in...

  • Write a program in C++ that simulates a soft drink machine. The program will need several...

    Write a program in C++ that simulates a soft drink machine. The program will need several classes: DrinkItem, DrinkMachine and Receipt. For each of the classes you must create the constructors and member functions required below. You can, optionally, add additional private member functions that can be used for doing implementation work within the class. DrinkItem class The DrinkItem class will contains the following private data members: name: Drink name (type of drink – read in from a file). Type...

  • I need a c++ code please. 32. Program. Write a program that creates an integer constant...

    I need a c++ code please. 32. Program. Write a program that creates an integer constant called SIZE and initialize to the size of the array you will be creating. Use this constant throughout your functions you will implement for the next parts and your main program. Also, in your main program create an integer array called numbers and initialize it with the following values (Please see demo program below): 68, 100, 43, 58, 76, 72, 46, 55, 92, 94,...

  • For this c++ assignment, Overview write a program that will process two sets of numeric information....

    For this c++ assignment, Overview write a program that will process two sets of numeric information. The information will be needed for later processing, so it will be stored in two arrays that will be displayed, sorted, and displayed (again). One set of numeric information will be read from a file while the other will be randomly generated. The arrays that will be used in the assignment should be declared to hold a maximum of 50 double or float elements....

  • c++, we have to write functions for the code given below and other instructions for it...

    c++, we have to write functions for the code given below and other instructions for it to compile. I am having issues understanding how to confront the problem and how to write functions and read the program so it can eventually be solved so it can be compiled 7/ * INSTRUCTIONS: Write two functions in the space // * indicated below. // * // * #1 => Find index of maximum value: Write a function that will // * find...

  • I NEED HELP WITH THIS 2 PROBLEMS PLEASE! THANK YOU SO MUCH Given below is a...

    I NEED HELP WITH THIS 2 PROBLEMS PLEASE! THANK YOU SO MUCH Given below is a partially completed C program, which you will use as a start to complete the given tasks. #define SIZE 9 #include <stdio.h> int compareAndCount (int[], int[]); double averageDifference (int[], int[]); void main() { } int compareAndCount(int arr1[SIZE], int arr2[SIZE]) { int count = @; for (int i = 0; i < SIZE; i++) { if (arr1[1] > arr2[i]) count++; return count; } Task 1: (10...

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