Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please write these problems in C++ format 9. Write a test harness that tests a f

ID: 3626512 • Letter: P

Question

Please write these problems in C++ format
9. Write a test harness that tests a function named equal. This must be a complete program, including all necessary include directives and using statements.
To get all 10 points for this question, your test harness (main function) must be thorough.
This test harness must be capable of finding ALL potential errors in the logic of the equal function. If you do not include all specific test values in your actual code, then you must state (in English is fine) what values you will enter for each test. I should be able to run your program (entering the values you state, if applicable) and tell by the output if the function has a logic or runtime error.
The equal function passes in 2 parameters, both vectors of doubles, and returns true if they are equal and false otherwise. For this function, equal means the 2 vectors have the exact same values in the exact same order. This also implies that the vectors must store the exact same number of values.
You are NOT implementing the equal function. You are only writing the test harness that, will thoroughly test the equal function.
Hypothetical Rubric:
2 pts: Complete program with no major syntax errors.
1 pt: Correctly declares and initializes vector with at least 1 set of test values.
2 pts: Correctly calls function and correctly uses return value in at least 1 valid test.
5 pts: Thoroughness of test cases.

Explanation / Answer

#include<iostream>
#include<vector>
using namespace std;
bool equal(vector<double>& v1,vector<double>& v2)
{
if(v1.size()!=v2.size()) return false;
for(int i=0; i<v1.size(); i++)
if(v1[i]!=v2[i]) return false;
return true;
}
int main()
{
double a[]={4.5,6.7,8.9,0.9,7.6};
double b[]={4.5,6.7,8.9,0.9,7.6};
vector<double> v1(a,a+5);
vector<double> v2(b,b+5);
cout << equal(v1,v2)<<endl;
return 0;

}