Question

Write a number of C++ functions, and a test driver ( harness ) to test them...

Write a number of C++ functions, and a test driver ( harness ) to test them with.

Functions:

 double radians( double degrees )

 double xCosXySinY( double x, double y )

 int linspace( double data[ ], double dataMin, double delta, int nPoints )

-----Fills data[ ] with nPoints values, starting at dataMin and increasing in steps of delta.

-----Returns the number of array spots filled, ( normally nPoints ), or -1 in the case of errors ( bad input. )

 int linspace( double data[ ], double dataMin, double delta, double dataMax )

-----Fills data[ ] with values, ranging from dataMin to dataMax in steps of delta

-----Returns the number of array spots filled, ( calculated ), or -1 in the case of errors ( bad input. )

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <iostream>
#include <cmath>

using namespace std;

double radians(double degrees){
   double pi = 2 * asin(1);
   return degrees * pi / 180;
}

double xCosXySinY(double x, double y){
   return (x * sin(radians(x))) + (y * sin(radians(x)));
}

int linspace(double data[], double dataMin, double delta, int nPoints){
   try{
       double val = dataMin;
       for(int i = 0; i < nPoints; ++i){
           data[i] = val;
           val += delta;
       }
       return nPoints;
   }
   catch(int e){
       return -1;
   }
}

int linspace(double data[], double dataMin, double delta, double dataMax){
   try{
       double val = dataMin;
       int count = 0;
       for(double val = dataMin; val <= dataMax; val += delta){
           data[count++] = val;
       }
       return count;
   }
   catch(int e){
       return -1;
   }
}

void printArr(double arr[], int count){
   for(int i = 0; i < count; ++i){
       cout << arr[i] << " ";
   }
   cout << endl;
}

int main(){
   double arr[10], arr1[100];
   linspace(arr, 0, 0.5, 10);
   printArr(arr, 10);
   int count = linspace(arr1, 0, 0.5, 7.5);
   printArr(arr1, count);
   return 0;
}

Add a comment
Know the answer?
Add Answer to:
Write a number of C++ functions, and a test driver ( harness ) to test them...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In C Write a couple of functions to process arrays. Note that from the description of...

    In C Write a couple of functions to process arrays. Note that from the description of the function you have to identify what would be the return type and what would be part of the parameter. display(): The function takes an int array and it’s size and prints the data in the array. sumArray(): It takes an int array and size, and returns the sum of the elements of the array. findMax(): It takes an int array and size, and...

  • c++ Write the following 2 functions and test them. Both of them need to be recursive...

    c++ Write the following 2 functions and test them. Both of them need to be recursive functions. int sum(int n); // recursive version to calculate the sum of 1 + 2 + ..... + n int str_length(char s[]; // Returns length of the string s[] and the null character, '0\', is not counted in the length). Example of program execution; Enter a positive integer: 10 (user input) The sum of 1+ 2+....+10 is: 55 Enter a sentence: Hello World! (user...

  • Do the following: - Write and test a function that takes an array of doubles and...

    Do the following: - Write and test a function that takes an array of doubles and returns the average of the values in the array - Write and test a function that takes an array of doubles and returns number of values in the array that are above the average of the values in the array - Write and test a function that takes an array of Strings and returns number of values in the array that start with an...

  • A test harness program for testing sorting methods is provided with the rest of the textbook...

    A test harness program for testing sorting methods is provided with the rest of the textbook program files. It is the file Sorts.java in the ch11 package. The program includes a swap method that is used by all the sorting methods to swap array elements. Describe an approach to modifying the program so that after calling a sorting method the program prints out the number of swaps needed by the sorting method. Implement your approach. Test your new program by...

  • Write a program that instantiates an array of integers named scores. Let the size of the...

    Write a program that instantiates an array of integers named scores. Let the size of the array be 10. The program then first invokes randomFill to fill the scores array with random numbers in the range of 0 -100. Once the array is filled with data, methods below are called such that the output resembles the expected output given. The program keeps prompting the user to see if they want to evaluate a new set of random data. Find below...

  • I need a c++ code please. 32. Program. Write a program that creates an integer constant...

    I need a c++ code please. 32. Program. Write a program that creates an integer constant called SIZE and initialize to the size of the array you will be creating. Use this constant throughout your functions you will implement for the next parts and your main program. Also, in your main program create an integer array called numbers and initialize it with the following values (Please see demo program below): 68, 100, 43, 58, 76, 72, 46, 55, 92, 94,...

  • Write a program that dynamically allocates an array in the freestore large enough to hold a...

    Write a program that dynamically allocates an array in the freestore large enough to hold a user defined number of test scores as doubles. Once all the scores are entered, the array should be passed to a function that finds the highest score. Another function the array should be passed to a function that finds the lowest score. Another function should be called that calculates the average score. The program should show the highest, lowest and average scores. Must use...

  • Write a program that dynamically allocates an array in the freestore large enough to hold a...

    Write a program that dynamically allocates an array in the freestore large enough to hold a user defined number of test scores as doubles. Once all the scores are entered, the array should be passed to a function that finds the highest score. Another function the array should be passed to a function that finds the lowest score. Another function should be called that calculates the average score. The program should show the highest, lowest and average scores. Must use...

  • PLEASE HELP!!! C PROGRAMMING CODE!!! Please solve these functions using the prototypes provided. At the end...

    PLEASE HELP!!! C PROGRAMMING CODE!!! Please solve these functions using the prototypes provided. At the end please include a main function that tests the functions that will go into a separate driver file. Prototypes int R_get_int (void); int R_pow void R Jarvis int start); void R_fill_array(int arrayll, int len); void R_prt_array (int arrayl, int len) void R-copy-back (int from[], int to [], int len); int R_count_num (int num, int arrayll, int len) (int base, int ex) 3. Build and run...

  • Write a driver C++ program that will test the following functions in the same order they...

    Write a driver C++ program that will test the following functions in the same order they are written next. You can test your program by reading the following values: n1= 10 and n2= 20 from the user: The main program sends the values of the variables n1 and n2 to the function. The function calculates the average and sends it back to main program through the parameter list as call by reference parameter and will not use the return statement.

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT