Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

2) [13 points] Youve been hired by Planet Poachers to write a C++ console application that converts planet data. Download file PlanetsIn.txt to project folder

2) [13 points] Youve been hired by Planet Poachers to write a C++ console application that converts planet data. Download file PlanetsIn.txt to project folder \. Within your application, open file PlanetsIn.txt and scan past the header line. Then, for each line read, echo the line, parse the line into three variables (planet, diameter, length). Use the following C++ string function to parse the line into substrings:

.substr(, )

Use the following C++ function to convert a substring to a real number (double):

stod()

You may combine the parse and convert operations into one. Here is an example:

stod(line.substr(11, 15))

Convert the diameter from miles to kilometers (diameter * 1.609344) and the length to earth days (length / 24). Print the planet, and the converted diameter and length. After all lines have been read from the input file, print the average diameters in miles and kilometers, and the average lengths in hours and days. Format any real numbers to one decimal place. The start of your output should look like this:image text in transcribedThe end of your output should look like this:

 
image text in transcribed 
Planet Diameter (miles) Length of Day (hours) Mercury 3032 4222.6 Venus 7521 2802.0 Earth 7926 24.0 Moon 2159 708.7 Mars 4221 24.7 Jupiter 88846 9.9 Saturn 74897 10.7 Uranus 31763 17.2 Neptune 30775 16.1 Pluto 1485 153.3 
Reading lines from tile PlanetsIn.txt .. . Input line (miles, hours): output line (kilometers, days): Mercury 3032 4879.5 4222.6 175.9 Input line (miles, hours): output line (kilometers, days): Venus 7521 12103.9 2802.0 116.8 Venus

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

Beginning Microsoft SQL Server 2012 Programming

Authors: Paul Atkinson, Robert Vieira

1st Edition

1118102282, 9781118102282

More Books

Students also viewed these Databases questions