Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need this in C language. Please follow the instructions as listed and do not HARD CODE to match the output Potential Habitability of Life on

Need this in C language. Please follow the instructions as listed and do not HARD CODE to match the output

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:
 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 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):

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 

image text in transcribedimage text in transcribedimage text in transcribed

S1 52 int main() G3 54 DO NOT MODIFY THE PROVIDED TEMPLATE CODE START OF PROVIDED TEMPLATE CODE instead, add your cade in main) below the provided code 56 Ihe following provided template code 571) allows the user to enter an integer, np 582) reads in data from a file for np planets 59 3) stores the planet data in 7 arrays 61 62 FLLt intile -NULL; // le pointer const intn 309; max. nunber of data const int m 20; buffer size 66 char planetNanes [n][m]; /planet names 68 double olanetRad11J[n]; //planet radius (units: # of Jupiter rad11) 70 double star Rd11 [n]; //star radus (units : solar radii) 72 Arrays to store planct info int planrtTDs[n] planet TDs (from NASA) dnuble planetorbPeriodn]; planet orhital perind units: days) dbl planetEqTenplnl plarit equilibrium temperature (units: K) double planetDistoverRadius[n]; /fratio (distance planet to star)/(star radius) int np 8; cant"d",&np) 74 75 printf( "How many planets would you like to read in:; int counter ; 79inFile fopen"planets2.txt","r); 8e if (inrileNULL) printf("Could not open file.n" return -1; 1 indicates error 32 83 84 while np){ (counter f5canf (inFile, "%" ,&planet IDs [counter] ); fscanf(inFile, "%s", olanetNames [counter] ); fscanf ( 1 nFi 1 e, "%lf",&planetorhPeriod [counter] ) i fscanf(inFile, "S1f ,&planetRad11 [counter]; fscarf (1nFile. "%lf",LstarRad11 [counter] ); fscanf(inFile,"%) f",iplanet EqTemplcounter]); fscanf(inFile, "%1f",&planetDLstOver Radius [counter] ); cnunterI 86 87 39 93 felosinFilr); 96 97 END OF PROVIDED TEMPLATE CODE Enter your code below this conment 58 2) reads in data from a file for np planets 59 3) stares the planet data in7 arrays FILE nFile - NULL; // File pointer const int n ; //max. number of data const int n28 huffer size 62 G5 Arrays Lo sLore planel into char planetNames[nplanet names nt planetIDs[n]; //planet IDs (from NASA) 68 double planet Rad i i][n1; //planet radius (units: # af Jupiter, radii) 69 double planetorbPeriodnl; planet orbital period (units: days) 70 71 72 double planetDistoverRadiusn] Fratio (distance planet to star)/(star radius) double starRadii[n] star radius (units: solar radii) double planctFaTemp[n /planct cquilihriun temperature (units: K) int np - printf("Ho~ many planets scanf("%d",&no); int counter would you like to read in: "); 75 76 inFile fopen"plenets2.txt","r": if (inFileNULL) 79 printr"Could not open file.n) return-1; 1 indicates erro B2 83 84 while (counter np) 85 86 B7 fscant( nfi le,"M",&planetTDs [counter]); fscar f(in File, s", planetNamescounter! ) ; fscanf(inFile,"lf",&planetorbPeriod[counter]); fscant(infile,"%lf",AplanetRadi)[counter]); fscant( in File, "%1f", &starRad 11 [counter] ) ; fscan f(inFile, "%1f", &pianetEqTemp[counter] ); tscant( infile,"xit",lplanetDistderRaduslcounter); counter++ 90 91 92 93 fclose(inFile); END or PROVIDED TEMPLATE CODE Enter your cade below this comnent 98 188 181 182 // IODO; mplement calculations and functions calls to acheive the required programming tasks return 8; S1 52 int main() G3 54 DO NOT MODIFY THE PROVIDED TEMPLATE CODE START OF PROVIDED TEMPLATE CODE instead, add your cade in main) below the provided code 56 Ihe following provided template code 571) allows the user to enter an integer, np 582) reads in data from a file for np planets 59 3) stores the planet data in 7 arrays 61 62 FLLt intile -NULL; // le pointer const intn 309; max. nunber of data const int m 20; buffer size 66 char planetNanes [n][m]; /planet names 68 double olanetRad11J[n]; //planet radius (units: # of Jupiter rad11) 70 double star Rd11 [n]; //star radus (units : solar radii) 72 Arrays to store planct info int planrtTDs[n] planet TDs (from NASA) dnuble planetorbPeriodn]; planet orhital perind units: days) dbl planetEqTenplnl plarit equilibrium temperature (units: K) double planetDistoverRadius[n]; /fratio (distance planet to star)/(star radius) int np 8; cant"d",&np) 74 75 printf( "How many planets would you like to read in:; int counter ; 79inFile fopen"planets2.txt","r); 8e if (inrileNULL) printf("Could not open file.n" return -1; 1 indicates error 32 83 84 while np){ (counter f5canf (inFile, "%" ,&planet IDs [counter] ); fscanf(inFile, "%s", olanetNames [counter] ); fscanf ( 1 nFi 1 e, "%lf",&planetorhPeriod [counter] ) i fscanf(inFile, "S1f ,&planetRad11 [counter]; fscarf (1nFile. "%lf",LstarRad11 [counter] ); fscanf(inFile,"%) f",iplanet EqTemplcounter]); fscanf(inFile, "%1f",&planetDLstOver Radius [counter] ); cnunterI 86 87 39 93 felosinFilr); 96 97 END OF PROVIDED TEMPLATE CODE Enter your code below this conment 58 2) reads in data from a file for np planets 59 3) stares the planet data in7 arrays FILE nFile - NULL; // File pointer const int n ; //max. number of data const int n28 huffer size 62 G5 Arrays Lo sLore planel into char planetNames[nplanet names nt planetIDs[n]; //planet IDs (from NASA) 68 double planet Rad i i][n1; //planet radius (units: # af Jupiter, radii) 69 double planetorbPeriodnl; planet orbital period (units: days) 70 71 72 double planetDistoverRadiusn] Fratio (distance planet to star)/(star radius) double starRadii[n] star radius (units: solar radii) double planctFaTemp[n /planct cquilihriun temperature (units: K) int np - printf("Ho~ many planets scanf("%d",&no); int counter would you like to read in: "); 75 76 inFile fopen"plenets2.txt","r": if (inFileNULL) 79 printr"Could not open file.n) return-1; 1 indicates erro B2 83 84 while (counter np) 85 86 B7 fscant( nfi le,"M",&planetTDs [counter]); fscar f(in File, s", planetNamescounter! ) ; fscanf(inFile,"lf",&planetorbPeriod[counter]); fscant(infile,"%lf",AplanetRadi)[counter]); fscant( in File, "%1f", &starRad 11 [counter] ) ; fscan f(inFile, "%1f", &pianetEqTemp[counter] ); tscant( infile,"xit",lplanetDistderRaduslcounter); counter++ 90 91 92 93 fclose(inFile); END or PROVIDED TEMPLATE CODE Enter your cade below this comnent 98 188 181 182 // IODO; mplement calculations and functions calls to acheive the required programming tasks return 8

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_2

Step: 3

blur-text-image_3

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 ASP.NET 4.5 Databases

Authors: Sandeep Chanda, Damien Foggon

3rd Edition

1430243805, 978-1430243809

More Books

Students also viewed these Databases questions

Question

What are the five major project fundamentals?

Answered: 1 week ago

Question

Evaluate the probabilities when n = 8 and p = .2 21. C*(2)'(.8)

Answered: 1 week ago

Question

Formulate strategies and recommendations for action on HRM issues.

Answered: 1 week ago