Question

In: Computer Science

How do I create this program? Using C++ language! Write a program that reads data from...

How do I create this program? Using C++ language!

Write a program 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....ALL INES OF THE PROGRAM MUST BE COMMENTED.

Solutions

Expert Solution

readvalues.txt (save this file under D Drive.Then the path of the file pointing to it is D:\\readvalues.txt)

98
93
72
86
99
61
89
77
91
73
79
71
86
74
19

______________________

#include <iostream>
#include <fstream>
#include <iomanip> // std::setprecision
#include <cmath>
using namespace std;

//Declaring global variables
double mean,standard_deviation;

//Function declarations
void calAvg(int grades[],int count);
void standardDeviation(int grades[],int count);

int main()
{
//defines an input stream for the data file  
ifstream dataIn;
  
//Declaring variables
int nos,count=0;
  
//Opening the input file
dataIn.open("D:\\readvalues.txt");
  
while(dataIn>>nos)
{
   count++;
}
  
//Closing the data input stream
dataIn.close();
  
//Create an integer array which is of size based on count value
int grades[count];
  
//Opening the input file
dataIn.open("D:\\readvalues.txt");
  
/* Getting the values from the txt file and
* populate those values into grades[] array
*/
for(int i=0;i<count;i++)
{
   dataIn>>nos;
   grades[i]=nos;
}
dataIn.close();
  
//Calling the function by passing the grades[] array as argument
calAvg(grades,count);
standardDeviation(grades,count);
  
//Setting the precision to Two decimal places
std::cout << std::setprecision(2) << std::fixed;

//displaying the mean and standard deviation
cout<<"Mean is "<<mean<<endl;
cout<<"Standard Deviation is "<<standard_deviation<<endl;
     
return 0;
}
//Function implementation which calculates the average value of grades[] array
void calAvg(int grades[],int count)
{
   //Declaring local variables
   double sum=0.0;
  
   //calculating the sum of grades[] array elements
   for(int i=0;i<count;i++)
   {
       //calculating the sum
       sum+=grades[i];
   }
  
   //calculating the average
   mean=sum/count;
  
}
//This function which claculates the standard deviation
void standardDeviation(int grades[],int count)
{
   int sum=0;
   double variance;
   //This loop Calculating the sum of square of eeach element in the deviation[] array
   for(int i=0;i<count;i++)
   {
   //Calculating the sum of square of eeach element in the deviation[] array  
   sum+=pow(grades[i]-mean,2);
   }
   //calculating the standard deviation of grades[] array
   variance=(double)sum/(count-1);
   standard_deviation=sqrt(variance);
}
  

___________________

output:

____________Thank You


Related Solutions

In C++, write a program that reads data from a text file. Include in this program...
In C++, write a program 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 variables are the actual data points, the mean, the standard deviation, and the number of data entered. All other variables 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... ALL LINES...
How to do in C++ HTML Converter Create a program that reads an HTML file and...
How to do in C++ HTML Converter Create a program that reads an HTML file and converts it to plain text. Console HTML Converter Grocery List * Eggs * Milk * Butter Specifications Your instructor should provide an HTML file named groceries.html that contains these HTML tags: <h1>Grocery List</h1> <ul>     <li>Eggs</li>     <li>Milk</li>     <li>Butter</li> </ul> When the program starts, it should read the contents of the file, remove the HTML tags, remove any spaces to the left of the tags, add...
C++ Language Write a program that reads the numbers.txt file and stores it into an array...
C++ Language Write a program that reads the numbers.txt file and stores it into an array of integers. Use the sample functions in the text and in the notes from chapter 8 to sort the array in ascending order (low to high). You can use either method (bubble or selection sort) to accomplish this. Then store the sorted array into an output file sorted Numbers.txt. There are 100 values both positive and negative integers in this file.
Write a C++ or Java program that reads an input graph data from a user. Then,...
Write a C++ or Java program that reads an input graph data from a user. Then, it should present a path for the travelling salesman problem (TSP). In the assignment, you can assume that the maximum number ofvertices in the input graph is less than or equal to 20. Input format: This is a sample input from a user. 4 12 0 1 2 0 3 7 0 2 5 1 0 2 1 2 8 1 3 3 2...
Using c++, write a program that reads a sequence of characters from the keyboard (one at...
Using c++, write a program that reads a sequence of characters from the keyboard (one at a time) and creates a string including the distinct characters entered and displays the string on the screen. The input terminates once the user enters a white-space character or the user has entered 50 distinct characters. Do not use C-Strings. 2. Use the following function to append character “ch” to the string “s”: s.push_back(ch); 3. Read the input characters one by one, i.e. do...
Using the provided m1_mbox.txt, write a program that reads the data from the file, locates the...
Using the provided m1_mbox.txt, write a program that reads the data from the file, locates the lines containing sender information (those lines begin with 'From:'), and extracts just the email address of the sender of each message. It should then duplicate the set of email addresses for senders, and write the duplicated list to a file called senders.txt, so that each sender appears in the output file only once. In addition, your program should print to the screen the following...
Use C language Write a program that reads in a series of lines of input character...
Use C language Write a program that reads in a series of lines of input character by character (using getchar()). The first line of the input contains an integer which specifies the number of remaining lines of input, each of which contains a floating point number. The integer value on the first line can be read with scanf(), but all of the following lines can only be read with getchar(). Each line after the first contains a single floating point...
write these programs in c++ using getch() function Write a program that reads 20 integers from...
write these programs in c++ using getch() function Write a program that reads 20 integers from a user using a while loop and determines and prints whether each of those integers is an even number. Write a program that uses a while statement to read integers from a user and prints the sum, average, and largest of these numbers. The input should terminate if the user enters -1.
using C++ 24. Using Files—Total and Average Rainfall Write a program that reads in from a...
using C++ 24. Using Files—Total and Average Rainfall Write a program that reads in from a file a starting month name, an ending month name, and then the monthly rainfall for each month during that period. As it does this, it should sum the rainfall amounts and then report the total rainfall and average rainfall for the period. For example, the output might look like this: During the months of March–June the total rainfall was 7.32 inches and the average...
this program is to be done in c language. Using Pointers Create a program pointerTester.c to...
this program is to be done in c language. Using Pointers Create a program pointerTester.c to experiment with pointers. Implement the following steps one by one in your program: YOU NEED TO ANSWER QUESTION Use printf to print your answers at the end(after 12). 1. Declare three integer variables a, b and c. Initialize them to 0, 100 and 225, respectively. 2. Print the value of each variable and its address. 3. Add the following declaration to your code: int...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT