Question: Please Write in C++ Given the following code, implement an output operator overalod such that the commented code can be uncommented and compile and so
Please Write in C++
Given the following code, implement an output operator overalod such that the commented code can be uncommented and compile and so that when the code runs it prints out all the temperature reading objects.
Starter Code:
#include#include #include #include struct TemperatureReading { std::string city; double temperature; }; TemperatureReading getNewReading(); int main() { std::array readings; for (auto i = 0; i < readings.size(); i++) { readings.at(i) = getNewReading(); } for (auto i = 0; i < readings.size(); i++) { // TODO: implement a output operater overload so that the following code compiles // std::cout << readings.at(i) << " "; } } TemperatureReading 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 TemperatureReading{ cities.at(cityRange(rand)), temperatureRange(rand) }; }
Sample Output:
READING: Las Vegas = 75.075 READING: Boston = 37.0607 READING: Boston = 7.36296 READING: San Francisco = 42.4018 READING: Atlanta = 10.7666 READING: Seattle = 103.802 READING: Seattle = 48.6055 READING: Denver = 5.68076 READING: Miami = 60.6335 READING: Denver = 80.7113
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
