Question

A A Ap Aa Consolas 14 AaBbCcDd AaBbCcDd AaBbCc Editing ste 1 No Spac.. Heading 1 В I 1 Normal x A U A v ab х. Dictate ipboard

I need this asap. C++ please

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Note: Could you plz go through this code and let me know if u need any changes in this.Thank You
_________________

We have to store the input file in bin folder C:\Program Files (x86)\Dev-Cpp\MinGW64\bin As I installed Dev C++ in C Drive

________________________

// weather.txt

70 53
74 56
78 60
84 68
88 73
91 76
93 76
93 77
90 74
85 67
78 60
71 53

________________________

#include <fstream>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <cstdlib>
using namespace std;

const int NO_OF_MONTHS=12;
void getData(int twoDim[][2],int rows);
int averageHigh(int twoDim[][2],int rows);
int averageLow(int twoDim[][2],int rows);
int indexHighTemp(int twoDim[][2],int rows);
int indexLowTemp(int twoDim[][2],int rows);
void display(int twoDim[][2],int rows);

ifstream inFile("weather.txt");
ofstream outFile("weather.out");
int main() {
int hilowArray[NO_OF_MONTHS][2];
int indexHigh;
int indexLow;
getData(hilowArray,NO_OF_MONTHS);
display(hilowArray,NO_OF_MONTHS);
cout<<"\nAverage high temperature:"<<averageHigh(hilowArray,NO_OF_MONTHS)<<endl;
outFile<<"\nAverage high temperature:"<<averageHigh(hilowArray,NO_OF_MONTHS)<<endl;
  
cout<<"\nAverage low temperature:"<<averageLow(hilowArray,NO_OF_MONTHS)<<endl;
outFile<<"\nAverage low temperature:"<<averageLow(hilowArray,NO_OF_MONTHS)<<endl;
  
indexHigh=indexHighTemp(hilowArray,NO_OF_MONTHS);
cout<<"\nHighest Temperature: "<<hilowArray[indexHigh][0]<<endl;
outFile<<"\nHighest Temperature: "<<hilowArray[indexHigh][0]<<endl;
  
indexLow=indexLowTemp(hilowArray,NO_OF_MONTHS);
cout<<"\nLowest Temperature: "<<hilowArray[indexLow][1]<<endl;
outFile<<"\nLowest Temperature: "<<hilowArray[indexLow][1]<<endl;
  
outFile.close();

   return 0;
}
void getData(int twoDim[][2],int rows)
{
   for(int i=0;i<rows;i++)
   {
       for(int j=0;j<2;j++)
       {
           inFile>>twoDim[i][j];
       }
   }
   inFile.close();
}
int averageHigh(int twoDim[][2],int rows)
{
   int sum=0,avg;
   for(int i=0;i<rows;i++)
   {
       sum+=twoDim[i][0];
   }
   avg=sum/rows;
   return avg;
}
int averageLow(int twoDim[][2],int rows)
{
   int sum=0,avg;
   for(int i=0;i<rows;i++)
   {
       sum+=twoDim[i][1];
   }
   avg=sum/rows;
   return avg;  
}
int indexHighTemp(int twoDim[][2],int rows)
{
   int max=twoDim[0][0],indx=0;
  
   for(int i=0;i<rows;i++)
   {
       if(max<twoDim[i][0])
       {
           max=twoDim[i][0];
           indx=i;
       }
   }
   return indx;
}
int indexLowTemp(int twoDim[][2],int rows)
{
       int min=twoDim[0][1],indx=0;
  
   for(int i=0;i<rows;i++)
   {
       if(min>twoDim[i][1])
       {
           min=twoDim[i][1];
          
           indx=i;
       }
   }
   return indx;
}
void display(int twoDim[][2],int rows)
{
   string months[] = { "January", "February", "March", "April", "May", "June", "July",
"August", "September", "October", "November", "December" };
  
cout<<"The following is the Brownsville's yearlong high and low temperatures"<<endl;
cout<<setw(10)<<left<<"Month\t\tHigh\tLow"<<endl;
for(int i=0;i<rows;i++)
{
   cout<<setw(10)<<left<<months[i]<<"\t";
   for(int j=0;j<2;j++)
   {
       cout<<twoDim[i][j]<<"\t";
           }
           cout<<endl;
       }
}

___________________________

Output:

C:\Program Files (x86)\Dev-Cpp\MinGW64\bin\ReadFileWriteFileWeatherHighLowArray.exe The following is the Brownsvilles yearlo

_____________________

weather.out (Outputfile)

weather - Notepad File Edit Format View Help Average high temperature: 82 Average low temperature: 66 Highest Temperature: 93


_______________Could you plz rate me well.Thank You

Add a comment
Know the answer?
Add Answer to:
I need this asap. C++ please A A Ap Aa Consolas 14 AaBbCcDd AaBbCcDd AaBbCc Editing...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a program that uses a two-dimensional array to store the highest and lowest temperatures for each month of the year. The program should output the average high, average low, and the highest and...

    Write a program that uses a two-dimensional array to store the highest and lowest temperatures for each month of the year. The program should output the average high, average low, and the highest and lowest temperatures for the year. Your program must consist of the following functions 1. Function getData: This function reads and stores data in the two- dimensional array. 2. Function averageHigh: This function calculates and returns the aver- age high temperature for the year. 3. Function averageLow:...

  • Write a program that uses a two-dimensional array to store the highest and lowest temperatures for...

    Write a program that uses a two-dimensional array to store the highest and lowest temperatures for each month of the year. You should also have a parallel array to store the names of the 12 months. The program should read the Month's names, and the temperatures from a given input file called temperature.txt. The program should output the highest and lowest temperatures for the year, and the months that correspond to those temperatures. The program must use the following functions:...

  • C++: modify the following code so the names of the month are listed to the left...

    C++: modify the following code so the names of the month are listed to the left of the high and low temperature readings and label the two columns of numbers as high (the one on the left) and low (the one on the right). Numbers are already in order so all that is needed is the months' names in order from top (jan.) to bottom (dec.) code: #include <iostream> #include <fstream> #include <iomanip> using namespace std; const int NO_OF_MONTHS =...

  • The following is a program from Starting out with C++ by Toni Gaddis. I am getting the following error messages pertain...

    The following is a program from Starting out with C++ by Toni Gaddis. I am getting the following error messages pertaining to the lines: cin>>month[i].lowTemp; and months[i].avgTemp = (months[i].highTemp + month[i].lowTemp)/2; The error messages read as follows: error C2039: 'lowTemp': is not a member of 'std::basic_string<_Elem,_Traits,_Ax>' and it continues. The second error message is identical. The program is as follows: Ch. 11, Assignment #3. pg. 646. Program #4. //Weather Statistics. //Write a program that uses a structure to store the...

  • Write a C++ program that demonstrates use of programmer-defined data structures (structs), an array of structs, passing...

    Write a C++ program that demonstrates use of programmer-defined data structures (structs), an array of structs, passing an array of structs to a function, and returning a struct as the value of a function. A function in the program should read several rows of data from a text file. (The data file should accompany this assignment.) Each row of the file contains a month name, a high temperature, and a low temperature. The main program should call another function which...

  • Write a program that demonstrates use of programmer - defined data structures. Please provide code! Thank...

    Write a program that demonstrates use of programmer - defined data structures. Please provide code! Thank you. Here are the temps given: January 47 36 February 51 37 March 57 39 April 62 43 May 69 48 June 73 52 July 81 56 August 83 57 September 81 52 October 64 46 November 52 41 December 45 35 Janual line Iranin Note: This program is similar to another recently assigned program, except that it uses struct and an array of...

  • Need help with a C++ program. I have been getting the error "this function or variable...

    Need help with a C++ program. I have been getting the error "this function or variable may be unsafe" as well as one that says I must "return a value" any help we be greatly appreciated. I have been working on this project for about 2 hours. #include <iostream> #include <string> using namespace std; int average(int a[]) {    // average function , declaring variable    int i;    char str[40];    float avg = 0;    // iterating in...

  • can someone help me fix this. The function that finds the minimum and maximum values of...

    can someone help me fix this. The function that finds the minimum and maximum values of the array and outputs the value and index doesnt find the maximum value of the array. #include <iostream> #include <fstream> #include<iomanip> using namespace std; void readArray(ifstream& inF, int arr[], int&ArrSize); void writeArray(ofstream & outF, int arr[], int & ArrSize); void MaxAndMin(ofstream & outF, int arr[], int & ArrSize, int &high, int &low); int main() {    int arr[100];    int i = 0;   ...

  • ********** PLEASE PROVIDE IN JAVA & NEW SET OF ALGORITHM For this lab use the program...

    ********** PLEASE PROVIDE IN JAVA & NEW SET OF ALGORITHM For this lab use the program at the bottom to sort an array using selection sort. Write a selection sort to report out the sorted low values: lowest to highest. Write another to report out the sorted high values – highest to lowest. Last but not least, the program should output all the values in the array AND then output the 2 requested sorted outputs. -----> MY OLD PROGRAM BELOW...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT