Question

Hi im having trouble with this homework question. Can someone show me how to do this in C++ with all the steps?
Weather Analysis WeatherAnalyzer - New Day Data 2- Good Days 3- Summary 0- Exit Step 0: You can get the sample file from this

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

Here is the code :

---------------------------------------------------------------------------------------------------------

#include <iostream>

#include <vector>

#include <fstream>

using namespace std;

//weather class

class weather{

  public:

  float temp;

  float humidity;

  float wind;

};

void addNewData(vector<weather> &V, const weather x); //function prototype for adding new data

void goodDays(const vector<weather> &V, float min, float max); //prototype for good days

void summary(const vector<weather> &V); //prototype for summary


int main(){

  ifstream input; //input file stream

  input.open("weather.txt");

  vector<weather> V;//dynamic array of weather objects

  weather x;//temporary weather object

  while(input >> x.temp){

      input >> x.humidity >> x.wind;

      V.push_back(x);

  }

  //interactive IO

  start:

  cout << "\nWeather Analysis\n===================" << endl;   

  cout << "1 - New Day Data" << endl;

  cout << "2 - Good Days" << endl;

  cout << "3 - Summary" << endl;

  cout << "0 - Exit" << endl;

  cout << "? ";

  int choice;

  cin >> choice;

  if(choice == 1){

      weather x;

      cout << "Temp: ";

      cin >> x.temp;

      cout << "Humidity: ";

      cin >> x.humidity;

      cout << "Wind: ";

      cin >> x.wind;

      addNewData(V, x);

      goto start;

  }

  else if(choice == 2){

      float min, max;

      cout << "Min. Desired Temp: ";

      cin >> min;

      cout << "Max. Desired Temp: ";

      cin >> max;

      goodDays(V, min, max);

      goto start;

  }

  else if(choice == 3){

      summary(V);

      goto start;

  }

  else{

      return 0;

  }

}

//function definitions

void addNewData(vector<weather> &V, const weather x){

  V.push_back(x); //add new data to array

  //add data to weather.txt

  ofstream output;

  output.open("weather.txt");

  for(int i = 0; i < V.size(); ++i){

      output << V[i].temp << " " << V[i].humidity << " " << V[i].wind << endl;

  }

}

void goodDays(const vector<weather> &V, float min, float max){

  int num = 0; //count to number of good days

  float avgtemp = 0; // average temperature

  for(int i = 0; i < V.size(); ++i){

      if(V[i].temp >= min && V[i].temp <= max && V[i].humidity > 40 && V[i].humidity < 70 && V[i].wind < 12){

          num++;

          avgtemp+=V[i].temp;

      }

  }

  avgtemp/=num;

  cout << "There were " << num << " good days w/ avg. temp " << avgtemp << "." << endl;

}

void summary(const vector<weather> &V){

  cout << "Dataset contains " << V.size() << " days of data." << endl;

  cout << "Lowest: " << endl;

  //finding minimum

  float x = 1000, y = 1000, z = 1000;

  for(int i = 0; i < V.size(); ++i){

      x = min(x, V[i].temp);

      y = min(y, V[i].humidity);

      z = min(z, V[i].wind);

  }

  cout << "Temp.: "<< x << "F" << endl;

  cout << "Humidity: "<< y << "%" << endl;

  cout << "wind: "<< z << "MPH" << endl;

  cout << "Highest: " << endl;

  //finding maximum

  x = -1000;

  y = -1000;

  z = -1000;

  for(int i = 0; i < V.size(); ++i){

      x = max(x, V[i].temp);

      y = max(y, V[i].humidity);

      z = max(z, V[i].wind);

  }

  cout << "Temp.: "<< x << "F" << endl;

  cout << "Humidity: "<< y << "%" << endl;

  cout << "wind: "<< z << "MPH" << endl;

}


-------------------------------------------------------------------------------------------------------

IO

[unseen@pc ]08:29 AM_$ N/prog/CPP > ./test1 Weather Analysis 1- New Day Data 2- Good Days 3Summary 0 - Exit Temp: 70 Humidity

Weather Analysis 1- New Day Data 2 Good Days 3-Summary 0- Exit Dataset contains 61 days of data. Lowest Temp. 60F Humidity: 4

Add a comment
Know the answer?
Add Answer to:
Hi im having trouble with this homework question. Can someone show me how to do this in C++ with all the steps? Weather Analysis WeatherAnalyzer - New Day Data 2- Good Days 3- Summary 0- Exit Step 0:...
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
  • In this assignment you will be implementing a weather forecaster. It involves writing 3 different classes...

    In this assignment you will be implementing a weather forecaster. It involves writing 3 different classes plus a driver program. It is recommended that you write one class at a time and then write a driver (tester) program to ensure that it works before putting everything together. Alternately, you can use the Interactions tab of JGRASP to test some of the early classes. This is discussed in the next few pages. The Season Class The first, shortest, and easiest class...

  • Hello! I have this python Homework due tonight that I don't know how to do. Here...

    Hello! I have this python Homework due tonight that I don't know how to do. Here is a document with the data in the csv file, as I didn't know how to share it https://docs.google.com/document/d/1bDJVR2MqWKInvw5u0r3fOG3-CBmu3BEiPZwlaq_CShQ/edit?usp=sharing Activity #3: On the class website is a CSV file containing weather data from Coulter Field (in Bryan) for 3 years (1 day is missing for some reason!); the data was taken from Weather Underground (wunderground.com). There are different versions of the file for Windows...

  • HI, I am having trouble finsihing this program i was wondering if someone could help me....

    HI, I am having trouble finsihing this program i was wondering if someone could help me. Thanks in adavnce. Here is the code that I have so far..... //Stack.h // implementation file for the stack class #include <iostream> using namespace std; const int stack_size = 100; class stack { private: char data [stack_size]; // elements in the stack int top; // index of the top element of the stack public: stack (); // constructor creates an empty stack void push...

  • Hi can you help me make a summary about this short article and how it affects...

    Hi can you help me make a summary about this short article and how it affects me economically as US citizen ? Supported by Federal Shutdown’s Uneven Toll: Some Americans Are Devastated, Others ObliviousFederal Shutdown’s Uneven Toll: Some Americans Are Devastated, Others Oblivious “It has been terrible,” said Andrea Caviedes, a furloughed loan processor in the Agriculture Department’s rural development program.CreditMichael B. Thomas for The New York Times Image “It has been terrible,” said Andrea Caviedes, a furloughed loan processor...

  • How can we assess whether a project is a success or a failure? This case presents...

    How can we assess whether a project is a success or a failure? This case presents two phases of a large business transformation project involving the implementation of an ERP system with the aim of creating an integrated company. The case illustrates some of the challenges associated with integration. It also presents the obstacles facing companies that undertake projects involving large information technology projects. Bombardier and Its Environment Joseph-Armand Bombardier was 15 years old when he built his first snowmobile...

  • 10. Write a one-page summary of the attached paper? INTRODUCTION Many problems can develop in activated...

    10. Write a one-page summary of the attached paper? INTRODUCTION Many problems can develop in activated sludge operation that adversely affect effluent quality with origins in the engineering, hydraulic and microbiological components of the process. The real "heart" of the activated sludge system is the development and maintenance of a mixed microbial culture (activated sludge) that treats wastewater and which can be managed. One definition of a wastewater treatment plant operator is a "bug farmer", one who controls the aeration...

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