Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

//This program demonstrates several types of recursive functions you are to finish getsum,getproduct, countpositive,getmin,getmax... etc to be able to test it in main. dont touch

//This program demonstrates several types of recursive functions

you are to finish getsum,getproduct, countpositive,getmin,getmax... etc to be able to test it in main. dont touch main unless you were to test it only

say its already in main called countpositive so you were to call count positive to see if it actually works or not, whatever is in the parameters of the getsum,product etc... dont touch, only touch what is inside of them that is my work

#include

#include

#include

using namespace std;

/*

Routine that prints contents of array of strings

*/

void printarray(int array[], int count) {

int i;

for (i = 0; i < count-1; i++) {

cout << array[i] << ", ";

}

cout << array[i];

cout << endl;

}

int countPositive(int *array, int length) {

if(length==0)

return 0;

if(*array>0)

return 1+ countPositive(array+1,length-1);

else

return 0+ countPositive(array+1,length-1);

}

int countRange(int *array, int length) {

if(length==0)

return 0;

if(*array <10)&&(*array > 50)

return 1+ countRange(array+1, length-1)

else

return 0+countRange(array+1, length-1)

}

int getMaximum_v2(int *array, int length) {

if (length==0)

return 0;

if(*array > *array+length)

return 1+getMaximum_v2(array+1,length-1);

else

return 0+getMaximum_v2(array+1, length-1);

}

int getMinimum_v2(int *array, int length) {

if(length == 0)

return 0;

if(*array < *array+length)

return 1-getMaximum_v2(array+1,length-1);

else

return 0-getMaximum_v2(array+1, length-1);

}

int getSum(int *array, int length) {

if(length <=0)

return 0;

return getSum(array,length-1)+ *array( length-1);

}

int getProduct(int *array, int length) {

if(length <= 0)

return 0;

return getProduct(array,length-1)* *array(length-1);

}

#define SIZE_OF_ARRAY 12

int main()

{

int test_array[SIZE_OF_ARRAY] = { 5,1,-1,1,24,1,-1,1,1,1,-10,29 };

int prod_array[SIZE_OF_ARRAY] = { 5,1,-1,1,20,1,1,1,1,1,-1,10 };

// print opening meessage

cout << endl << "Array to be used contains:" << endl;

printarray(test_array, SIZE_OF_ARRAY);

cout << "Result of countPositive: " << countPositive(test_array,SIZE_OF_ARRAY) << endl;

system("pause");

}

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_2

Step: 3

blur-text-image_3

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

Joe Celkos Data And Databases Concepts In Practice

Authors: Joe Celko

1st Edition

1558604324, 978-1558604322

More Books

Students also viewed these Databases questions

Question

=+ Is the source or sponsor of the information indicated?

Answered: 1 week ago

Question

Working with other project stakeholders for support.

Answered: 1 week ago

Question

Knowledge of project management (PMI) teachings

Answered: 1 week ago