declare variables, include your arrays. Declare two struct variables to hold data. The first will be the TravelerInfo struct, which holds name(string), weight(double), newWeight(double) for the weight on the other planet, planetChoice ( int) and speed(int). The second struct is the TravelTimeCalc struct. It holds total travel time, years, days, and hours. All are ints. Both structs are declared in the Functions.h file. Write out a program title and brief introduction using your Header function. Pass the arrays to the FillPlanetInfo function, which will load the data into the three arrays. Start a do while loop in main as your Play loop. Pass the function AskSpaceTravellerInfo a reference to the TravelerInfo struct variable and the array of planet names. Get the user’s name, Earth weight, the speed they want to travel and the planet they wish to visit. You will need to provide a menu with the planet names and a way for the user to select the chosen destination. Pass the data you obtained (TravelerInfo variable), the TravelTimeCalc struct variable, and the 3 arrays into the CalculateTimeandWeight function, which will determine the user’s weight on the destination planet and the travel time in hours. Call the Write function, passing the planet name array, a pointer to the filename, and the two structs, containing all the data to be presented to the user in a cout statement and to be written into a file. Call the CalcTimes function to convert the total hours to years, days and hours. Use a stringstream to create a string with all of the output data which will be displayed to the user and also written into a file. Use two decimal places to display any numbers. Still in the Write function, call CreateFilename to create a filename from the user’s name and from today’s date. Declare a static variable in CreateFilename, static int number = 1; Increment number each time the function CreateFilename is called. Use system time and date to get the integers needed to create this form of filename: name _ month_day_year_number.txt. Write the string you have created into this file. Return a string to Write containing the filename. In Write, open the file and check to see if the file was opened. Return a bool from the Write function indicating file success or failure. Check the bool in main and report to the user that the file was created, and the filename and if not, that no file was created. Ask the user if they would like to calculate another space trip. Remember to tell the user the choices for an answer. If yes, loop up to the top of the Play Loop. When the user is done, present a good-bye message. Set the precision, etc, so you are reporting numbers with 2 decimal places. equations: Weight on New Planet = Weight on Earth * Relative Surface Gravity of New Planet Travel Time (hours) = Travel Distance (miles) / Speed of Travel(mph) Planets, distance from sun(millions of miles), surface gravity as a percent of earth’s gravity: Mercury 36 0.27 Venus 67 0.86 Earth 93 1.00 Mars 141 0.37 Jupiter 483 2.64 Saturn 886 1.17 Uranus 1782 0.92 Neptune 2793 1.44
declare variables, include your arrays. Declare two struct variables to hold data. The first will be the TravelerInfo struct, which holds name(string), weight(double), newWeight(double) for the weight on the other planet, planetChoice ( int) and speed(int). The second struct is the TravelTimeCalc struct. It holds total travel time, years, days, and hours. All are ints. Both structs are declared in the Functions.h file.
Write out a program title and brief introduction using your Header function. Pass the arrays to the FillPlanetInfo function, which will load the data into the three arrays. Start a do while loop in main as your Play loop.
Pass the function AskSpaceTravellerInfo a reference to the TravelerInfo struct variable and the array of planet names. Get the user’s name, Earth weight, the speed they want to travel and the planet they wish to visit. You will need to provide a menu with the planet names and a way for the user to select the chosen destination.
Pass the data you obtained (TravelerInfo variable), the TravelTimeCalc struct variable, and the 3 arrays into the CalculateTimeandWeight function, which will determine the user’s weight on the destination planet and the travel time in hours.
Call the Write function, passing the planet name array, a pointer to the filename, and the two structs, containing all the data to be presented to the user in a cout statement and to be written into a file. Call the CalcTimes function to convert the total hours to years, days and hours. Use a stringstream to create a string with all of the output data which will be displayed to the user and also written into a file. Use two decimal places to display any numbers.
Still in the Write function, call CreateFilename to create a filename from the user’s name and from today’s date. Declare a static variable in CreateFilename, static int number = 1; Increment number each time the function CreateFilename is called. Use system time and date to get the integers needed to create this form of filename: name _ month_day_year_number.txt. Write the string you have created into this file. Return a string to Write containing the filename.
In Write, open the file and check to see if the file was opened. Return a bool from the Write function indicating file success or failure. Check the bool in main and report to the user that the file was created, and the filename and if not, that no file was created.
Ask the user if they would like to calculate another space trip. Remember to tell the user the choices for an answer. If yes, loop up to the top of the Play Loop. When the user is done, present a good-bye message.
Set the precision, etc, so you are reporting numbers with 2 decimal places.
equations:
Weight on New Planet = Weight on Earth * Relative Surface Gravity of New Planet
Travel Time (hours) = Travel Distance (miles) / Speed of Travel(mph)
Planets, distance from sun(millions of miles), surface gravity as a percent of earth’s gravity:
Mercury 36 0.27
Venus 67 0.86
Earth 93 1.00
Mars 141 0.37
Jupiter 483 2.64
Saturn 886 1.17
Uranus 1782 0.92
Neptune 2793 1.44
Unlock instant AI solutions
Tap the button
to generate a solution