Which sentence is correct about the code below?#include <iostream>#include <algorithm>#include <vector>using namespace s

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

Which sentence is correct about the code below?#include <iostream>#include <algorithm>#include <vector>using namespace s

Post by answerhappygod »

Which sentence is correct about the code below?#include <iostream>#include <algorithm>#include <vector>using namespace std;class A {int a;public:A(int a) : a(a) {}int getA() const { return a; }void setA(int a) { this?>a = a; }/* Insert Code Here */};struct add10 { void operator()(A & a) { a.setA(a.getA() + 10); } }; int main() { int t[] = { 10, 5, 9, 6, 2, 4, 7, 8, 3, 1 }; vector<A> v1(t, t + 10); for_each(v1.begin(), v1.end(), add10()); vector<A>::iterator it = find(v1.begin(), v1.end(), A(7)); cout << it?>getA() << endl; return 0;}

A. it will compile and print 7
B. it will not compile
C. it will compile but the program result is unpredictable
D. adding code: bool operator !=(const A & b) const { if (this?>a != b.a) { return true; } return false; } at Place 1 will allow the program to compile
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!

This topic has 1 reply

You must be a registered member and logged in to view the replies in this topic.


Register Login
 
Post Reply