Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need help with this assignment, I will provide a code that I found on here but when ran, it would not open the file I

Need help with this assignment, I will provide a code that I found on here but when ran, it would not open the file I needed it to. In my file explorer it's called "sequence" but when opened in my IDE DevC++ it's named "sequence.txt" so I cant even tell if it works or not, If on windows the sequence doc is just values listed in notepad, first number is how many numbers are in the sequence followed by said amount of numbers. Ex:
2
5
6
assignment details in picuture, PLEASE provide whole code to copy even if you did minor changes. Also There is no comment section and others can't seem to find one either, so is there another way to contact you to help with further details on this code? Since i dont want to leave a thumbs up on a code that I cant get to run, or leave a thumbs down when I pretty sure the fix could be something simple:
meanAndStdDev.cpp--------------------
// Used for input & output functions
#include
// Used for file handling functions
#include
// Include stats.h header file
#include "meanAndStdDev.h"
using namespace std;
// Main function
int main()
{
// Open file for reading date from file
ifstream infile("sequence.txt", ios::in);
// If file can't open
if(!infile)
{
cout "Error: File can't open";
return 0;
}
// Used to store number of values
int n;
// Read the number of values in file
infile >> n;
// Create an array to store values in array
double *arr = new double[n];
// Used to store array index
int i =0;
// Loop to read line by line data till end of file & store in ith index of array
while(infile >> arr[i])
{
// Increase index i by 1
i++;
}
// Call function to compute the mean of data
double avg = mean(arr, n);
// Call function to compute the standard deviation of data
double std = std_dev(arr, n);
// Print the mean
cout "Mean: " avg "
";
// Print the standard deviation
cout "Standard Deviation: " std "
";
delete[] arr;
return 0;
}
meanAndStdDev.h----------------
// Used for mathematical functions
#include
// Function used to compute the mean of data
double mean(double arr[], int n)
{
// Used to store the sum of data
double sum =0;
// Loop for each value in array from index i from 0 to n-1
for(int i =0; i n; i++)
{
// Add ith value with sum
sum += arr[i];
}
// Compute the mean of data
double avg = sum / n;
// Return mean
return avg;
}
// Function used to compute the standard deviation of data
double std_dev(double arr[], int n)
{
// Call function to compute the mean of data
double avg = mean(arr, n);
// Used to store the sum of square of difference
double sumSqr =0;
// Loop for each value in array i from index i from 0 to n-1
for(int i =0; i n; i++)
{
// Compute the sum of square of difference of ith value & mean & add with sumSqr
sumSqr += pow((arr[i]- avg),2);
}
// Compute the standard deviation
double std = sqrt(sumSqr / n);
// Return the standard deviation
return std;
}
image text in transcribed

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_2

Step: 3

blur-text-image_3

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

25 Vba Macros For Data Analysis In Microsoft Excel

Authors: Klemens Nguyen

1st Edition

B0CNSXYMTC, 979-8868455629

Students also viewed these Databases questions