Question
/ // TODO: this header, formatting, proper variable names, // comment functions and main code blocks, etc. // #include #include #include #include //Global variables: DO
/ // TODO: this header, formatting, proper variable names, // comment functions and main code blocks, etc. // #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; }
11.18 Project 2b - Habitability of Exoplanets Introduction and Background (duplicated from Project 1a) From the National Academy of Engineering website: "in the popular mind, scientists andi engineers have distinct job descriptions. Scientists explore, experiment, and discover, engineers create, design, and build But in truth, the distinction is blurry, and engineers participate in the scientific process of discovery in many ways. Grand experiments and missions of exploration always need engineering expertise to design the tools, instruments, and systems that make it possible to acquire new knowledge about the physical and biological worlds. In the century ahead, engineers will continue to be partners with scientists in the great quest for understanding many unanswered questions of nature This project is focused on exploring real data on exoplanets (and some a little closer to home). An exoplanet is a planet outside our solar system, orbiting around another star in our galaxy. Most of the exoplanets that we know of today have been discovered in the past two decades using NASA's Kepler space telescope. In general, we are looking for exoplanets that are Earth size and within a habitable zone around a sun-like star, as that may be our best hope of finding life elsewhere in the universe. Check out this video that discusses the search for exoplanets Is There Life on Earth? Watch later 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 candidates for the habitability of life. In this project, we seek to find the few that have been deemed potentially habitable discover are not good 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 overal structure to your code. The template includes a scanf0 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 planet Names In] [m: //planet names int planet.IDs Inli //planet IDs (from NASA's database) double planetRadiidinl: I/planet radius (units: of Jupiter radii) double planetorbPeriodin): //planet orbital period (units: days) double starRadiinli //star radius (units: solar radii) double planetEqTemp[n): //planet equilibrium temperature (units: K) double planetDistoverRadius In): //ratio (distance planet to star)/(star radius) planetDistOverRadius is an array of ratios for the planet distance to its star TO its star's radius radi as a proportion to Jupiters 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. starRadi is the array of star radi for the planets, as a proportion to our Sun's radius (thus, Earth and Mars have star radi of 1.0). Programing Tasks Some of the tasks require general proper functionality of user-defined functions (specificlly and very unhabitablit general proper functionality of user-defined functions (specifically the functions that test for planet habitability y). Some of the test cases involve unit testing of your functions, independent of your calls from main0. These tests test for ensure proper and general functionality of your user-defined functions. 1.Calculate an array of planet distances to their stars using the calcDistToStaro function: Write a function (the shell for calcDist ToStarO is provided in the template) to calculate the distance from a planet to its star using the star's radius (in solar radi 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 In main0. make an additional array to hold planet-distance-to-star values for each planet. Fill this array by calling calcDistToStar0 inside a loop. Again, you already achieved this task in project 2a, but now do so by calling your calcDistToStar0 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 countDatalninterval0 function o Write the function countDatalninterval0.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 countDatalnintervalO 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 isitHabitable0 function o Write the function isitHabitable0, 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 o In main0, call isltHabitable0 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 isitVeryUnhabitable0 function o Write the function isitVeryUnhabitable0, 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 isltHabitable0 function. In main0, call isitVeryUnhabitable0 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: Very Unhabitable Planets CoRoT-11 CoRoT-1 COROT-10 CoRoT-13 CoRoT-14 CoRoT-17 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 Repler-435 Kepler-44 Kepler-45 Total number of Very Unhabitable Planets: 31 Grading [100 points total 45 points: auto graded test cases 20 points: closer inspection of program functionality o these points will be awarded for significant progress at developing code that ended up non-functional (i.e. not passing the test cases) NOTE: Your code must compile, run, and pass tasks to be submitted to us via zyBooks o hardcoding output to match test case output is not allowed and will result in O points for this grade component, with the possibility of additional grade penalities 25 points: formatting and style, 5 points for each of the following (see piazza post @6 for more details): o meaningful variable names o comments short description stating the purpose of each block of code in main) and each function o variable declaration &initialization: valid types, proper initializing, no additional global variables o code layout: nested levels with proper indentation o program header must include overall goal of program, author, class, and date 10 points: submit your code to Gradescope odevelop &submit on zyBooks o download your best submission, should be a project2b.c file o upload the project2b.c file to Gradescope->Project 2b 2 TOD0: this header, formatting, proper variable names, comment functions and main code blocks, etc. 5 #include
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started