CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com

# Thread: Help Me Solving This Question

1. Member
Join Date
Jul 2010
Posts
75

## Help Me Solving This Question

hello
our doctor give as in assignment , i already try to solve it but i got some errors...

==========

Write a function named compareArrays that takes 4 parameters, two arrays of any type

(arrA[] and arrB[]) , and two integers sizeA and sizeB, being the number of elements in the two arrays respectively. The function should return boolean value which is true if the arrays are of the same size and all the corresponding elements in both arrays arrA and arrB are equal. Otherwise, it will return false. (i.e. return false if sizeA is different from sizeB or if any element of arrA is different from the corresponding element of arrB). Test the functions by writing a C++ program.

==========
PHP Code:
``` #include <iostream> template <class Type> bool compareArrays(Type *arrA, Type  *arrB); using namespace std; template <class Type> bool compareArrays(Type arrA,Type arrB, int sizeA, int sizeB){ bool flag=true; // arrayA     cout<<"Enter the number of element in arrayA:";     cin>>sizeA;     arrA= new Type[sizeA];     cout<<"Enter the elements of arrayA:";     for ( int i=0; i<sizeA; i++)     cin>>arrA[i]; // arrayB          cout<<"Enter the number of element in arrayB:";     cin>>sizeB;     arrB= new Type[sizeB];     cout<<"Enter the elements of arrayB:";     for ( int j=0; j<sizeB; j++)     cin>>arrB[j]; // compareArrays checks equivalent     while(flag){     if (sizeA!=sizeB)     {    flag= false;     break;     }     else{          for (int q=0; q<sizeA; q++)         if(arrA[q]!=arrB[q]){     flag=false;     break;}              return flag;     }          } } int main(){ int sA, sB; compareArrays<int>(a ,b, sA,  sB); return 0; }  ```
the errors

Error 1 error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup MSVCRTD.lib Assigment7

Error 2 fatal error LNK1120: 1 unresolved externals C:\Users\user\Desktop\Assigment7\Debug\Assigment7.exe Assigment7

2. Member +
Join Date
Apr 2008
Posts
726

## Re: Help Me Solving This Question

looks like you have your project setup wrongly in msvc ie, it looks like win32 rather than empty/console app.

3. ## Re: Help Me Solving This Question

Your code is wrong on many many levels. As already mentioned, you have project configuration problems, but also algorithm problems, and finally, just downright logic problems.

Forget input from user, and do things 1 at a time. Start by writing your compare function only.

Here is a "fill in the gap" file:

Code:
```#include <iostream>

template <typename T>
bool compareArrays(T arrA, int sizeA, T arrB, int sizeB)
{
//please fill me
}

int main()
{
//fancy output
std::cout.setf(std::ios_base::boolalpha);

//first test //false
{
int A[] = {1, 2, 3, 4};
int ASize = 4;
int B[] = {4, 3, 2};
int BSize = 3;
bool result = compareArrays(A, ASize, B, BSize);
std::cout << "Test1 result: " << result << std::endl;
}

//second test //false
{
int A[] = {1, 2, 3, 4};
int ASize = 4;
int B[] = {1, 2, 3, 5};
int BSize = 4;
bool result = compareArrays(A, ASize, B, BSize);
std::cout << "Test2 result: " << result << std::endl;
}

//third test //true
{
int A[] = {1, 2, 3, 4};
int ASize = 4;
int B[] = {1, 2, 3, 4};
int BSize = 4;
bool result = compareArrays(A, ASize, B, BSize);
std::cout << "Test3 result: " << result << std::endl;
}

//fourth test //false
{
int A[] = {1, 2, 3, 4};
int ASize = 4;
int B[] = {1, 2, 3, 4, 5};
int BSize = 5;
bool result = compareArrays(A, ASize, B, BSize);
std::cout << "Test4 result: " << result << std::endl;
}

return 0;
}```
The correct answer should be "false, false, true, false". Get that to work, it is the first step.

4. ## Re: Help Me Solving This Question

Originally Posted by Amleto
looks like you have your project setup wrongly in msvc ie, it looks like win32 rather than empty/console app.
Actually, it looks like it is setup for a console app. The issue is that if this is the entire code, there is no 'main' function.

Viggy

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)

×
We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.