Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question 1 has already been posted to Chegg and I am waiting for the answer on this issue - (When the below program is added

Question 1 has already been posted to Chegg and I am waiting for the answer on this issue - (When the below program is added to a Dev C++ complier, there are no errors shown; however, when the program is run, the answer appears as zero instead of the correct value. What am I doing wrong?)

Question 2 is another using the same program. Please answer this question for this posting. My teach wants us to write a probram that reads data from a text file. Include in this program functions that calculate the mean and the standard deviation. Make sure that the only global varibles are the mean, standard deviation, and the number of data entered. All other varibles must be local to the function. At the top of the program make sure you use functional prototypes instead of writing each function before the main function. My problem is that it seems that the mean, standard deviation and the number of data are already global and there seems to not be any other program functions to make local. What am I not doing correctly or understanding.

include//Basically a code file where all input (keyboard) and output (monitor) functions are defined. #include//Basically a code whereas information is able to be read from a file #include//Arrays are a programming tool that provide a mechanism to store a group of values under a single name. The values can be any available data type (e.g., int, double, string, etc.). In C++, the term vectors are used, rather than arrays. #include//declares a set of functions to compute common mathematical operations and transformations using namespace std;//By using namespaces, you can create your own classes and functions with the same names that the standard library provides and place them in differently named namespaces.

int main()//The main function is a driver function because it tells the other functions in the program the sequence of actions that need to be executed. {//states that the main program begins here vector v;//declares a vector of integers when the number of vectors is unknown (v). Permits the program to run without knowing the exact number of integers. ifstream inputFile; // Ifstream handles file input (reading from files) ofstream outputFile;//ofstream handles file output (writing to files) outputFile.open ("output.txt"); //opens the output file int n;//A generic substitute identification for the integers since the integers listed in the array file are unknown until the integers are read. All the numbers in the array will be read in sequence int total = 0;//Within the array file, the program to calculate the total is to retrieve the integer from the primary position or the zero position int standardDeviation = 0;// within the array file, the program to calculate standard deviation is to retrieve the integer from the primary position or the zero position if (inputFile.is_open()) //checking whether the input file can be opened or not

{ //states the function to get the data from the array file and be used in the calculations begins here while (!inputFile.eof()) //loop to get each value from the input file until the End of File. { //states the function to retrieve each integers begins here inputFile >> n; // reading each value into variable n total = total + n; //caalculating the sum of all the numbers in the file v.push_back(n); //adding each value from file to vector. }//states the function to retrieve each integer ends here double mean = total/ (double)v.size(); //provides the formula to calculate the mean which is the total of all the array numbers added together divided by (the variance times itself) for(int i=0; i

{//states the function to calculate the variance from the mean using the integers with the array data begins here standardDeviation += pow(v[i] - mean, 2); //produces the vector value which is (array number for all the loops - the mean) ( times itself)] }//states the function to calculate the variance from the mean using the integers within the array data ends here standardDeviation = sqrt(standardDeviation / (double)v.size());// tells the function the std dev is the [(vector value * itself) / (the number of integers in the array)], afterward the square root of the total result is calculated cout<<"Mean: "<

}//states the function to get the data from the array file and be used in the calculations ends here outputFile.close();//closing output file inputFile.close();//closing input file return 0;// indicates the end of all programming }//states that the main program ends here

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

MySQL Crash Course A Hands On Introduction To Database Development

Authors: Rick Silva

1st Edition

1718503008, 978-1718503007

More Books

Students also viewed these Databases questions