1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
#include <iostream>
#include <iomanip>
using namespace std;
//Global declaration
int table[5][4] = { { 192,148, 1206, 137 },
{ 147, 190, 1312,121 },
{ 186, 112, 1121, 138 },
{ 114,121,1408,139 },
{ 267,113, 1382,129 },
};
int candidateSum[5];
int stationSum[4];
int voteSum( int voteArray[][4], int row, int rSum[], int cSum[]);
int main()
{
int totalSum;
cout << "This is an Election System that displays the voting results of 5 candidates at 4 polling stations."<<endl;
cout << "\nThe program is using function voteSum() to determine:" << endl;
cout << "(i) the sum of votes cast for each candidate and " << endl;
cout << "(ii)the sum of votes cast for each polling station." << endl;
//By using array table, call function voteSum to find 1) the candidates sum of votes and 2) the polling stations sum of votes; using the table array, and return the total of votes in the election.
totalSum = voteSum( table, 5, candidateSum, stationSum);
cout << "\nThe election details are shown in the following table:" << endl<<endl;
}
int voteSum(int voteArray[][4], int row, int rSum[],int cSum[])
{int total;
total=0;
cout<<setw(30)<<setfill(' ');
for(int i=0; i<4 ;i++)
cout<<"Station "<<i+1<<setw(10);
cout<<setw(5)<<'|'<<" TOTAL VOTE";
cout<<setfill('-')<<setw(79)<<"-"<<endl;
for(int i=0; i<row ;i++)
{cout<<"Candidate "<<i+1<<" : ";
for (int j=0; j<4; j++)
cout<<setw(12)<<setfill(' ')<<voteArray[i][j];
cout<<setw(7)<<'|';
{
for (int j=0; j<4; j++)
rSum[i]+=voteArray[i][j];
cout<<setw(10)<<rSum[i];}
cout<<endl;}
cout<<setfill('-')<<setw(79)<<"-"<<endl;
cout<<"TOTALS : ";
for (int j=0; j<4; j++)
{
for(int i=0; i<row ;i++)
cSum[j]+=voteArray[i][j];
cout<<setw(12)<<setfill(' ')<<cSum[j];
for(int i=0; i<row ;i++)
total +=voteArray[i][j];}
cout<<setw(7)<<'|';
cout<<setw(10)<<total<<endl;
return total;
}
|