Answered step by step
Verified Expert Solution
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:
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 infilesequencetxt ios::in;
If file can't open
ifinfile
cout "Error: File can't open";
return ;
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 doublen;
Used to store array index
int i ;
Loop to read line by line data till end of file & store in ith index of array
whileinfile arri
Increase index i by
i;
Call function to compute the mean of data
double avg meanarr n;
Call function to compute the standard deviation of data
double std stddevarr n;
Print the mean
cout "Mean: avg
;
Print the standard deviation
cout "Standard Deviation: std
;
delete arr;
return ;
meanAndStdDev.h
Used for mathematical functions
#include
Function used to compute the mean of data
double meandouble arr int n
Used to store the sum of data
double sum ;
Loop for each value in array from index i from to n
forint i ; i n; i
Add ith value with sum
sum arri;
Compute the mean of data
double avg sum n;
Return mean
return avg;
Function used to compute the standard deviation of data
double stddevdouble arr int n
Call function to compute the mean of data
double avg meanarr n;
Used to store the sum of square of difference
double sumSqr ;
Loop for each value in array i from index i from to n
forint i ; i n; i
Compute the sum of square of difference of ith value & mean & add with sumSqr
sumSqr powarri avg;
Compute the standard deviation
double std sqrtsumSqr n;
Return the standard deviation
return std;
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