Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Part 1 (50 points) Write a function that is able to calculate the resistance of a metal given the resistivity of a particular metal (expressed

Part 1 (50 points) Write a function that is able to calculate the resistance of a metal given the resistivity of a particular metal (expressed as a double), the length of the wire in meters (expressed as an int), and the diameter of the wire in millimeters (expressed also as an int). 1) Be sure to write at least one multi-line comment above the function describing what it does, how to use it, etc.. 2) In addition, within the function, include comments explaining what the pieces of your code are doing. The formula for calculating the resistance of a metal is as follows: Resistance = resistivity * length of wire / area of wire Here is the prototype for the function that you must follow. In vocareum, the prototype is already written into hw2.h and MUST be included in your file. Your c file should also be named hw2.c. Example: #include "hw2.h" <-- This should be at the top of your hw2.c file double calc_resistance(double resistivity, int length_m, int diameter_mm); Tips for part 1: The math library includes constants (variables whose values cannot be modified) and functions useful for math. If you include the library, you can use them as-if you had created them in your file. Here are a few that might be helpful: M_PI = value of pi M_PI_4 = value of pi/4 result = pow(number, power you want to raise it to) Keep in mind that you will be given the DIAMETER of the wire in mm. The formula uses the area of a wire. After converting from some diameter (in mm) to area you will end up with some area mm2. You will need to account for that when you use the number in your formula.

Part 2 (50 points each correctly calculated term up to 46 will result in 1/46th % credit of the 50 pts) Write a function that can calculate the nth term in the Fibonacci sequence given some whole number n. You should use Binets formula in your function to solve this. You DO NOT need to worry about negative numbers for n. Your function ONLY needs to be correct up to the 46th fib term. Below is the prototype for the function you will be making. It will be included in hw2.h. int calc_fibn(int n); Here are links explaining both the Fibonacci series and Binets formula to calculate the nth term of the Fibonacci series. https://www.mathsisfun.com/numbers/fibonacci-sequence.html http://www.maths.surrey.ac.uk/hosted-sites/R.Knott/Fibonacci/fibFormula.html You can check your work here: http://www.maths.surrey.ac.uk/hosted-sites/R.Knott/Fibonacci/fibtable.html TIP for implementing Binets formula in C: The square root of a number can be expressed as that number raised to the .5 power (think about how to represent phi in Binets formula). EXTRA CREDIT (10 points each correctly calculated term from 47 71 will result in 1/24th % credit of the 10 points): If you can, modify the dummy function Ive included in such a way that it can correct calculate up to the 71st Fibonacci term. I have already created a dummy function prototype in hw2.h. DO NOT remove it, OR change the function name, OR change the parameter, as my tests depend on at least that being present. Modify the dummy prototype as necessary to attempt extra credit. I have already created a dummy function definition for you in hw2.c that simply returns the number 1. DO NOT remove it, OR change the function name, OR change the parameter, as my tests depend on at least that being present. Modify the dummy function definition as necessary to attempt extra credit. TIP for the extra credit: An integer is only capable of displaying up to the 46th term correctly due to the size of that number and the number of bits that the integer datatype is allowed to use.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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