Login to TechLifeForum X
Board Index Go to Reboot.Pro
  • Account Login
  • Register
TechLifeForum
  • Home
  • Members
  • Awards
  • Rules
  • Help
  • Donate
  • Live IRC
TechLifeForum / Programming and Development / General Programming Discussion v
« Previous 1 ... 6 7 8 9 10 ... 13 Next »
/  Programming Challenge #2[Advanced Search]
« Previous 1 2 3 4 Next »
Reply to thread
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5

[Announcement] Programming Challenge #2

07-29-2011, 07:11 AM (This post was last modified: 07-29-2011 07:12 AM by AceInfinity.)
Post: #21
AceInfinity Offline
∞ IҊϜIɴITϵ ☭
*****
Microsoft MVP
Posts: 8,696
Joined: Jun 2011
Reputation: 61
RE: .Net Coding Challenge #2
Seems nice :) The hover effect is different.



Microsoft MVP .NET Programming - (2012 - Present)
®Crestron DMC-T Certified Automation Programmer


Development Site: aceinfinity.net
WWW Find
Reply
07-29-2011, 07:33 AM
Post: #22
Immortal Offline
Member
**
Posts: 167
Joined: Jun 2011
Reputation: 3
First 25
RE: .Net Coding Challenge #2
I know cause im original :P
Find
Reply
07-29-2011, 10:57 AM (This post was last modified: 07-29-2011 10:58 AM by ThePrinCe.)
Post: #23
ThePrinCe Offline
Member
**
Posts: 84
Joined: Jun 2011
Reputation: 4
Sticky Note
RE: .Net Coding Challenge #2
Application Name: P-Calc
Language Used: VB.net
Description: a simple Calc
Level of Completion: i think 1 lol
Preview:

Source: the Code is simple and clear i don't need to comment
Code: (SELECT ALL CODE)
Dim A As Double
    Dim B As Double


    Private Sub MenuButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuButton1.Click
        Me.Close()
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        If TextBox1.Text = "" Then
            MsgBox("Pleaze Fill In")
        End If
        If TextBox2.Text = "" Then
            MsgBox("Pleaze Fill In")
        End If


        A = TextBox1.Text
        B = TextBox2.Text

        If Plus.Checked Then
            TextBox3.Text = A + B
            Label4.Text = TextBox3.Text

        End If

        If Moin.Checked Then
            TextBox3.Text = A - B
            Label4.Text = TextBox3.Text
        End If

        If Foi.Checked Then
            TextBox3.Text = A * B
            Label4.Text = TextBox3.Text
        End If

        If Sur.Checked Then
            TextBox3.Text = A / B
            Label4.Text = TextBox3.Text
        End If


    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        TextBox1.Clear()
        TextBox2.Clear()
        TextBox3.Clear()
    End Sub
Virus Scan: N/A
Download: N/A
Find
Reply
07-29-2011, 02:05 PM (This post was last modified: 10-18-2012 07:15 PM by KoBE.)
Post: #24
KoBE Offline
¯\_(ツ)_/¯
*******
Administrators
Posts: 4,197
Joined: Jun 2011
Reputation: 47
RE: .Net Coding Challenge #2
Application Name: Expression Calculator
Language Used: VB.Net
Description: This application will take any valid expression and solve it. It utilizes the shunting-yard algorithm and processes the expression using Reverse Polish Notation.
Level of Completion: 3
Preview:

Virus Scan: Click here
Download: Full Source+Binary [see attachment]
Source:
Code: (SELECT ALL CODE)
'This application uses the Shunting-yard algorithm to
'convert an expression to Reverse Polish Notation.
'Once in RPN, the Calculate() function calculates the
'expression using a Push/Pop method to maintain
'the correct order of operations.
Public Class Form1

    Private Sub btnCalc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalc.Click
        lblAnswer.Text = "Answer: " & Calculate(txtInput.Text)
    End Sub
    Private Sub txtInput_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtInput.KeyPress
        'only allow these characters to be pressed
        Dim allowed As String = "0123456789+-()*/^" & Chr(8) & Chr(32) 'backspace = Chr(8)  'spacebar = Chr(32)
        If Not allowed.Contains(e.KeyChar) Then
            e.Handled = True
        End If

    End Sub

    Private Function Calculate(ByVal expression As String) As String
        'sOperators is a list of useable operators
        Dim sOperators As String = "+-*/^"
        'sExp holds the RPN format of the expression
        Dim sExp As String = Convert(expression)
        'if the convert failed, exit return an empty string
        If sExp = "" Then Return ""
        'Dim sExp As String = "5 1 2 + 4 * + 3 -"           'test RPN string
        'Dim sExp As String = "17 3 1 - 2 * + 5 + 2 /"      'test RPN string
        'sSplit splits each value into an array
        Dim sSplit As String() = sExp.Split(" ".ToCharArray)
        'stValues holds the values to be evaluated
        Dim stValues As New Stack(Of Double)
        'loop through each value in the expression
        For i = 0 To sSplit.Length - 1
            'if the character is an Operator then
            'decide what to do.
            If sOperators.Contains(sSplit(i)) Then
                Select Case sSplit(i)
                    Case "+"
                        'once popped, the value falls out of the stack
                        'so this takes the last two values out of the stack,
                        'adds them, then pushes the value back on.
                        stValues.Push(stValues.Pop + stValues.Pop)
                    Case "-"
                        'these to variables were added to make sure the
                        'expression is evaluated in the correct order.
                        'the first number popped, must be subtraced from
                        'the second number popped
                        Dim y As String = stValues.Pop
                        Dim x As String = stValues.Pop
                        stValues.Push(x - y)
                    Case "*"
                        'same as addition
                        stValues.Push(stValues.Pop * stValues.Pop)
                    Case "/"
                        'same as subtraction
                        Dim y As String = stValues.Pop
                        Dim x As String = stValues.Pop
                        stValues.Push(x / y)
                    Case "^"
                        'same as subtract/division
                        Dim y As String = stValues.Pop
                        Dim x As String = stValues.Pop
                        stValues.Push(System.Math.Pow(x, y))
                End Select
            Else
                'if it's not an operator, push the value to the stack.
                stValues.Push(sSplit(i))
            End If
        Next
        'return the answer
        Return stValues.Pop
    End Function
    Private Function Convert(ByVal expression As String) As String
        'list of accepted operators
        Dim sOperators As String = "+-*/^"
        'FormatExp() makes sure there are spaces on
        'both sides of the operators. So not to be confused
        'as part of a number when being split.
        Dim sSplit As String() = FormatExp(expression)
        'stOutput when finished, will be
        'expression in RPN.
        Dim stOutput As New Stack(Of String)
        'stOperators holds the operators that will
        'eventually be pushed to the output
        Dim stOperators As New Stack(Of String)
        'loop through the expression
        For i = 0 To sSplit.Length - 1
            'this logic get's a bit tricky to explain
            'I suggest looking at this for a better
            'explanation: http://en.wikipedia.org/wiki/Shunting-yard_algorithm
            If sSplit(i) = ")" Then
                'If it runs into a ), then pop/push
                'the operators onto the output stack
                'until we run into the matching (
                Do Until stOperators(0) = "("
                    Try
                        stOutput.Push(stOperators.Pop)
                    Catch ex As Exception
                        lblAnswer.Text = "Answer: Parenthesis do not match up"
                        Return ""
                    End Try
                Loop
                'pop the remaining ( off
                stOperators.Pop()
            ElseIf sSplit(i) = "(" Then
                'all ( get pushed onto the operator stack
                stOperators.Push(sSplit(i))
            ElseIf sOperators.Contains(sSplit(i)) Then
                'if it's an operator then go through more checks
                If stOperators(0) = "(" Then
                    'all operators get pushed onto a (
                    stOperators.Push(sSplit(i))
                    'if it's not a ( then check the Operator Precedence
                ElseIf HigherPrecedence(stOperators(0), sSplit(i)) Then
                    'If the existing operator is higher, push
                    'the new one onto the stack.
                    stOperators.Push(sSplit(i))
                Else
                    'if there is an operator and  the new
                    'operator is higher, push/pop
                    'the old operator onto the output stack
                    If Not stOperators.Count = 0 Then
                        stOutput.Push(stOperators.Pop)
                        stOperators.Push(sSplit(i))
                    Else
                        'if there are no operators, push
                        'an operator on to the operator stack
                        stOperators.Push(sSplit(i))
                    End If
                End If
            Else
                'if it's a number push it to the output stack
                stOutput.Push(sSplit(i))
            End If
        Next
        'reverse the output and join the string
        'putting a space between each seperate
        'value. Then pop the remaining operators
        Dim sResult As String = String.Join(" ", stOutput.Reverse)
        For i = 1 To stOperators.Count
            sResult &= " " & stOperators.Pop
        Next
        Return sResult
    End Function
    Private Function FormatExp(ByVal text As String) As String()
        'hold a list of operators
        Dim ops As String = "+-*/()^"
        'add a space to either side of each operator
        For Each c As Char In ops
            text = text.Replace(c, " " & c & " ")
        Next
        'return an array with no empties.
        Return text.Split(" ".ToCharArray, StringSplitOptions.RemoveEmptyEntries)
    End Function
    Private Function HigherPrecedence(ByVal oper As String, ByVal nOper As String) As Boolean
        'Check the Precedecne
        Select Case nOper
            Case "^"
                '^ is the highest precedecne
                Return True
            Case "*", "/"
                '* / are only higher than + -
                If oper = "+" OrElse oper = "-" Then
                    Return True
                End If
            Case "+", "-"
                'the lowest, this can be removed.
                'it will always return false
        End Select

        Return False
    End Function

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub
End Class


Attached File(s)
.rar  math.rar (Size: 69.44 KB / Downloads: 4)
WWW Find
Reply
07-29-2011, 03:51 PM
Post: #25
bobolobo Offline
.. the proud Viking!
**
Posts: 156
Joined: Jun 2011
Reputation: 3
First 25
RE: .Net Coding Challenge #2
I would have entered this, but iam just started a big project..

If it was a joke... would it be funny?
Find
Reply
07-29-2011, 04:14 PM (This post was last modified: 07-30-2011 08:30 PM by Immortal.)
Post: #26
Immortal Offline
Member
**
Posts: 167
Joined: Jun 2011
Reputation: 3
First 25
RE: .Net Coding Challenge #2
Dont warn me 50% for flaming i didnt flame i trolled! GRRRRRRRrr
Find
Reply
07-29-2011, 04:15 PM
Post: #27
ImOnABoat Offline
Prepare for the worst. Hope for the best
*****
BSOD Crew
Posts: 163
Joined: Jun 2011
Reputation: 5
First 25
RE: .Net Coding Challenge #2
i dunno if i should post mine. im embarresed by the way i set out the code :( and used help for some parts :'(

Find
Reply
07-29-2011, 04:24 PM (This post was last modified: 07-29-2011 04:24 PM by AceInfinity.)
Post: #28
AceInfinity Offline
∞ IҊϜIɴITϵ ☭
*****
Microsoft MVP
Posts: 8,696
Joined: Jun 2011
Reputation: 61
RE: .Net Coding Challenge #2
(07-29-2011 04:15 PM)ImOnABoat Wrote:  i dunno if i should post mine. im embarresed by the way i set out the code :( and used help for some parts :'(

I'd suggest posting it anyway, it doesn't matter, my code wasn't cleaned up either because I made the entry really quick. I already have 2 entries here lol. If you post it people can help you out too, if you want help. This isn't HF, this is a far more supportive forum.



Microsoft MVP .NET Programming - (2012 - Present)
®Crestron DMC-T Certified Automation Programmer


Development Site: aceinfinity.net
WWW Find
Reply
07-29-2011, 04:54 PM (This post was last modified: 07-29-2011 06:17 PM by ImOnABoat.)
Post: #29
ImOnABoat Offline
Prepare for the worst. Hope for the best
*****
BSOD Crew
Posts: 163
Joined: Jun 2011
Reputation: 5
First 25
RE: .Net Coding Challenge #2
Application Name: Calculator
Language Used: VB .NET
Description: Basic calculator
Level of Completion: 2
Preview:
Source:
Code: (SELECT ALL CODE)
Public Class Form1

    Public dNumber As Double
    Public sOperation As String

    Public FirstNumber, SecondNumber, Operation As Boolean


    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        dNumber = 0
        sOperation = vbNullString

        FirstNumber = False
        SecondNumber = False

    End Sub


    Private Sub btn1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn1.Click
        If FirstNumber Then
            If dNumber <> 0 Then
                If TextBox1.Text = 0 Then
                    TextBox1.Text = 1
                    SecondNumber = True

                    Exit Sub
                End If
                TextBox1.Text &= 1
                Exit Sub
            End If
            TextBox1.Text &= 1
        Else
            TextBox1.Text = 1
            FirstNumber = True
            Operation = False
        End If

    End Sub

    Private Sub btn2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn2.Click
        If FirstNumber Then
            If dNumber <> 0 Then
                If TextBox1.Text = 0 Then
                    TextBox1.Text = 2
                    SecondNumber = True

                    Exit Sub
                End If
                TextBox1.Text &= 2
                Exit Sub
            End If
            TextBox1.Text &= 2
        Else
            TextBox1.Text = 2
            FirstNumber = True
            Operation = False
        End If

    End Sub

    Private Sub btn3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn3.Click
        If FirstNumber Then
            If dNumber <> 0 Then
                If TextBox1.Text = 0 Then
                    TextBox1.Text = 3
                    SecondNumber = True

                    Exit Sub
                End If
                TextBox1.Text &= 3
                Exit Sub
            End If
            TextBox1.Text &= 3
        Else
            TextBox1.Text = 3
            FirstNumber = True
            Operation = False
        End If

    End Sub

    Private Sub btn4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn4.Click
        If FirstNumber Then
            If dNumber <> 0 Then
                If TextBox1.Text = 0 Then
                    TextBox1.Text = 4
                    SecondNumber = True

                    Exit Sub
                End If
                TextBox1.Text &= 4
                Exit Sub
            End If
            TextBox1.Text &= 4
        Else
            TextBox1.Text = 4
            FirstNumber = True
            Operation = False
        End If

    End Sub

    Private Sub btn5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn5.Click
        If FirstNumber Then
            If dNumber <> 0 Then
                If TextBox1.Text = 0 Then
                    TextBox1.Text = 5
                    SecondNumber = True

                    Exit Sub
                End If
                TextBox1.Text &= 5
                Exit Sub
            End If
            TextBox1.Text &= 5
        Else
            TextBox1.Text = 5
            FirstNumber = True
            Operation = False
        End If

    End Sub

    Private Sub btn6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn6.Click
        If FirstNumber Then
            If dNumber <> 0 Then
                If TextBox1.Text = 0 Then
                    TextBox1.Text = 6
                    SecondNumber = True

                    Exit Sub
                End If
                TextBox1.Text &= 6
                Exit Sub
            End If
            TextBox1.Text &= 6
        Else
            TextBox1.Text = 6
            FirstNumber = True
            Operation = False
        End If

    End Sub

    Private Sub btn7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn7.Click
        If FirstNumber Then
            If dNumber <> 0 Then
                If TextBox1.Text = 0 Then
                    TextBox1.Text = 7
                    SecondNumber = True

                    Exit Sub
                End If
                TextBox1.Text &= 7
                Exit Sub
            End If
            TextBox1.Text &= 7
        Else
            TextBox1.Text = 7
            FirstNumber = True
            Operation = False
        End If

    End Sub

    Private Sub btn8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn8.Click
        If FirstNumber Then
            If dNumber <> 0 Then
                If TextBox1.Text = 0 Then
                    TextBox1.Text = 8
                    SecondNumber = True

                    Exit Sub
                End If
                TextBox1.Text &= 8
                Exit Sub
            End If
            TextBox1.Text &= 8
        Else
            TextBox1.Text = 8
            FirstNumber = True
            Operation = False
        End If

    End Sub

    Private Sub btn9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn9.Click
        If FirstNumber Then
            If dNumber <> 0 Then
                If TextBox1.Text = 0 Then
                    TextBox1.Text = 9
                    SecondNumber = True

                    Exit Sub
                End If
                TextBox1.Text &= 9
                Exit Sub
            End If
            TextBox1.Text &= 9
        Else
            TextBox1.Text = 9
            FirstNumber = True
            Operation = False
        End If

    End Sub

    Private Sub btn0_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn0.Click
        If FirstNumber Then
            If dNumber <> 0 Then
                If TextBox1.Text <> 0 Then
                    TextBox1.Text &= 0
                End If
                Exit Sub
            End If
            TextBox1.Text &= 0
        Else
            TextBox1.Text = 0
        End If
    End Sub

    Private Sub btntimes_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btntimes.Click
                If SecondNumber Then
            sOperation = "*"
            dNumber = dNumber + Val(TextBox1.Text)
            SecondNumber = False
            TextBox1.Text = 0
            Exit Sub
        End If
        If FirstNumber Or Operation Then
            If Operation Then
                FirstNumber = True
            End If
            sOperation = "*"
            dNumber = Val(TextBox1.Text)
            TextBox1.Text = 0
        End If
    End Sub

    Private Sub btnmin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnmin.Click
        If SecondNumber Then
            sOperation = "-"
            dNumber = dNumber + Val(TextBox1.Text)
            SecondNumber = False
            TextBox1.Text = 0
            Exit Sub
        End If
        If FirstNumber Or Operation Then
            If Operation Then
                FirstNumber = True
            End If
            sOperation = "-"
            dNumber = Val(TextBox1.Text)
            TextBox1.Text = 0
        End If
    End Sub

    Private Sub btnplus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnplus.Click
        If SecondNumber Then
            sOperation = "+"
            dNumber = dNumber + Val(TextBox1.Text)
            SecondNumber = False
            TextBox1.Text = 0
            Exit Sub
        End If

        If FirstNumber Then
            sOperation = "+"
            dNumber = Val(TextBox1.Text)
            TextBox1.Text = 0
        End If
    End Sub

    Private Sub btndiv_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btndiv.Click
        If SecondNumber Then
            sOperation = "/"
            dNumber = dNumber + Val(TextBox1.Text)
            SecondNumber = False
            TextBox1.Text = 0
            Exit Sub
        End If
        If FirstNumber Or Operation Then
            If Operation Then
                FirstNumber = True
            End If
            sOperation = "/"
            dNumber = Val(TextBox1.Text)
            TextBox1.Text = 0
        End If
    End Sub

    Private Sub btnEQ_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEQ.Click
        If FirstNumber And SecondNumber Then
            If (sOperation = "+") Then
                TextBox1.Text = Val(TextBox1.Text) + dNumber
            ElseIf (sOperation = "-") Then
                TextBox1.Text = dNumber - Val(TextBox1.Text)
            ElseIf (sOperation = "*") Then
                TextBox1.Text = Val(TextBox1.Text) * dNumber
            ElseIf (sOperation = "/") Then
                TextBox1.Text = dNumber / Val(TextBox1.Text)            
                Else
                    Exit Sub
                End If
                dNumber = Val(TextBox1.Text)
                FirstNumber = True
                SecondNumber = False
                sOperation = ""

            End If
    End Sub

    Private Sub btnC_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnC.Click
        TextBox1.Text = 0
    End Sub

    Private Sub btnCE_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCE.Click
        dNumber = 0
        sOperation = vbNullString

        FirstNumber = False
        SecondNumber = False
        TextBox1.Text = 0
    End Sub

    Private Sub btnBackspace_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBackspace.Click
        Dim str As String = TextBox1.Text
        str = str.Remove(str.Length - 1)
        TextBox1.Text = str
    End Sub

    Private Sub btndot_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btndot.Click
        If TextBox1.Text = 0 Then
            If FirstNumber = False Then
                TextBox1.Text = "0."
                FirstNumber = True
                Exit Sub
            End If
        End If
        If FirstNumber Then
            If dNumber <> 0 Then
                If TextBox1.Text = 0 Then
                    TextBox1.Text &= "."
                    SecondNumber = True

                    Exit Sub
                End If
                TextBox1.Text &= "."
                Exit Sub
            End If
            TextBox1.Text &= "."
            Exit Sub
        End If
    End Sub
End Class
Virus Scan: NA
Download: NA

It's missing a few things, that's why the Boolean "operation" isn't fully being used.

Find
Reply
07-29-2011, 05:29 PM
Post: #30
AceInfinity Offline
∞ IҊϜIɴITϵ ☭
*****
Microsoft MVP
Posts: 8,696
Joined: Jun 2011
Reputation: 61
RE: .Net Coding Challenge #2
Looks good enough to me :)



Microsoft MVP .NET Programming - (2012 - Present)
®Crestron DMC-T Certified Automation Programmer


Development Site: aceinfinity.net
WWW Find
Reply
« Previous 1 2 3 4 Next »
Reply to thread


Possibly Related Threads...

Thread: Author Replies: Views: Last Post
  K Programming Language AceInfinity 4 194 05-28-2013 04:03 PM
Last Post: AceInfinity
  Sphere Online Judge (SPOJ) - Programming Challenges AceInfinity 2 151 05-26-2013 05:46 PM
Last Post: AceInfinity
  ACM-ICPC - Programming Competition KoBE 17 594 05-25-2013 04:58 PM
Last Post: KoBE
  Programming Challenge Site - Al Zimmermann's AceInfinity 2 224 04-23-2013 01:56 AM
Last Post: AceInfinity
  TreasureChest Challenge AceInfinity 2 187 04-16-2013 12:27 AM
Last Post: AceInfinity

  • View a Printable Version
  • Send this Thread to a Friend
  • Subscribe to this thread
Forum Jump:


Users browsing this thread
1 Guest(s)
Youtube Facebook Twitter Digg
Return to Top
All content © copyright TechLifeForum
Powered By MyBB, © 2002-2013 MyBB Group
Designed by ThemeFreak
Mobile Version