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

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...
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...
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...
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...
Using C++ Write a program that reads a text from the keyboard until the user presses...
Using C++ Write a program that reads a text from the keyboard until the user presses the “Enter” key. Your program must count the number of uppercase alphabets (A through Z), lowercase alphabets (a through z), digits (0 through 9) and any other characters. The other character count value should NOT include the “Enter” key. Display the count on the screen. You must use the in-built C++ character I/O functions in this program.
Write a program named FinalExamProgram2 that reads numbers from a file (which you will create using...
Write a program named FinalExamProgram2 that reads numbers from a file (which you will create using Notepad) into a one-dimensional array and then analyzes the numbers as described below. Your program must use loops to read the numbers into the array and to analyze the contents of the array. The program’s main function should do the following:  Read eight floating-point numbers from the file named numbers.txt into a onedimensional array, displaying each number on the screen.  Pass the...
c++ language Create a file program that reads an int type Array size 10; the array...
c++ language Create a file program that reads an int type Array size 10; the array has already 10 numbers, but your job is to resize the array, copy old elements of array to the new one and make it user input and add an additional 5 slots in the array, and lastly do binary search based on user input. close the file.
Program Language C++ How do I take lines of string from an input file, and implement...
Program Language C++ How do I take lines of string from an input file, and implement them into a stack using a double linked list? Example input, command.txt, and output file. Ex: Input.txt postfix: BAC-* prefix:+A*B/C-EF postfix:FE-C/B*A+ postfix:AB-C-D/ postfix:AB-CF*-D / E+ Command.txt printList printListBackwards Output.txt List: postfix:BAC-* prefix:+A*B/C-EF postfix:FE-C/B*A+ postfix:AB-C-D/ postfix:AB-CF*-D/E+ Reversed List: postfix:AB-CF*-D/E+ postfix:AB-C-D/ postfix:FE-C/B*A+ prefix:+A*B/C-EF postfix:BAC-*
IN C LANGUAGE This program reads a threshold, a size, and an array of integers. The...
IN C LANGUAGE This program reads a threshold, a size, and an array of integers. The program then calls the foo function. The function will modify the array x of size n by doubling any values in x that are less than the threshold. The function will count how many values were changed and how many were not changed via two reference parameters. The function signature is: void foo(int n, int x[], int threshold, int *pChanged, int *pUnchanged); The function...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT