Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

You've been hired by Faraway Fantasies to write a C++ console application that reads data from file NearestStars.txt. The file contains the ten nearest stars

You've been hired by Faraway Fantasies to write a C++ console application that reads data from file NearestStars.txt. The file contains the ten nearest stars to Earth. It has a header line and ten detail lines. Each detail line contains two tokens:

Star name

Distance from Earth in light minutes (Sun) and light years (all other stars).

Place the file in a folder where your development tool can locate it, or place the file in a data folder and use a path to the file. In the app, attempt to open the file. If it doesn't open, print an error message. If it does open, print a file-reading message, and three column headers:

Star

Distance

Time (described next)

Use a while loop to read through the file. For each detail line, read the star name and distance. Assume there is a spacecraft that travels 0.4 light years per hour (yes, that's fast; is it possible? Ask Jacob.). Calculate the time to travel to the star. Note that the distance to the Sun is in light minutes so the time calculation will have to use a factor of 525,600 minutes per year. Use formatted output manipulators (setw, left/right) to print in one row the following:

Star

Distance

Time

Track the number of lines read and print the count after the loop. Define constants for the input file name, spacecraft speed, minutes per year, and the column widths. Format all real numbers to six decimal places. See sample app TextFileInput-OneTokenPerRead.cpp on Canvas. The output should look like this:

Welcome to Faraway Fantasies

----------------------------

Reading tokens from file 'NearestStars.txt' ...

Star Distance* Time (hours)

...

*Distance to sun is in light minutes. Distance to all other stars is in light years.

11 line(s) read from file 'NearestStars.txt'.

End of Faraway Fantasies

NearestStars.txt

Star Distance Sun 8.2 Proxima_Centauri 4.24 Alpha_Centauri_A 4.36 Alpha_Centauri_B 4.36 Barnard's_Star 5.96 WISE_1049-5319 6.5 Wolf_359 7.78 Lalande_21185 8.3 Sirius_A 8.58 Sirius_B 8.5

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

Professional Visual Basic 6 Databases

Authors: Charles Williams

1st Edition

1861002025, 978-1861002020

More Books

Students also viewed these Databases questions

Question

What are hybrid securities? Give an example of a hybrid security.

Answered: 1 week ago