Question

Create a function NumEven( std: forward_list-int> SList) that computes and returns the number of even values in a singly link[ Select] for (int i; i < num; i++) { if (n / 2 == 0) num-- ; } return num; unsigned num = 0; for (auto n: SList) { if (n % 2

All in C++

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

SOLUTION:

As the function needs to return unsigned number so declare unsigned num = 0;
Now we need to iterate through list and check the number is divisible by 2 using mod increment num for (auto n: SList ){ if (n % 2 == 0) num++; }
Now return num;

Remaining are wrong statements.

I have provided the code and output for a clear view.

The 3 statements to be filled are :

unsigned num = 0;

for (auto n: SList ){ if (n % 2 == 0) num++; }

return num;

CODE ATTACHMENTS:

5 6 7 8 9 10 11 12 13 14 15 16 17 #include<iostream> #include<forward_list> unsigned NumEven(std::forward_list<int> Slist) {

Please do comment for any queries.
Please like it.
Thank you.

Add a comment
Know the answer?
Add Answer to:
All in C++ Create a function NumEven( std: forward_list-int> SList) that computes and returns the number...
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
  • What is the output of the following C++ code? int count = 1; int num =...

    What is the output of the following C++ code? int count = 1; int num = 25; while (count < 25) { num--; count++; } cout << count « " " « num << endl i 25 1 0 24 1 0 25 0 0 24 0 In this while loop statement, while (counter < 10), where counter is an int variable. Which statement below is an equivalent way to write this while statement? while (10 < counter) while (9...

  • 1) Fix the Function #include <iostream> void print Num() { std::cout << number; }; int main()...

    1) Fix the Function #include <iostream> void print Num() { std::cout << number; }; int main() { int number = 35; printNum (number); return 0; (Give two ways to fix this code. Indicate which is preferable and why.) #include <iostream> void double Number (int num) {num = num * 2;} int main() { int num = 35; double Number (num); std::cout << num; // Should print 70 return 0; (Changing the return type of doubleNumber is not a valid solution.)

  • Convert the below code into if else selection: #include <iostream> using namespace std; int main() {...

    Convert the below code into if else selection: #include <iostream> using namespace std; int main() { int num; sin. >> num; switch (num) { case 1: cout << "Casel: Value is: << num << endl; break; case 2: break; case 3: cout << "Case3: Value is: " << num << endl; break; default: cout << "Default: Value is: << num << endl; break; } return; }

  • QUESTION 26 Given the following function: int secret(int num, int m) inti, prod=1; if (m=0) return...

    QUESTION 26 Given the following function: int secret(int num, int m) inti, prod=1; if (m=0) return 1: - for (i=0; i<m; i++) { prod = prod * num; } return prod; What is the output for this function call? cout << secret(10,6);

  • (a) Consider the following C++ function: 1 int g(int n) { 2 if (n == 0)...

    (a) Consider the following C++ function: 1 int g(int n) { 2 if (n == 0) return 0; 3 return (n-1 + g(n-1)); 4} (b) Consider the following C++ function: 1 bool Function (const vector <int >& a) { 2 for (int i = 0; i < a. size ()-1; i ++) { 3 for (int j = i +1; j < a. size (); j ++) { 4 if (a[i] == a[j]) return false; 5 6 } 7 return...

  • 1 #include<iostream> 2 using namespace std; int main() int number; 7 cout < "Enter a number...

    1 #include<iostream> 2 using namespace std; int main() int number; 7 cout < "Enter a number to p cin number; cout << "start:" rint the square numbers in reverse order from numb 10 ut << 1. N was: number return e; 12 13

  • What is the time and space complexity of this code with explanation? public static int getv(int...

    What is the time and space complexity of this code with explanation? public static int getv(int num, List<Integer> rating, int target) { int count 0; HashMap<Integer, Integer> map = new HashMap<>(); for(int i = 0; i < num; i++){ if(!map.containsKey(rating.get(i))){ map.put(rating.-get(i), 0); } map.put(rating.get(i), map.get(rating.get(i))+1); } for(int i = 0; i < num; i++){ if(map.get(target -rating.get(i)) != null){ count += map.get(target-rating.get(i)); } if(target-rating.get(i) == rating.get(i)){ count--; } return count/2; }

  • c++ #include using namespace std; int main() {    int n, x, num, j = 0;...

    c++ #include using namespace std; int main() {    int n, x, num, j = 0;    cin >> n >> x;    int*arr = new int[n];    for (int i = 0; i < n; i++)    {        cin >> num;        if (num < x)        {            arr[j] = num;            j++;        }    }    for (int i = 0; i < j; i++)    {...

  • in c++ #include <iostream> using namespace std; int main() int beta[7] = 3, 5); for (int...

    in c++ #include <iostream> using namespace std; int main() int beta[7] = 3, 5); for (int i = 2; i < 7; i++) beta[i] = 3 * i + 2; beta[i - 1] = beta[i - 1] + beta[i]; beta[i - 2) = betali - 2] + beta (i - 1]; for (int i = 0; i < 7; i++) cout << beta[i] << " "; cout << endl; return 0;

  • Write following program using Switch statement. #include <iostream> using namespace std; int main() int number; cout...

    Write following program using Switch statement. #include <iostream> using namespace std; int main() int number; cout << "Enter an integer cin >> number; if (number > B) cout << You entered a positive integer: " << number << endl; else if (number (8) cout<<"You entered a negative integer: " << number << endl; cout << "You entered e." << endl; cout << "This line is always printed." return 0;

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