Help Me Solving This Question
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Help Me Solving This Question

  1. #1
    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 *arrAType  *arrB);

    using namespace std;

    template <class Type>
    bool compareArrays(Type arrA,Type arrBint sizeAint 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=0i<sizeAi++)
        
    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=0j<sizeBj++)
        
    cin>>arrB[j];
    // compareArrays checks equivalent

        
    while(flag){
        if (
    sizeA!=sizeB)
        {    
    flagfalse;
        break;
        }

        else{
        
        for (
    int q=0q<sizeAq++)
            if(
    arrA[q]!=arrB[q]){
        
    flag=false;
        break;}
        

            return 
    flag;
        }

        
        }



    }

    int main(){
    int sAsB;

    compareArrays<int>(,bsA,  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. #2
    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. #3
    Join Date
    Jun 2009
    Location
    France
    Posts
    2,290

    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.
    Is your question related to IO?
    Read this C++ FAQ LITE article at parashift by Marshall Cline. In particular points 1-6.
    It will explain how to correctly deal with IO, how to validate input, and why you shouldn't count on "while(!in.eof())". And it always makes for excellent reading.

  4. #4
    Join Date
    Feb 2002
    Posts
    4,640

    Re: Help Me Solving This Question

    Quote Originally Posted by Amleto View Post
    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
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center