Question: Arrays, Pointers and Functions Exercise Sinusoidal Function Generator 3.2.1 Time Series Function Write a function with comment blocks to create an array of time steps

Arrays, Pointers and Functions Exercise

Sinusoidal Function Generator 3.2.1 Time Series Function Write a function with comment blocks to create an array of time steps from start to stop at a specified time step. Heres the prototype: int timeVector(double *tVec, double tStart, double tStep, double tStop) tVec address to time series vector which will be assigned in the function. It will have N elements. tVec[0] = tStart, tVec[i] - tVec[i-1] = tStep;

tVec[N-1] = tStop? Or does it always = tStop? N is the number of elements in tVec The variable here to calculate is the number of elements and it must be adjusted to accommodate tStart, tStep and tStop. But depending on their value you will not always be able to meet tStop exactly. For example consider tStart = 0, tStep = .3, tStop = 2. 0, 0.3, 0.6, 0.9, 1.2, 1.5, 1.8, 2.1 N = 8 We need a rule and the rule is: tVect[N-1] <= tStop. So our function timeVector would generate: 0, 0.3, 0.6, 0.9, 1.2, 1.5, 1.8 N = 7 You will need to calculate N, the number of elements defined by tStart, tStep and tStop in the function and use it as the return value of the function so that users of tVec will know how many valid elements are in it. Your function must return 1 if any of the following conditions are TRUE: (N > TVEC_SIZE) OR (tStart > tStop) OR (tStart OR tStep OR tStop) is < 0

i.e Since we cannot dynamically allocate an array just declare an array in main with 10,000 elements (careful not to exceed the size of the stack). And pass the array address to the function. #define TVEC_SIZE 100000 int main() // begin main { double timeArr[TVEC_SIZE] = {}; // define timeArr buffer to its max. all zeros int arrSize; arrSize = timeVector(timeArr, 0, .1, 1000); // timeArr assigned 10000 elements. Test this function !! Use the debugger to examine array contents or for small arrays print values to the screen.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!