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

C# Loops Arrays Variables Strings Main() and command-line arguments Properties Y

ID: 3831469 • Letter: C

Question

C# Loops Arrays Variables Strings Main() and command-line arguments Properties Your company has been hired to develop a new voting system for the upcoming Presidential Elections. Your boss comes to you and ask you to be the head developer to complete this task. He explained the main problems of the current system and at the same time gives you the requirements for the new system which are as follows: System Configuration: I) a. System must be capable to configure which parties are involved in the presidential elections (ex: Democratic, Republican, Independent, etc.) b. System must be capable to configure the president candidate's names (ex: Hillary Clinton, Donald Trump, etc.) c. System must be capable to configure the vice president candidate's names (ex: Bennie Sanders, Ted Cruz, etc.) d. System must be capable to run endlessly unless a sentinel character is entered. 2) System output Display (Each ballot must contain the following information) a. A welcome greeting message must be displayed explaining the voter how to use the new voting system. b, Display candidates and Party information i. Candidate's name and Party (President) ii. Candidate's name and Party rvice President) 3) Voting Begins: a. System must prompt voters to enter voter's name and identification. b. System must be capable to record each vote for president and vice president (NOTE: voters must have the choice to vote for one Party for President and another Party for Vice President. c. After each ballot a message must prompt the voter if vote has been successful or not 4) Results a. Results must be displayed ONLY when the system has been successfully completed, in other words when the sentinel character has been entered. b. output must display the winner President and Vice President with the number of votes that each candidate received. output must also display which candidate was second, third, and so on (president and vice president with total number of votes that each candidate received as well. IMPORTANT: YOU MUST HAVE TWO CLASSES, ONE CLASS FOR IMPLEMENTATION AND ONE FOR TESTING ITS CAPABILITIES.

Explanation / Answer

For developing the voting system, Firstly you need to set-up an Database for the Voting Application.

Here, I will explain you about the C# code along with the comments.

One Class for Implementation: -

Program:


// Created a method named EligibleVoter

private void EligibleVoter(string vID)
{
// This is to connect your database to the c# code
  
SqlConnection conn = new SqlConnection(WebConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
  
   // I have created the table name Votes and column_name as CountVotes along with the vID as primary key
  
SqlCommand cmd = new SqlCommand("UPDATE Votes SET CountVotes = CountVotes+1 WHERE vID=@vID", conn);
cmd.CommandType = CommandType.Text;

cmd.Parameters.AddWithValue("@vID", vID);

using (conn)
{
//Now, it will open and connect to the database
conn.Open();
  
       // This statement is used to execute the update query which we have written at top
      
cmd.ExecuteNonQuery();
}

protected void btn_Click(object sender, EventArgs e)
{
  
EligibleVoter("A");
}

One Class for Testing: -

Program:

<!doctype html>
<html>
<head>
<title> Voting System </title>
</head>

<body>
<form id="votingForm" runat="server">
<div>
<asp:voterLoginView ID="voterLogView" runat="server">
<AnonymousTemplate>
<asp:voterLogin ID="voterLogView2" runat="server">
</asp:voterLogin>
</AnonymousTemplate>
</asp:voterLoginView>
<br />
<table>
<tr>
<td>
<asp:Label ID="labelA" runat="server" Text="Label"></asp:Label>
</td>
<td>
<asp:Label ID="labelB" runat="server" Text="Label"></asp:Label>
</td>
</tr>
<tr>
<td>
<asp:Button ID="VoteAbtn" runat="server" Text="Type Vote A" />
</td>
<td>
<asp:Button ID="VoteBbtn" runat="server" Text="Type Vote A" />
</td>
</tr>
</table>

</div>
</form>
</body>

</html>