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

//how do i fix this? im gettint these errors. bool sameSet(const int *aBeg, cons

ID: 3601554 • Letter: #

Question

//how do i fix this? im gettint these errors.

bool sameSet(const int *aBeg, const int *aEnd,
const int *bBeg, const int *bEnd)
{
// Add your code yere
for (auto p = aBeg; p!= aEnd; p++)
{
bool a = false;
for (auto p2 = bBeg; p2 != bEnd; p2++)
{
if(*p2 == *p)
{
a = true;
break;
}
else
{
return false;
}
}
}


for (auto q = bBeg; q != bEnd; q++)
{
bool b = false;
for (auto q2 = aBeg; q2 != aEnd; q2++)
{
if(*q2 == *q)
{
b = true;
break;
}

}
}
return true;
}

Checking function: sameSet +For input of ARRAY (111}), ARRAY (111, 11, 11)) X For input of ARRAY (1, 4, 9, 16, 9, 7, 4, 9, 11}), ARRAY (111, 11, 7, 9, 16, 4, 1)) should be true, but is false. +For input of ARRAY (1, 4, 1}), ARRAY (11, 11, 7, 9, 16, 4, 1}) +For input of ARRAY (1, 1, 11}), ARRAY (111, 11, 7}) +For input of ARRAY (1, 4, 9, 16), ARRAY (19, 4, 1,}) +For input of ARRAY (111, 11}), ARRAY (11)) +For input of ARRAY (1, 4, 9, 16), ARRAY (19, 4, 1,}) X For input of ARRAY (111, 11, 550, 650}), ARRAY (f11, 550, 550, 650, 550) should be true, but is false. X For input of ARRAY (111, 11, 11, 11, 2), ARRAY (12,2,2,11}) should be true, but is false. +For input of ARRAY (1, 4, 91), ARRAY (9, 4, 1,16)) Tests passing 7/10 (70%).

Explanation / Answer

#include <stdio.h>

//bool sameSet(const int *aBeg, const int *aEnd, const int *arrayB, const int *bEnd);

//aSize is the size of arrayA

//bSize is the size of arrayB

bool sameSet(const int *arrayA,const int aSize, const int *arrayB, const int bSize);

int main(void) {

int a[] = {1,4,1};

int b[] = {11,11,7,9,16,4,1};

int aSize = sizeof(a)/sizeof(a[0]);

int bSize = sizeof(b)/sizeof(b[0]);

bool stat = sameSet(a,aSize,b,bSize);

printf("%d",stat);

return 0;

}

//Logic :

//We want first take Array A, and compare with Array B if its a subset of Array B. We store the result in Boolean aFinal as true or false.

//Then we take Array B, and compare with Array A if its a subset of Array A. We then again store the result in Boolean bFinal as true or false.

//We take the OR of aFinal and bFinal. Since Array A might be a subset of B or Array B might be a subset of B or both. And store the result in Boolean final, //and return final

bool sameSet(const int *arrayA, const int aSize,const int *arrayB, const int bSize){

// Add your code yere

auto p = arrayA;

bool final = false;

bool aFinal = true;

bool bFinal = true;

for (int i = 0; i < aSize; i++)

{

bool a = false;

auto p2 = arrayB;

for (int j = 0; j < bSize; j++)

{

if(*p2 == *p)

{

a = true;

break;

}

p2++;

}

if(a == false){

aFinal = false;

break;

}

p++;

}

auto q = arrayB;

for (int i = 0; i < bSize; i++)

{

bool b = false;

auto q2 = arrayA;

for (int j = 0; j < aSize; j++)

{

if(*q2 == *q)

{

b = true;

break;

}

q2++;

}

if(b == false){

bFinal = false;

break;

}

q++;

}

final = aFinal | bFinal;

return final;

}