Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David M. Kroenke, David J. Auer

7th edition

133544621, 133544626, 0-13-354462-1, 978-0133544626

More Books

Students also viewed these Databases questions

Question

Question What is a secular trust?

Answered: 1 week ago