The results from the mayor\'s race have been reported by each precinct as follow
ID: 3762266 • Letter: T
Question
The results from the mayor's race have been reported by each precinct as follows:
Candidate Candidate Candidate Candidate Winner Runoff
Precinct A B C D
1 192 48 206 37
2 147 90 312 21
3 186 12 121 38
4 114 21 408 39
5 267 13 382 29
Write a program to do the following:
a. Read the raw vote totals from a data file that contains one row for each precinct.
b. Display the table with appropriate headings for the rows and columns.
c. Compute and display the total number of votes received by each candidate and
the percent of the total votes cast.
d. If any one candidate received over 50% of the votes, the program should print, in the last column, a message declaring that candidate the winner.
e. If no candidate received 50% of the votes, the program should print a message
declaring a run-off between the two candidates receiving the highest number of
votes; the two candidates should be identified by their letter names.
f. For testing, run the program with the above data, and also with another
data file where Candidate C receives only 108 votes in precinct 4.
Data file:
(precinct, candiadateAvotes, , candiadateBvotes, candiadateCvotes, candiadateDvotes
1 192 48 206 37
2 147 90 312 21
3 186 12 121 38
4 114 21 408 39
5 267 13 382 29
Explanation / Answer
#include <iostream.h>
#include <conio.h>
intconst size=50;
class vote
{
int candidate;
int vote[5];
staticint spvote;
void getdisplay(void);
};
int vote :: spvote;
void vote :: getdisplay(void)
{
cout<<" Enter how many candidate you want to make:-";
cin>>candidate;
staticint a,b,c,d,e;
a=0;
a=b=c=d=e;
cout<<" Enter 1-5 Integers ";
for(int i=0;i< candidate;i++)
{
cin>>ballet[i];
switch(ballet[i])
{
case 1:vote[a];
a++;
break;
case 2:vote[b];
b++;
break;
case 3:vote[c];
c++;
break;
case 4:vote[d];
d++;
break;
case 5:vote[e];
e++;
break;
default : ++spvote;
}
}
//for displayingint choice;
do
{
cout<<" Choices Available ";
cout<<" 1) A By vote ";
cout<<"2) B By vote ";
cout<<"3) C By vote ";
cout<<"4) D By vote ";
cout<<"5) E By vote ";
cout<<"6) Spoilt vote ";
cout<<"7) EXIT ";
cout<<"Enter Your Choice :- ";
cin>>choice;
switch(choice)
{
case 1: cout<<"A Scored vote is "<<a;
break;
case 2: cout<<"B By vote is "<<b;
break;
case 3: cout<<"C By vote is "<<c;
break;
case 4: cout<<"D By vote is "<<d;
break;
case 5: cout<<"E By vote is "<<e;
break;
case 6: cout<<"Spoil vote were "<<spA;
break;
case 7: goto end;
}
}while(1);
end:
}
void main()
{
clrscr();
vote o1;
o1.getdisplay();
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.