With our time on Earth coming to an end, Cooper and Amelia have volunteered to undertake what could be the most importan

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

With our time on Earth coming to an end, Cooper and Amelia have volunteered to undertake what could be the most importan

Post by answerhappygod »

With our time on Earth coming to an end, Cooper and Amelia have
volunteered to undertake what could be the most important mission
in human history: travelling beyond this galaxy to discover whether
mankind has a future among the stars. Fortunately, astronomers have
identified several potentially habitable planets and have also
discovered that some of these planets have wormholes joining them,
which effectively makes travel distance between these
wormhole-connected planets zero. Note that the wormholes in this
problem are considered to be one-way. For all other planets, the
travel distance between them is simply the Euclidian distance
between the planets. Given the locations of planets, wormholes, and
a list of pairs of planets, find the shortest travel distance
between the listed pairs of planets.

implement your code to expect input from an input file indicated by
the user at runtime with output written to a file indicated by the
user.
The first line of input is a single integer, T (1 ≤ T ≤ 10): the
number of test cases.
• Each test case consists of planets, wormholes, and a set of
distance queries as pairs of planets.
• The planets list for a test case starts with a single integer, p
(1 ≤ p ≤ 60): the number of planets.
Following this are p lines, where each line contains a planet name
(a single string with no spaces)
along with the planet’s integer coordinates, i.e. name x y z (0 ≤
x, y, z ≤ 2 * 106). The names of the
planets will consist only of ASCII letters and numbers, and will
always start with an ASCII letter.
Planet names are case-sensitive (Earth and earth are distinct
planets). The length of a planet name
will never be greater than 50 characters. All coordinates are given
in parsecs (for theme. Don’t
expect any correspondence to actual astronomical distances).
• The wormholes list for a test case starts with a single integer,
w (1 ≤ w ≤ 40): the number of
wormholes, followed by the list of w wormholes. Each wormhole
consists of two planet names
separated by a space. The first planet name marks the entrance of a
wormhole, and the second
planet name marks the exit from the wormhole. The planets that mark
wormholes will be chosen
from the list of planets given in the preceding section. Note: you
can’t enter a wormhole at its exit.
• The queries list for a test case starts with a single integer, q
(1 ≤ q ≤ 20), the number of queries.
Each query consists of two planet names separated by a space. Both
planets will have been listed in
the planet list.
C++ Could someone help me to edit this code in order to read
information from an input file and write the results to an output
file?
The input.txt
3
4
Earth 0 0 0
Proxima 5 0 0
Barnards 5 5 0
Sirius 0 5 0
2
Earth Barnards
Barnards Sirius
6
Earth Proxima
Earth Barnards
Earth Sirius
Proxima Earth
Barnards Earth
Sirius Earth
3
z1 0 0 0
z2 10 10 10
z3 10 0 0
1
z1 z2
3
z2 z1
z1 z2
z1 z3
2
Mars 12345 98765 87654
Jupiter 45678 65432 11111
0
1
Mars Jupiter
The expected output.txt
Case 1:
The distance from Earth to Proxima is 5 parsecs.
The distance from Earth to Barnards is 0 parsecs.
The distance from Earth to Sirius is 0 parsecs.
The distance from Proxima to Earth is 5 parsecs.
The distance from Barnards to Earth is 5 parsecs.
The distance from Sirius to Earth is 5 parsecs.
Case 2:
The distance from z2 to z1 is 17 parsecs.
The distance from z1 to z2 is 0 parsecs.
The distance from z1 to z3 is 10 parsecs.
Case 3:
The distance from Mars to Jupiter is 89894 parsecs.
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply