Question
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
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
{ //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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started