Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Date due: to Course instructor by by 115gpm Dec 2 Submit New Skills Practiced (L

ID: 3779693 • Letter: D

Question

Date due: to Course instructor by by 115gpm Dec 2 Submit New Skills Practiced (Learning Goals) Problem solving and debugging. Arrays Sorting Use of filestream variables Functional decomposition Functions and parameter passing. INPUT FILE DESCRIPTION and low temperature readings Assume you are given an input file that contains the daily high for several months in Hypothetical City. The file will have the following format. For each month the file will contain, mixture of upper the name of the month (string) the name will be in a random and lower case letters maximum value of the number of temperature reading for the month (int the this number will be the number of days in the month high followed by the low temperature reading (in) for each day sample input for a month: 105 85 jUlY 5 101 89 105 93 100 85 102 81 PROGRAM DESCRIPTION Design a C++ program that will interactively prompt the user for the name of the input file and read it use an input filestream variable to open the file for reading all output should be displayed to the screen display your name, lecture section and assignment read and process the data for each month display the name of the month with the first letter capitalized and the remaining letters in lower case along with a descriptive label display the number of temperature readings given with label e determine and display the highest high and lowest low temperature readings (as the month determine and display the average high and average low temperatures (with 3 digits to the right of the decimal) for the month determine and display the median high and low temperatures (will require sorting the temperatures use bubblesort) median should be displayed as an integer if there are an odd number of data sets median should be displayed with 1 digit to the right of the decimal if there are an even number of data sets. determine and display the standard deviation of the high and low temperatures (with 3 digits to the right of the decimal) for the month http://web.cs.unlv.edu/leelcs135/assign05 cs135fa16.html 11/30/2016

Explanation / Answer

#include<iostream>
#include <fstream>
#include <string>
#include <math.h>
// proto types of functions
using namespace std;
int maximum(int high[],int count);
int minimum(int low[],int count);
float average(int arr[],int length);
float median(int arr[],int length);
float variance(int arr[],int length,float avg);
float st_de(int arr[],int length);
// main function definition
int main(){
   char fname[20];
   cout << "What is the name of the input file ?"<< endl;
   cin >> fname;
   string line;
   ifstream myfile (fname);                   // taking input from user
   string month;
   int count;
   int i=0;
   cout << endl << "Lee Misch   Lec   Sec#10__   Assignment #5"<<endl;
if (myfile.is_open())
{
    while(myfile >> month){                                   // for each month loop takes name and count
      
       int j;
       if(month[0]>=97){
           month[0] = month[0] -32;
           cout << endl << month[0];
       }
       for(j=1;j<month.size();j++){
           if(month[j]<97){
               month[j] = month[j] + 32;
           }
           cout << month[j];
       }
       myfile >> count;
       cout << " Temperature Data: " << count << " Readings Taken" << endl;
       int high[count];
       int low[count];
       for(i=0;i<count;i++){                       // taking temparature data
           myfile >> high[i];
           myfile >> low[i];
       }
       // printing output
       printf("Maximum high: %15d     Minimum low: %15d ",maximum(high,count),minimum(low,count));
       printf("average high: %15.3f     average low: %15.3f ",average(high,count),average(low,count));
       printf("Median high: %15.3f     Median low: %15.3f ",median(high,count),median(low,count));
       printf("std dev of highs: %10.3f     std dev of low:   %10.3f ",st_de(high,count),st_de(low,count));

    }
    myfile.close();
}
}
// this function takes integer array and an integer i.e. length of array.outputs maximum value in that array
int maximum(int high[],int count){
   int i,max = high[0];
   for(i=1;i<count;i++){
       if(max < high[i]){
           max = high[i];
       }
   }
   return max;
}
// this function takes integer array and an integer i.e. length of array. returns minimum value in that array
int minimum(int low[],int count){
   int i,min = low[0];
   for(i=1;i<count;i++){
       if(min > low[i]){
           min = low[i];
       }
   }
   return min;
}
// this function takes integer array and an integer i.e. length of array. returns average value in that array
float average(int arr[],int length){
   int i=0;
   float sum=0;
   for(i=0;i<length;i++){
       sum = sum + arr[i];
   }
   return sum/length;
}
// this function takes integer array and an integer i.e. length of array . returns median of that array
float median(int arr[],int length){
   int i=0,j,temp;
   for(i=0;i<length;i++){
       for(j=0;j<length;j++){
           if(arr[i]>arr[j]){
               temp = arr[i];
               arr[i] = arr[j];
               arr[j] = temp;
           }
       }
   }
   if(length%2!=0){
       return arr[length/2];
   }
   else{
       return (arr[length/2-1]+arr[length/2])/2.0;
   }
}
// this function takes integer array and an integer i.e. length of array. returns standard deviation of that array
float st_de(int arr[],int length){
  
   float avg = average(arr,length);
   float vrnce = variance(arr, length, avg);
   float std = sqrt(vrnce);
}
// this function takes integer array and an integer i.e. length of array and also average value of that array returns variance of that array
float variance(int arr[],int length,float avg){
   int i;
   float vari = 0;
   for(i=0;i<length;i++){
       vari = vari + ((avg - arr[i])*(avg - arr[i]));
   }
   vari = vari /(length - 1);
   return vari;
}
// end of program

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote