Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Code in C++ Given the following program which creates an array of 100 temperature readings, print out the city with the highest temperature reading. Also
Code in C++
Given the following program which creates an array of 100 temperature readings, print out the city with the highest temperature reading. Also print out the average temperature of "Houston".
Starter Code:
#include#include #include #include using namespace std::string_literals; struct CityTempReading { std::string city; double temperature; }; CityTempReading getNewReading(); int main() { std::array readings; for (auto i = 0; i < readings.size(); i++) { readings.at(i) = getNewReading(); } // TODO: print city with the hottest temperature reading // TODO: print out the average temperature of "Houston" } CityTempReading getNewReading() { static std::mt19937 rand{ std::random_device{}() }; static std::uniform_real_distribution temperatureRange{ 0.0, 110.0 }; static std::array cities = { "New York", "Los Angeles", "Las Vegas", "Denver", "Houston", "Atlanta", "Seattle", "San Francisco", "Boston", "Miami" }; static std::uniform_int_distribution cityRange{ 0, cities.size() - 1 }; return CityTempReading{ cities.at(cityRange(rand)), temperatureRange(rand) }; }
Sample Output:
hottest temperature: Miami at 108.635 degrees Houston average: 55.0432
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started