CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2008
    Posts
    24

    Code comparation

    Hi all,
    i need to find a way to compare c# codes. In other words, i will have a coding question requiring the user to write some code and solution code for the question. Then i will get input code from the user according to that question and compare these two results. For example i will have a question like : "Write some code that calculates the sum of the numbers between 1 and 10." and solution of the question will be like:

    Code:
    int sum=0;
    for(int i=1; i<=10; i++)
    {
          sum+=i;
    }
    After i get the user input i will compare the user's answer and my solution and user will get or lose points. But i need some suggestions for solving that problem. First, i mustn't compare codes as plain text because user may provide a different answer than my solution which is correct too. For example, users may write "int count=0;" instead of "int sum=0;" and they lose points eventhough their answers are correct. So i need a better technique to manage that. Actually what i need is to make the user's answer and my solution comparable by converting the codes to something unique. Please help me about that.
    Any help would be greatly appreciated.

  2. #2
    Join Date
    Apr 2006
    Posts
    220

    Re: Code comparation

    In programming competitions, the user's solution is verified against some random inputs.. and the output is checked.

  3. #3
    Join Date
    Mar 2004
    Location
    Prague, Czech Republic, EU
    Posts
    1,701

    Re: Code comparation

    You can process it with CSharpCodeProvider and than inspect the compiled assembly using reflection and compare the result with the expected one. Maybe visitor design pattern could be handy here.
    • Make it run.
    • Make it right.
    • Make it fast.

    Don't hesitate to rate my post.

  4. #4
    Join Date
    Mar 2008
    Posts
    24

    Re: Code comparation

    Thanks for replying.. Comparing the compiled assembly and checking the output by using random inputs may work in some situations but if i have more complex questions (eg. writing classes) is it possible to find out a better solution??

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

Featured