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

Please help with the following problem using Visual Studio using namespace std a

ID: 3860135 • Letter: P

Question

Please help with the following problem using Visual Studio using namespace std as i am not familiar with any other compilers. Thank you.

Write a function bool equals(int a[], int a_size, int b[], int b_size) that checks whether two arrays have the same elements in the same order.

Please prompt the user for two arrays that are identical and your program produces the message claiming, “Both arrays are the same”. Please print the content of these two arrays first and a message follows.

Please prompt the user for two arrays that are different and your program produces the message claiming, “Two arrays are different”.

Please print the content of these two arrays first and a message follows. Each array should contain at least 10 elements.

Explanation / Answer

#include <iostream>
using namespace std;
bool equals(int a[], int a_size, int b[], int b_size) {
if(a_size != b_size) {
return false;
} else {
for(int i=0;i < b_size; i++) {
if(a[i] != b[i]) {
return false;
}
}
return true;
}
}
int main()
{
int a[10], b[10];
cout<<"Enter two arrays that are identical: "<<endl;
cout<<"Enter the first array: "<<endl;
for(int i=0; i<10; i++) {
cin >> a[i];
}
cout<<"Enter the second array: "<<endl;
for(int i=0; i<10; i++) {
cin >> b[i];
}
bool status = equals(a,10,b,10);
if(status) {
cout<<"Both arrays are the same"<<endl;
} else {
cout<<"Two arrays are different"<<endl;
}
  
cout<<"Enter two arrays that are different: "<<endl;
cout<<"Enter the first array: "<<endl;
for(int i=0; i<10; i++) {
cin >> a[i];
}
cout<<"Enter the second array: "<<endl;
for(int i=0; i<10; i++) {
cin >> b[i];
}
status = equals(a,10,b,10);
if(status) {
cout<<"Both arrays are the same"<<endl;
} else {
cout<<"Two arrays are different"<<endl;
}
return 0;
}

Output:

sh-4.2$ g++ -o main *.cpp                                                                                                                                                                             

sh-4.2$ main                                                                                                                                                                                          

Enter two arrays that are identical:                                                                                                                                                                  

Enter the first array:                                                                                                                                                                                

1 2 3 4 5 6 7 8 9 10                                                                                                                                                                                  

Enter the second array:                                                                                                                                                                               

1 2 3 4 5 6 7 8 9 10                                                                                                                                                                                  

Both arrays are the same                                                                                                                                                                              

Enter two arrays that are different:                                                                                                                                                                  

Enter the first array:                                                                                                                                                                                

1 2 3 4 5 6 7 8 9 10                                                                                                                                                                                  

Enter the second array:                                                                                                                                                                               

1 2 3 4 5 8 7 6 10 9                                                                                                                                                                                  

Two arrays are different