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

Exercise 1: Sample Count 50 marks Problem Statement A sample count is performed

ID: 3887660 • Letter: E

Question

Exercise 1: Sample Count 50 marks Problem Statement A sample count is performed at the start of the counting pracess for each electoral division to get an early indication of the possible electoral outcome. This will be released once for each electoral division. Releasing the sample count helps to prevent speculation and misintormation from unofficial sources while the counting is underway and before the formal election results are announced. In this exercise, assume two teams A and B are competing in an electoral division with N polling stations, 1sN S. After the end of the polling hours, the election officer will select 100 tickets trom each station. Write a program to compute the sample counts for teams A and B. Your program should read in the following inputs (all of type int] from the user: numStation: The total number of polling stations in the electoral division. numVoterDivision: The total number of voters in the electoral division. " . For each polling station, you will read in the folloing data: - numVoteA: The number of votes for team A - numVoteB: The number of votes for team B numVoterStation: The total number of voters in the polling station. Your program should compute the sample count (of type float for each team weighted by the number of voters in each polling station. To compute the sample count of team A, we have: sumpleCoutA where numInvalidVote = 100-numVoteA-numVoteB. For example, in the first sample run, the numbers of invalid votes in the two stations are 100-80-15 = 5 and 100-65-25 = 10, respectively Therefore, the sample count for team A is (-ao- The sample count for team B can be similarly computed by replacing numVoteA with X 100) + (1 651-X10 a)-79.42% numVoteB in the equation. Your program should output the computed sample counts. In addition, it should also print a summary message based an which team wins and how big is the win margin lf there is no difference between the sample counts, output "There is no winner in this election." · the difference is less than 5%, say 52% for team A and 48% for team B. output Team A narrowly wins this election." lf the difference is between 5% and 30% (both inclusive, say 42.50% for team A and 57.50% for team B, output "Team B wins by a significant margin." · ·

Explanation / Answer

Hi,

you can definitely do this in one hour without arrays , recursion and pointers, here is a simple code which does the job, i have added comments to help you understand.

#include <stdio.h>

void printSummary(float sampleCountA,float sampleCountB)

{

printf("sample count for team A=%.2f ",sampleCountA*100);

printf("sample count for team B=%.2f ",sampleCountB*100);

if(sampleCountA==sampleCountB)

printf("There is no winner in this election");

else if((sampleCountA*100-sampleCountB*100)<5 && (sampleCountA*100-sampleCountB*100)>0 )

printf("Team A narrowly wins this election");

else if((sampleCountB*100-sampleCountA*100)<5 && (sampleCountB*100-sampleCountA*100)>0)

printf("Team B narrowly wins this election");

else if((sampleCountA*100-sampleCountB*100)<30 && (sampleCountA*100-sampleCountB*100)>0)

printf("Team A wins by significant margin");

else if((sampleCountB*100-sampleCountA*100)<30 && (sampleCountB*100-sampleCountA*100)>0)

printf("Team B wins by significant margin");

else if(sampleCountA>sampleCountB)

printf("Team A wins by a landslide");

else

printf("Team B wins by a landslide");

}

int main(void) {

// your code goes here

float sampleCountA=0.0;

float sampleCountB=0.0;

int numStation,totalVoters;

printf("enter total number of voters ");

scanf("%d",&totalVoters);

printf("enter number of polling stations ");

scanf("%d",&numStation);

while(numStation--)

{

int voters,votersA,votersB;

printf("enter number of voters in station %d ",numStation+1);

scanf("%d",&voters);

printf("enter number of voters for team A ");

scanf("%d",&votersA);

printf("enter number of voters for team B ");

scanf("%d",&votersB);

int invalid=100-votersA-votersB;

float fraction= (float)voters/(float)totalVoters;

sampleCountA+= (float)(votersA*fraction)/(100-invalid);

sampleCountB+= (float)(votersB*fraction)/(100-invalid);

}

printSummary(sampleCountA,sampleCountB);

return 0;

}

THumbs up if this was helpful, otherwise let me know in comments.