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 P

M_PI_4 = value of P / 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.

image text in transcribed

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.comumbers/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). image text in transcribed

File: work/hw2.c 1 #include "hw2.h" //DO NOT REMOVE THIS INCLUDE STATEMENT FNMTN 6 /*DO NOT DELETE THE FUNCTION BELOW 7 Modify the function below to attempt the extra credit. 9 int calc_fib71(int n) 10 { */ return 1; 13 } File: work/hw2.h 1 // You SHOULD NOT modify this file unless you are attempted to get extra credit 2 #ifndef HW2_H 3 #define HW2_H 5 double calc_resistance( double resistivity, int length_m, int diameter_mm): 6 int calc_fibn(int n); 8 //modify the function prototype below (DON'T CHANGE THE FUNCTION NAME OR PARAMETER) to attempt the extra credit 9 int calc_fib71(int n); 10 11 #endif

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

Big Data, Mining, And Analytics Components Of Strategic Decision Making

Authors: Stephan Kudyba

1st Edition

1466568704, 9781466568709

More Books

Students also viewed these Databases questions

Question

Queues can help to equitably reduce moral hazard.

Answered: 1 week ago