Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <iomanip>
- #include <fstream>
- using namespace std;
- //prototype for the user information function.
- //prototype for the standard deviation function.
- //prototype for function that finds the high value
- //prototype for function that finds the low value
- double findMean(const double list[], int numOfElements);
- double findStdDev(const double list[], int numOfElements);
- double findBiggest(const double list[], int size);
- double findSmallest(const double list[], int size);
- double findMean(double list[], int numOfElements)
- {
- int index=0;
- double sum = 0;
- for (index = 0; index < numOfElements; index++)
- sum = sum + list[index];
- return sum / numOfElements;
- }
- ///==================================================
- double findStdDev(const double list[], int numOfElements){
- //lesse if i can get mean this way instead then
- int indexM=0;
- double sumM = 0;
- for (indexM = 0; indexM < numOfElements; indexM++)
- sumM = sumM + list[indexM];
- double mean = sumM;
- double numerator=0, stdDev=0;
- int index=0;
- for (index=0; index <numOfElements; index++)
- numerator = numerator + pow(list[index] - mean,2);
- stdDev = sqrt(numerator / numOfElements);
- return stdDev;
- } // define the function to calculate standared deviation
- ///==================================================
- double findSmallest(const double list[], int size){ // define the function to determine the smallest value
- // in the array
- double smallest = list[0];
- for (int index =0; index<size; index++){
- if (list[index]<smallest){
- smallest = list[index];
- }
- }
- return smallest;
- }
- ///==================================================
- double findBiggest(const double list[], int size){ // define the function to determine the largest value
- // in the array.
- double biggest = list[0];
- for (int index =0; index<size; index++){
- if (list[index]>biggest){
- biggest = list[index];
- }
- }
- return biggest;
- }
- ///==================================================
- ///==================================================
- int main()
- {
- double numList[100];
- int count=0; //total numbers read
- ifstream inFile;
- inFile.open("lab8input.txt");
- if(!inFile){
- cout <<"\n\nINPUT FILE ERROR!\n\n";
- return 1;
- }
- cout << fixed << showpoint << setprecision(2);
- inFile >> count; //read the number of items
- cout << "************\n"; //loop and
- for(int index=0; index<count; index++){ //fill the array
- inFile >> numList[index];
- }
- //////////////////////////////
- cout << "\nThe mean value is equal to: "<< findMean(numList, count);
- cout << "\nThe standard deviation is equal to: "<< findStdDev(numList, count);
- cout << "\nThe largest value equals: " << findBiggest(numList, count);
- cout << "\nThe smallest value equals: " << findSmallest(numList, count);
- inFile.close();
- return 0;
- }
- ///==================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement