Question

#include <iostream> #include <string> using std::string; using std::cout; using std::endl; void testAnswer(string testname, int answer, int...

#include <iostream>
#include <string>

using std::string;
using std::cout;
using std::endl;

void testAnswer(string testname, int answer, int expected) {
if (answer == expected)
cout << "PASSED: " << testname << " expected and returned " << answer << "\n";
else
cout << "FAILED: " << testname << " returned " << answer << " but expected " << expected << "\n";
}

// Implement printArray here
void printArray(int array[],int b)
{
for(int i = 0; i<b;i++)
{
std::cout<< array[i] << " " <<std::endl;
}
}
int countArray(myarray[],int boo,int bla){
//idk how to do countarray
// Implement countArray here


// EDIT CODE BELOW ONLY FOR TESTING (YOUR CODE WILL BE GRADED WITH DIFFERENT TESTS)

int main() {
cout << "count elements larger than a given number\n";
{
int myarray[] = {92, 45, 23, 45, 10};
cout << "Contents of array : ";
printArray(myarray, 5);
testAnswer("countArray(myarray, 5, 40)", countArray(myarray, 5, 40), 3);
testAnswer("countArray(myarray, 5, 100)", countArray(myarray, 5, 100), 0);
testAnswer("countArray(myarray, 5, 90)", countArray(myarray, 5, 90), 1);
}
{
int myarray[] = {92, 45, 23, 45};
cout << "Contents of array : ";
printArray(myarray, 4);
testAnswer("countArray(myarray, 4, 100)", countArray(myarray, 4, 100), 0);
testAnswer("countArray(myarray, 4, 40)", countArray(myarray, 4, 40), 3);
}
{
int myarray[] = {0};
cout << "Contents of array : ";
printArray(myarray, 0);
testAnswer("countArray(myarray, 0, 10)", countArray(myarray, 0, 10), 0);
}
//   system("pause"); // comment/uncomment if needed

return 0;
}

i just neeed someone to solve the count array please asap i have one hour

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

PROGRAM:

#include <iostream>

#include <string>

using std::string;
using std::cout;
using std::endl;

void testAnswer(string testname, int answer, int expected)
{
if (answer == expected)
cout << "PASSED: " << testname << " expected and returned " << answer << "\n";
else
cout << "FAILED: " << testname << " returned " << answer << " but expected " << expected << "\n";
}

// Implement printArray here
void printArray(int array[],int b)
{
for(int i = 0; i<b;i++)
{
std::cout<< array[i] << " " <<std::endl;
}
}

int countArray(int myarray[],int boo,int number)
{
int count=0; // Count variable
for(int i=0;i<boo;i++) // for loop to iterate through the entire array
{
if(myarray[i]>number) // if array value is greater than the given number
count++; // increment count variable by 1
}
return count; // return count value
}

// EDIT CODE BELOW ONLY FOR TESTING (YOUR CODE WILL BE GRADED WITH DIFFERENT TESTS)

int main()
{
cout << "count elements larger than a given number\n";
{
int myarray[] = {92, 45, 23, 45, 10};
cout << "Contents of array : \n";
printArray(myarray, 5);
testAnswer("countArray(myarray, 5, 40)", countArray(myarray, 5, 40), 3);
testAnswer("countArray(myarray, 5, 100)", countArray(myarray, 5, 100), 0);
testAnswer("countArray(myarray, 5, 90)", countArray(myarray, 5, 90), 1);
}
{
int myarray[] = {92, 45, 23, 45};
cout << "Contents of array : ";
printArray(myarray, 4);
testAnswer("countArray(myarray, 4, 100)", countArray(myarray, 4, 100), 0);
testAnswer("countArray(myarray, 4, 40)", countArray(myarray, 4, 40), 3);
}
{
int myarray[] = {0};
cout << "Contents of array : \n";
printArray(myarray, 1);
testAnswer("countArray(myarray, 0, 10)", countArray(myarray, 1, 10), 0);
}
// system("pause"); // comment/uncomment if needed

return 0;
}

Please refer to the following screenshot of the program for indentation of the code:

OUTPUT:

Add a comment
Know the answer?
Add Answer to:
#include <iostream> #include <string> using std::string; using std::cout; using std::endl; void testAnswer(string testname, int answer, int...
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
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