Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In C please with comments, I would like to re-do it on my own thanks! Potential Habitability of Life on Exoplanets As discovered in project

In C please with comments, I would like to re-do it on my own thanks!

Potential Habitability of Life on Exoplanets

As discovered in project 1a, the current state-of-the-art methods for finding exoplanets is good at finding very BIG planets that are are very close to their stars, which is not a good combination for the habitability of life. Thus, many of the exoplanets we discover are not good candidates for the habitability of life. In this project, we seek to find the few that have been deemed potentially habitable.

For our purposes, potentially habitable is defined as all of the following (loosely interpreted from this source to include Mars as habitable):

  • planet's radius is between 0.2 and 5.0 times Earth's radius
  • planet's orbital period is between 91 and 801 days
  • planet's equilibrium temperature is between 183 and 294 K
  • planet's distance to its star is between 0.4 and 2.35 AU

Code Template & Input Data

  • A template code is provided. Your program must contain all aspects of the template. That is, you will need to add a lot of code, but you should not remove or modify any part of the template when adding your code. It is vital for passing some of the test cases that the function definitions (function names, parameter types and order, return type, etc.) are exactly as they appear on the template. The template also has six commented TODO statements, which highlight the coding components that are required and give an overall structure to your code.
  • The template includes a scanf() of a single user input, which represents how many planets to read-in data for and analyze. Assume the user enters a number between 1 and 263 (since the file contains data for 263 total planets).
  • A subset of the data that NASA has collected on exoplanets (in addition to three planets closer to home) is read in from a file in the template code provided for this project. The data is stored in the following arrays, where the comments describe each:

image text in transcribed

That is:

  • planetDistOverRadius is an array of ratios for the planet distance to its star TO its star's radius.
  • planetRadiiJ is the array of planets radii as a proportion to Jupiter's radius (that's just a convenient unit on the exoplanetary scale).
  • planetOrbPeriod is the array of planet orbital periods in days.
  • planetEqTemp is the array of planet equilibrium temperatures in Kelvin.
  • starRadii is the array of star radii for the planets, as a proportion to our Sun's radius (thus, Earth and Mars have star radii of 1.0).

Programing Tasks

Some of the tasks require general, proper functionality of user-defined functions (specifically the functions that test for planet habitability and very unhabitability). Some of the test cases involve unit testing of your functions, independent of your calls from main(). These tests ensure proper and general functionality of your user-defined functions.

  1. Calculate an array of planet distances to their stars using the calcDistToStar() function:

    • Write a function (the shell for calcDistToStar() is provided in the template) to calculate the distance from a planet to its star using the star's radius (in solar radii units) and the ratio of the planet distance to its star to the star's radius. Note that you have already coded this calculation to complete project 2a. Now, generalize the functionality by writing the calculation as a function. Recall: the units for the distance must be Astronomical Units, AU (or the typical distance from the Sun to the Earth, where 1 AU = 215 solar radii). See the comments in the template for the required input parameters and return type.
    • In main(), make an additional array to hold planet-distance-to-star values for each planet. Fill this array by calling calcDistToStar() inside a loop. Again, you already achieved this task in project 2a, but now do so by calling your calcDistToStar() function. You will use this new array in all following programming tasks.
  2. Report the number of planets (among the data read in and stored in the arrays) that satisfy EACH of the four criteria for habitability using the countDataInInterval() function:

    • Write the function countDataInInterval(), which counts up the values in an array that fall into the specified interval. See the comments in the template for the required input parameters and return type.
    • In main(), call your countDataInInterval() function for each of the four habitability criteria. Report the results by printing a message to screen formatted as shown in the sample output below.
  3. Find the planets in the data set that are deemed potentially habitable using the isItHabitable() function:

    • Write the function isItHabitable(), which returns a boolean representing whether ALL four habitability criteria are met for input planet parameters. That is, the function should return true if the planets meets ALL of the habitability criteria. See the comments in the template for more details, including the required input parameters and return type.
    • In main(), call isItHabitable() for each of the planets stored in the arrays, and print out a list of potentially habitable planets, in addition to the total number of habitable planets found. See the sample output below for proper formatting of output.
  4. Find the planets in the data set that are deemed very unhabitable using the isItVeryUnhabitable() function:.

    • Write the function isItVeryUnhabitable(), which returns a boolean representing whether NONE of the four habitability criteria are met for input planet parameters. That is, the function should return true if the planets meets NONE of the habitability criteria. You need to write the function definition for this function, which must have identical input parameters (and in the same order) as the isItHabitable() function.
    • In main(), call isItVeryUnhabitable() for each of the planets stored in the arrays, and print out a list of very unhabitable planets, in addition to the total number of very unhabitable planets found. See the sample output below for proper formatting of output.

Sample Output

Here is a complete sample output from the code, where 50 planets on the list of been included in the investigation (note: two habitable exoplanets have been found here, in addition to two in our solar system):

image text in transcribed

image text in transcribed

// // TODO: this header, formatting, proper variable names, // comment functions and main code blocks, etc. // #include #include #include #include

//Global variables: DO NOT REMOVE, DO NOT MODIFY, DO NOT ADD ANY MORE double const RADIUS_JUPITER = 43441.0; //miles double const RADIUS_EARTH = 3959.0; //miles

// calcDistToStar: calculates planet distance to its star // [in] starRadius: radius of star in units of Solar radii // [in] planetRatio: ratio of (planet distance to star)/(star radius) // [out] returns double: planet distance to star in units of AU double calcDistToStar(double starRadius, double planetRatio){ //TODO: write the code to obtain the required functionality for this function }

// countDataInInterval: "bins" the input data by counting entries in the specified interval // [in] lowerBound: lower value of interval // [in] upperBound: upper value of interval // [in] data[size]: array of doubles to be binned (counted) // [in] size: array size of data[] // [out] returns int: count of values in data[] that fall in the specified interval int countDataInInterval(double lowerBound, double upperBound, double data[], int size){ //TODO: write the code to obtain the required functionality for this function }

// isItHabitable: apply conditions for "Habitable Exoplanet" to check if the planet is "habitable" // [in] radius: planet radius (in miles) // [in] orbitPer: orbital period for planet (in days) // [in] temperature: equilibrium temperature of the planet (in K) // [in] distance: to the star (in AU) // [out] returns bool: true only if planet passes all the "habitable" tests, otherwise false bool isItHabitable(double radius, double orbitPer, double temperature, double distance){ //TODO: write the code to obtain the required functionality for this function }

//TODO: WRITE THE FUNCTION isItVeryUnhabitable(), // which takes in identical input argruments // (numebr, type, etc.) as isItHabitable() // (make sure to include a description similar // to those in the provided code template)

int main(){ // ~~~~~~~~~~~~~~ START OF PROVIDED TEMPLATE CODE ~~~~~~~~~~~~~~~~~~~` // DO NOT MODIFY THE PROVIDED TEMPLATE CODE // instead, add your code in main() below the provided code. // The following provided template code... // 1) allows the user to enter an integer, np // 2) reads in data from a file for np planets // 3) stores the planet data in 7 arrays

FILE *inFile = NULL; // File pointer const int n = 300; //max. number of data const int m = 20; //buffer size //Arrays to store planet info char planetNames[n][m]; //planet names int planetIDs[n]; //planet IDs (from NASA) double planetRadiiJ[n]; //planet radius (units: # of Jupiter radii) double planetOrbPeriod[n]; //planet orbital period (units: days) double starRadii[n]; //star radius (units: solar radii) double planetEqTemp[n]; //planet equilibrium temperature (units: K) double planetDistOverRadius[n]; //ratio (distance planet to star)/(star radius) int np = 0; printf("How many planets would you like to read in: "); scanf("%d",&np); int counter = 0; inFile = fopen("planets2.txt","r"); if (inFile == NULL) { printf("Could not open file. "); return -1; // -1 indicates error } while (counter

return 0; }

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

Practical Neo4j

Authors: Gregory Jordan

1st Edition

1484200225, 9781484200223

More Books

Students also viewed these Databases questions

Question

How do you add two harmonic motions having different frequencies?

Answered: 1 week ago