Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please I need help with this ASAP. In C and no HARD CODING. Potential Habitability of Life on Exoplanets As discovered in project 1a, the

Please I need help with this ASAP.

In C and no HARD CODING.

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.

Here is a small subset of the data that has been collected on exoplanets (in addition to three planets closer to home):

Planet Name Planet Radius Star Radius Planet Distance to Star/Star Radius
Earth 0.091135 1.0 215.1
Mars 0.0475 1.0 327.8
Venus 0.08465 1.0 154.87
HAT-P-16 1.289 1.24 7.7
K2-29 1.19 0.86 10.51
KELT-4-A 0.699 1.6 5.792
Kepler-421 0.371 0.76 346.0
KOI-94 0.585 1.52 43.1
Kepler-62 0.144 0.64 144.0
Kepler-46 0.808 0.79 45.1
PH2 0.903 1.0 176.7
WASP-82 0.999 0.59 12.63

The units associated with the columns of data are given here:

Planet Name Planet Radius Star Radius Planet Distance to Star/Star Radius
[in Jupiter radii units] [in Solar radii]

Note: the rightmost column is the ratio of the planet distance to its star TO its star's radius.

Note: the planet size (radius) is given as a proportion to Jupiter's radius (that's just a convenient unit on the exoplanetary scale). For example, the Earth has a radius that is 0.091135 times that of Jupiter (i.e. Earth has a radius about 9% of Jupiter's radius). The star radius is given as a proportion to our Sun's radius (thus, Earth and Mars have star radii of 1.0).

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 sixcommented 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:
 char planetNames[n][m]; //planet names int planetIDs[n]; //planet IDs (from NASA's database) 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) 

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 habitabilityand 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 theisItHabitable() 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):

How many planets would you like to read in: 50 Total number of planets passing the radius check: 18 Total number of planets passing the orbital period check: 5 Total number of planets passing the equilibrium temperature check: 4 Total number of planets passing the distance to star check: 6 Potentially Habitable Planets: Earth Mars Kepler-22 Kepler-421 Total number of Potentially Habitable Planets: 4 Very Unhabitable Planets: CoRoT-11 CoRoT-1 CoRoT-10 CoRoT-13 CoRoT-14 CoRoT-17 CoRoT-18 CoRoT-19 CoRoT-20 CoRoT-23 CoRoT-25 CoRoT-26 CoRoT-27 CoRoT-4 CoRoT-6 Kepler-17 Kepler-39 Kepler-40 Kepler-41 Kepler-412 Kepler-423 Kepler-425 Kepler-426 Kepler-427 Kepler-428 Kepler-43 Kepler-433 Kepler-434 Kepler-435 Kepler-44 Kepler-45 Total number of Very Unhabitable Planets: 31 

Here is default template for this code

// // 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 < np){ fscanf(inFile,"%d",&planetIDs[counter]); fscanf(inFile,"%s",planetNames[counter]); fscanf(inFile,"%lf",&planetOrbPeriod[counter]); fscanf(inFile,"%lf",&planetRadiiJ[counter]); fscanf(inFile,"%lf",&starRadii[counter]); fscanf(inFile,"%lf",&planetEqTemp[counter]); fscanf(inFile,"%lf",&planetDistOverRadius[counter]); counter++; } fclose(inFile); // ~~~~~~~~~~~~~~ END OF PROVIDED TEMPLATE CODE ~~~~~~~~~~~~~~~~~~~` // **** Enter your code below this comment **** // TODO: implement calculations and functions calls to acheive the required programming tasks

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

Students also viewed these Databases questions