Topical Information Use C++. This lab will help you practice with dynamic memory (NOT mixed with classes). Program Information Heat flow through a rod can be simulated fairly easily in a computer program. We can simulate the rod using an array of temperatures. The rod begins all at the same temperature (user determined), but holding some position(s) of the rod at constant temperature (holding a match or ice cube to the rod) provides a [set of] heat source(s) (or sink(s)). To update the temperature at each time step (second?), you take the average of the positions on each side from the previous time step (and at the current position). For instance, if the following was the initial state of the rod: +------+------+------+------+------+------+------+------+  |   10   |   10    |   10   |   10    |   10   |   10   |   10   |   10    | +------+------+------+------+------+------+------+------+ And then the user specifies that there is a heat source at the left end of 100 degrees: +------+------+------+------+------+------+------+------+  |  100  |   10   |   10    |   10   |   10    |   10    |   10   |   10   | +------+------+------+------+------+------+------+------+ Then the next time step would result in: +------+------+------+------+------+------+------+------+ |   100  |   40    |   10   |   10   |   10    |   10    |   10   |   10    | +------+------+------+------+------+------+------+------+ Note how the left end stays the same as it is the heat source and won't change. The next position, however, becomes the average of itself and its two neighbors. Likewise the position after that becomes the average of itself and its two neighbors (it just happens that its two neighbors and it all had the same value — since they all started out the same). A second time step would result in: +------+------+------+------+------+------+------+------+  |   100 |   50   |    20   |    10   |   10   |   10   |    10   |    10   | +------+------+------+------+------+------+------+------+ After many time steps have passed, the heat will flow through the rod and all 7 positions not attached to a heat source will eventually change. Speaking of which, what do you do at the end of the rod? When you hit the end of the rod you don't have two neighbors, do you? You've only got the one previous neighbor! Just take the average of yourself and that one neighbor, then. Problem solved! You should allow the user to enter the length of the rod, the number of time steps to simulate, the positions and temperatures of any heat sources (sinks) (notice I'm not specifying how many sources/sinks there are), and the number of steps to skip between printings (if they simulate for 2 minutes, they probably don't need to see all 120 time steps...maybe just every 20th one or so). Always show the initial (heat sources applied) and final (after the last time step) states of the rod — no matter how many skipped time steps they specify! Use as little memory as possible...

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Topical Information

Use C++. This lab will help you practice with dynamic memory (NOT mixed with classes).

Program Information

Heat flow through a rod can be simulated fairly easily in a computer program. We can simulate the rod using an array of temperatures. The rod begins all at the same temperature (user determined), but holding some position(s) of the rod at constant temperature (holding a match or ice cube to the rod) provides a [set of] heat source(s) (or sink(s)).

To update the temperature at each time step (second?), you take the average of the positions on each side from the previous time step (and at the current position). For instance, if the following was the initial state of the rod:

+------+------+------+------+------+------+------+------+

 |   10   |   10    |   10   |   10    |   10   |   10   |   10   |   10    |

+------+------+------+------+------+------+------+------+

And then the user specifies that there is a heat source at the left end of 100 degrees:

+------+------+------+------+------+------+------+------+

 |  100  |   10   |   10    |   10   |   10    |   10    |   10   |   10   |

+------+------+------+------+------+------+------+------+

Then the next time step would result in:

+------+------+------+------+------+------+------+------+

|   100  |   40    |   10   |   10   |   10    |   10    |   10   |   10    |

+------+------+------+------+------+------+------+------+

Note how the left end stays the same as it is the heat source and won't change. The next position, however, becomes the average of itself and its two neighbors. Likewise the position after that becomes the average of itself and its two neighbors (it just happens that its two neighbors and it all had the same value — since they all started out the same).

A second time step would result in:

+------+------+------+------+------+------+------+------+

 |   100 |   50   |    20   |    10   |   10   |   10   |    10   |    10   |

+------+------+------+------+------+------+------+------+

After many time steps have passed, the heat will flow through the rod and all 7 positions not attached to a heat source will eventually change.

Speaking of which, what do you do at the end of the rod? When you hit the end of the rod you don't have two neighbors, do you? You've only got the one previous neighbor! Just take the average of yourself and that one neighbor, then. Problem solved!

You should allow the user to enter the length of the rod, the number of time steps to simulate, the positions and temperatures of any heat sources (sinks) (notice I'm not specifying how many sources/sinks there are), and the number of steps to skip between printings (if they simulate for 2 minutes, they probably don't need to see all 120 time steps...maybe just every 20th one or so).

Always show the initial (heat sources applied) and final (after the last time step) states of the rod — no matter how many skipped time steps they specify!

Use as little memory as possible...

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education