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

An application in V isual Basic that allow: 1) Enter the number of candidates in

ID: 3879107 • Letter: A

Question

An application in Visual Basic that allow:

1) Enter the number of candidates in the voting.

2) Based of the number of candidates the application should ask the name and lastName of the candidates..

3) The name of the candidates must be registered.

4) You must provide a form that allow the voting process:

a) Voting Form: The Voting form should contain the instructions for the selection of the candidate and provide a way to record each vote.

b) You must increase the sum of the votes for the corresponding candidate according to the vote.

5) As a result, the list of candidates and their total vote must be provide.

SICI 3029 Voting System Ver 1 a Voting Functions SICI Voting System 2016 Select Candidiate from the list below and press Vote System Admin Functions Voting Functions Exit System Admin Functions Vote System Admin Functions Conclude Voting Indicate Number Candidates Display Results Ist Results Enter Candidate Names Preview Candidate List Display Results Reset Candidates Back to Main Options Display Winner Back to Admin Options

Explanation / Answer

creating the structure of the XML file:

<?xml version="1.0" encoding="utf-8"?>
<Poll>
<Vote>
<Choice>Obama</Choice>
</Vote>
<Vote>
<Choice>McCain</Choice>
</Vote>
</Poll>

Once we have designed our form, we can double-click on the Submit button to create a handler for it in the code-behind:

Private Sub butSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butSubmit.Click
If radMcCain.Checked = True Then
submitVote("McCain")
ElseIf radObama.Checked = True Then
submitVote("Obama")
End If
End Sub

The submitVote method looks something like this:

Private Sub submitVote(ByVal theVote As String)
Try
Dim xmlDoc As XDocument = XDocument.Load("Poll.xml")

xmlDoc.Element("Poll").Add(New XElement("Vote", New XElement("Choice", theVote)))

xmlDoc.Save("Poll.xml")
lblResults.Text = "Thank you for your vote."
readXML()
Catch
lblResults.Text = "Sorry, unable to process request. Please try again."
End Try
End Sub

readXML method to output current results to the form:

Public Class Form1

Private Sub butSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butSubmit.Click
If radMcCain.Checked = True Then
submitVote("McCain")
ElseIf radObama.Checked = True Then
submitVote("Obama")
End If
End Sub

Private Sub submitVote(ByVal theVote As String)
Try
Dim xmlDoc As XDocument = XDocument.Load("Poll.xml")

xmlDoc.Element("Poll").Add(New XElement("Vote", New XElement("Choice", theVote)))

xmlDoc.Save("Poll.xml")
lblResults.Text = "Thank you for your vote."
readXML()
Catch
lblResults.Text = "Sorry, unable to process request. Please try again."
End Try
End Sub

Private Sub readXML()
Dim xmlDoc As XDocument = XDocument.Load("Poll.xml")

Dim votes = From vote In xmlDoc.Descendants("Vote") _
Select Vote = vote.Element("Choice").Value

Dim mCount As Integer
Dim oCount As Integer
mCount = 0
oCount = 0

For Each vote In votes
If vote = "McCain" Then
mCount += 1
ElseIf vote = "Obama" Then
oCount += 1
End If
Next vote

Dim theTotal As Double
theTotal = mCount + oCount
Dim mPercent As Double
Dim oPercent As Double
mPercent = (mCount / theTotal) * 100
oPercent = (oCount / theTotal) * 100

lblResults.Text = "McCain: " & mCount & " votes (" & mPercent & "%)." & Constants.vbLf
lblResults.Text = lblResults.Text & "Obama: " & oCount & " votes (" & oPercent & "%)." & Constants.vbLf + Constants.vbLf
End Sub

Private Sub butResults_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butResults.Click
readXML()
End Sub
End Class

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote