Implement a function that finds the number of values that are less than 0 and the number of values greater than 0 stored in an array of integers. Assume the array is the partially filled array from the previous question, and uses 0 to indicate the end of values stored in it. (18 pts) Note: the results should be passed back to the caller, not directly displayed in the function. Also note, as the following code template requires, the function’s return type is void. Please finish the function header, and function implementation. Hint.. In the beginning, set the lessThan and greaterThan values to be 0. Then as you scan through the array elements one by one, compare the next array element with 0. If the element is greater, update your greaterThan count; otherwise, if the element is less, update the lessThan count, otherwise do nothing. Continue until you see the value 0.     GIVEN CODE:    #include using namespace std; // Find the number of values stored that is less than 0 and the number greater than // 0 in a partially filled array of int, which uses the special sentinel value 0 to // indicate the end of the array // @param a: int array // @param less: // @param greater: void findLessAndGreater (/* TODO: declare the parameters */) { //To do: implement the function ... } int main() { int a[] = { -15, 23, 32, -12, 10, 9, -43, 5, -999, 0 }; int less, greater; // ToDo: Call your function // Print the results cout << "Number of values less than 0 is " << less << endl; cout << "Number of values greater than 0 is " << greater << endl; return 0; }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Implement a function that finds the number of values that are less than 0 and the number of values greater than 0 stored in an array of integers. Assume the array is the partially filled array from the previous questionand uses 0 to indicate the end of values stored in it. (18 pts)

Note: the results should be passed back to the caller, not directly displayed in the function. Also note, as the following code template requires, the function’s return type is void.

Please finish the function header, and function implementation.

Hint.. In the beginning, set the lessThan and greaterThan values to be 0. Then as you scan through the array elements one by one, compare the next array element with 0. If the element is greater, update your greaterThan count; otherwise, if the element is less, update the lessThan count, otherwise do nothing. Continue until you see the value 0.

 

 

GIVEN CODE: 

 

#include <iostream>
using namespace std;

// Find the number of values stored that is less than 0 and the number greater than
// 0 in a partially filled array of int, which uses the special sentinel value 0 to
// indicate the end of the array
// @param a: int array
// @param less:
// @param greater:
void findLessAndGreater (/* TODO: declare the parameters */)
{
//To do: implement the function ...

}

int main()
{
int a[] = { -15, 23, 32, -12, 10, 9, -43, 5, -999, 0 };
int less, greater;

// ToDo: Call your function

// Print the results
cout << "Number of values less than 0 is " << less << endl;
cout << "Number of values greater than 0 is " << greater << endl;
return 0;
}

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education