Skip to content

Instantly share code, notes, and snippets.

@heyAyushh
Created December 3, 2017 14:37
Show Gist options
  • Save heyAyushh/ac7c8df1cae9e21bb5ba024b41c7c1de to your computer and use it in GitHub Desktop.
Save heyAyushh/ac7c8df1cae9e21bb5ba024b41c7c1de to your computer and use it in GitHub Desktop.
This is a question that is asked in various exams of object oriented programming and it is implemented in c++
/*==================================================================================================================+
| |
| An election is contested by five candidates. |
| The candidates are numbered 1 to 5 and the voting is done by marking the candidate number on the ballot paper. |
| Write a program to read the ballots and counts |
| the votes cast for each candidates using an array variable count. |
| In case, a number read is outside the range 1 to 5, the ballot should be considered as a 'spoilt ballot' |
| and the program should also count the number of spoilt ballots. |
| |
+==================================================================================================================*/
#include<iostream.h>
#include<conio.h>
int const size = 50;
class ballot
{
int candidate; //candidate you want to create for votingint vote[size];
int ballot[5];
static int spballot; //spoil ballotpublic :
void getdisplay(void);
};
int ballot::spballot;
void ballot::getdisplay(void)
{
cout << "\n\n\nEnter how many candidate you want to make:-";
cin >> candidate;
static int a, b, c, d, e;
a = 0;
a = b = c = d = e;
cout << "\nEnter 1-5 Integers\n";
for (int i = 0; i < candidate; i++)
{
cin >> vote[i];
switch (vote[i])
{
case 1:
ballot[a];
a++;
break;
case 2:
ballot[b];
b++;
break;
case 3:
ballot[c];
c++;
break;
case 4:
ballot[d];
d++;
break;
case 5:
ballot[e];
e++;
break;
default:
++spballot;
}
}
//for displaying int choice;
do
{
cout << "\n\n\n\nChoices Available\n";
cout << "\n1) Scored By Ballot A\n";
cout << "2) Scored By Ballot B\n";
cout << "3) Scored By Ballot C\n";
cout << "4) Scored By Ballot D\n";
cout << "5) Scored By Ballot E\n";
cout << "6) Spoilt Ballot\n";
cout << "7) EXIT\n";
cout << "Enter Your Choice :- ";
cin >> choice;
switch (choice)
{
case 1:
cout << "Scored By Ballot A is " << a;
break;
case 2:
cout << "Scored By Ballot B is " << b;
break;
case 3:
cout << "Scored By Ballot C is " << c;
break;
case 4:
cout << "Scored By Ballot D is " << d;
break;
case 5:
cout << "Scored By Ballot E is " << e;
break;
case 6:
cout << "Spoil Ballot were " << spballot;
break;
case 7:
goto end;
}
} while (1);
end:
}
void main()
{
clrscr();
ballot o1;
o1.getdisplay();
}
@heyAyushh
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment