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
  • #include <iostream>#include <string>using namespace std;// Implement printArray here// Implement deleteSmallest here//...

    #include#includeusing namespace std;// Implement printArray here// Implement deleteSmallest here// DO NOT CHANGE MAIN FUNCTION BELOWint main() {int myarray[100];cout << "Enter number of integers : ";int n;cin >> n;cout << "Enter " << n << " integers" << endl;for (int i = 0; i < n; i++)cin >> myarray[i];cout << "Contents of array : ";printArray(myarray, n);deleteSmallest(myarray, n);cout << "Contents of array after deleteSmallest: ";printArray(myarray, n-1);}

  • //Find two smallest integers #include <iostream> #include <string> using namespace std; // implement printArray here //...

    //Find two smallest integers #include <iostream> #include <string> using namespace std; // implement printArray here // implement findTwoSmallest here // DO NOT WRITE ANY CODE BELOW THIS LINE (EXCEPT FOR TESTING - REMOVE BEFORE SUBMITTING) int main() {     int n;     int arr[100];        cout << "Enter number of integers: ";     cin >> n;        cout << "Enter " << n << " integers: ";       for(int i = 0; i < n; i++) {        ...

  • int myarray[100]; cout << "Enter number of integers : "; int n; cin >> n; cout...

    int myarray[100]; cout << "Enter number of integers : "; int n; cin >> n; cout << "Enter " << n << " integers" << endl; for (int i = 0; i < n; i++)   cin >> myarray[i]; cout << "Contents of array : "; printArray(myarray, n);

  • #include <iostream> using namespace std; int main(void) {    int SIZE;    cout<<"Enter the size of the...

    #include <iostream> using namespace std; int main(void) {    int SIZE;    cout<<"Enter the size of the array"<<endl;    cin>>SIZE;     int *numlist = new int[SIZE];     // Read SIZE integers from the keyboard     for (int i = 0; i<SIZE; i++ )    {        cout << "Enter value #" << i+1 << ": ";        cin >> numlist[i];     }     // Display the numbers in a reverse order     for (int i = SIZE; i > 0; i--...

  • #include <iostream> #include <cstddef> using std::cout; using std::endl; class Node { int value; public: Node* left;...

    #include <iostream> #include <cstddef> using std::cout; using std::endl; class Node { int value; public: Node* left; // left child Node* right; // right child Node* p; // parent Node(int data) { value = data; left = NULL; right = NULL; p = NULL; } ~Node() { } int d() { return value; } void print() { std::cout << value << std::endl; } }; int main(int argc, const char * argv[]) { } function insert(Node *insert_node, Node *tree_root){ //Your code here...

  • #include <iostream> #include <cstring> #include <string> #include <istream> using namespace std; //Function prototypes int numVowels(char *str);...

    #include <iostream> #include <cstring> #include <string> #include <istream> using namespace std; //Function prototypes int numVowels(char *str); int numConsonants(char *str); int main() {    char string[100];    char inputChoice, choice[2];    int vowelTotal, consonantTotal;    //Input a string    cout << "Enter a string: " << endl;    cin.getline(string, 100);       do    {        //Displays the Menu        cout << "   (A) Count the number of vowels in the string"<<endl;        cout << "   (B) Count...

  • 1 #include <string> 2 #include <iostream> 3 using std::string; 4 using std::cout; 5 using std::endl; 7...

    1 #include <string> 2 #include <iostream> 3 using std::string; 4 using std::cout; 5 using std::endl; 7 class Pet 8 { 9   public: 10       string name; 11       virtual void print( ) const; 12}; 13 14 class Dog:public Pet 15 { 16   public: 17       string breed; 18       virtual void print( ) const; 19}; 20 21 int main( ) 22 { 23   Dog vdog; 24   Pet vpet; 25   vdog.name = "Tiny"; 26   vdog.breed = "Great Dane"; 27   vpet =...

  • #include using namespace std; void test(); int x = 0; int main(){ cout << x <<...

    #include using namespace std; void test(); int x = 0; int main(){ cout << x << endl; test(); cout << x << endl; } void test(){ int x = 100; cout << x << endl; for(int x = 0; x < 5; x++){ cout << x << endl; } } how many separate variables named ‘x’ are created?

  • #include <iostream> using namespace std; template <typename Item> class MyArray{ private:    Item *myarray;    int...

    #include <iostream> using namespace std; template <typename Item> class MyArray{ private:    Item *myarray;    int size;    int used;    void doubleSize(); public:    MyArray();    ~MyArray();    int length();    void insertHead(Item i);    void insertTail(Item i);    void deleteHead();    void deleteTail();    void sortAscending();    void sortDescending();    Item operator [](int i){        return myarray[i];    } }; template <typename Item> MyArray<Item>::MyArray(){    size = 5;    used = 0;    myarray = new Item[size];...

  • #include <iostream> using namespace std; const int SIZE = 10; void displayGreaterThan(int[], int); void displaySmallerThan(int[],int); void...

    #include <iostream> using namespace std; const int SIZE = 10; void displayGreaterThan(int[], int); void displaySmallerThan(int[],int); void displayArrayContent(int[]); void displayLargestValue(int[]); void displaySmallestValue(int[]); int main(){    int number;    int numbers[SIZE] = {9,1,90,98,53,22,76,29,37,65}; cout <<"Enter a number: "; cin >> number; cout << endl;    displayGreaterThan(numbers,number); cout << endl; displaySmallerThan(numbers,number); cout << endl; displayArrayContent(numbers); cout << endl; displayLargestValue(numbers); cout << endl; displaySmallestValue(numbers); cout << endl;    return 0;       } void displayGreaterThan(int value[],int num){ cout << " All larger value(s)than" <<...

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