Please help me! Please do this as fast as possible. All code in C++ Edit the Wea
ID: 3718665 • Letter: P
Question
Please help me!
Please do this as fast as possible.
All code in C++
Edit the Weather Class below to work correctly. There are two conditions, temperature and humidity. There should be a random number generated for humidity between 0 and 100. There should be a random number generated between -50 and 120 for temperature. There has to be a test function, where we test what happens after each test. Depending of the values for temperature and humidity, the class should display, the current weather(chilly, foggy, raining, sunny, overcast, ect.)
The following is the Weather class so far:
class Weather
{
public:
double getWeather()
{
double humid = humidity:weather();
double temp = temperature:weather();
if(temp = 80 && humid = 40)
{
return 0; //Sunny
}
else if (temp = 58 && humid = 60)
{
return 1; //Foggy
}
else if(temp = 60 && humid = 60)
{
return 2; //Overcast
}
else if(temp = 20 && humid = 30)
{
return 3; //Snowing
}
else if(temp = 60 && humid = 75)
{
return 4; //Raining
}
else if (temp = 60 && humid = 100)
{
return 5; //Night time
}
else if (temp = 59 && humid = 40)
{
return 6; //Cool Weather
}
else if (temp = 85 && humid = 40)
{
return 7; //Warm Weather
}
else if (temp = 95 && humid = 50)
{
return 8; //Hot Weather
}
else if (temp = 77 && humid = 45)
{
return 9; //Medium Weather
}
else if (temp = 80 && humid = 20)
{
return 10; //Dry Weather
}
else if (temp = 86 && humid = 90)
{
return 11; //Wet Weather
}
else if (temp = 65 && humid = 99)
{
return 12; //Foggy
}
};
Explanation / Answer
#include <iostream>
#include <random>
#include<time.h>
#include <string>
using namespace std;
class Weather
{
public:
// This function will return a string
// representing weather a/c to the generated
// humid and temperature
string getWeather()
{
// Generate random number between 2 numbers using this
// rand()%(max-min+1)+min
double humid =rand()%(101);
double temp = rand()%(120+50+1)-50;
// Print humid and temp just to test, what values are being generated
// Return weather - chilly, foggy, raining, sunny, overcast, etc.
cout<<"Humid: "<<humid<<" Temp: "<<temp;
if(temp == 80 && humid == 40)
{
return "Sunny"; //Sunny
}
else if (temp == 58 && humid == 60)
{
return "Foggy"; //Foggy
}
else if(temp == 60 && humid == 60)
{
return "Overcast"; //Overcast
}
else if(temp == 20 && humid == 30)
{
return "Snowing"; //Snowing
}
else if(temp == 60 && humid == 75)
{
return "Raining"; //Raining
}
else if (temp == 60 && humid == 100)
{
return "Night time"; //Night time
}
else if (temp == 59 && humid == 40)
{
return "Cool Weather"; //Cool Weather
}
else if (temp == 85 && humid == 40)
{
return "Warm Weather"; //Warm Weather
}
else if (temp == 95 && humid == 50)
{
return "Hot Weather"; //Hot Weather
}
else if (temp == 77 && humid == 45)
{
return "Medium Weather"; //Medium Weather
}
else if (temp == 80 && humid == 20)
{
return "Dry Weather"; //Dry Weather
}
else if (temp == 86 && humid == 90)
{
return "Wet Weather"; //Wet Weather
}
else if (temp == 65 && humid == 99)
{
return "Foggy"; //Foggy
}else{
return "Unknown";
}
}
};
int main ()
{
srand(time(NULL)); // Seed the time
// Test weather class
Weather w1;
string res = w1.getWeather();
cout<<" Weather: "<<res<<endl;
res = w1.getWeather();
cout<<" Weather: "<<res<<endl;
res = w1.getWeather();
cout<<" Weather: "<<res<<endl;
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.