Question: Please help! C++ problem! Choose the best solution (Analyze ALL the possible answers before choosing): Write a bool function, areSame, to accept two vectors of

Please help! C++ problem!

Choose the best solution (Analyze ALL the possible answers before choosing):

Write a bool function, areSame, to accept two vectors of ints and return true if the two vectors contain the same values in every cell. The vectors are the same size. Efficiency counts!

a)

bool areSame(const vector &V1, const vector &V2) { bool OK = true; int i=0; for(int i=0; i < V1.size());i++) { if(V1[i] != V2[i]) OK = false; } return OK; }

b)bool areSame(const vector &V1, const vector &V2) { bool OK = false; int i=0; while(OK && i < V1.size()) { if(V1[i] == V2[i]) i++; else OK = true; } return OK; }

c)bool areSame(const vector &V1, const vector &V2) { bool OK = true; int i=0; while(OK && i < V1.size()) { if(V1[i] == V2[i]) i++; else OK = false; } return OK; }

d)bool areSame(const vector &V1, const vector &V2) { bool OK; int i=0; for(int i=0; i < V1.size());i++) { if(V1[i] != V2[i]) OK = false; } else OK = false; return OK; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!