You are on page 1of 6

ELECTRONIC

EVM
VOTING
MACHINE
By Alexander Aronowitz
TABLE
OF
• vote CONTE 01



NTS
Nominations
total votes
See nominations
02
03
04
• Add nominations 05
• Undo vote 06
• Exit 07
EVM
Electronic voting machine
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin varius, eros nec efficitur euismod, lectus
turpis sollicitudin augue, non ultricies enim nunc sit amet augue. Quisque ante magna, varius et
vehicula congue, viverra eu nulla.
EVM
#include <iostream>
#include <cstdlib>
#include <stack>
using namespace std;

struct Leaf {
string name;
string electionSymbol;
int votes;
Leaf* next;
};

stack<pair<Leaf*, int>> voteStack;


Leaf* root = nullptr;

void addNomination(string name, string electionSymbol) {


Leaf* newLeaf = new Leaf;
newLeaf->name = name;
newLeaf->electionSymbol = electionSymbol;
newLeaf->votes = 0;
newLeaf->next = root;
root = newLeaf;
cout << "Nomination added: " << name << " (Symbol: " << electionSymbol << ")" << endl;
}

void initializeDefaultNominations() {
addNomination("PTI", "Bat");
addNomination("PMLN", "Lion");
addNomination("PPP", "Arrow");
}

void displayNominations() {
Leaf* current = root;
while (current != nullptr) {
cout << current->name << " - Symbol: " << current->electionSymbol
<< " - Votes: " << current->votes << endl;
current = current->next;
}
}

void vote(string name) {


Leaf* current = root;
while (current != nullptr) {
if (current->name == name) {
current->votes++;
voteStack.push({current, 1});
cout << "Vote casted for: " << name << " (Symbol: " << current->electionSymbol << ")" << endl;
return;
}
current = current->next;
}
cout << "Nomination not found." << endl;
}

void undoVote() {
if (!voteStack.empty()) {
auto lastVote = voteStack.top();
lastVote.first->votes -= lastVote.second;
voteStack.pop();
cout << "Last vote undone." << endl;
} else {
cout << "No votes to undo." << endl;
}
}

void clearScreen() {
#ifdef _WIN32
system("cls");
#else
system("clear");
#endif
}

int main() {
initializeDefaultNominations();

int choice;
string nominationName;
string electionSymbol;

do {
cout << "\nEVM Menu:\n";
cout << "1. Vote\n";
cout << "2. See Nominations\n";
cout << "3. Total Votes for Nominations\n";
cout << "4. Add Nomination\n";
cout << "5. Undo Vote\n";
cout << "0. Exit\n";
cout << "Enter your choice: ";
cin >> choice;

cin.ignore();

switch (choice) {
case 1:
cout << "Enter the nomination name to vote: ";
cin >> nominationName;
vote(nominationName);
break;
case 2:
displayNominations();
break;
case 3:
displayNominations();
break;
case 4:
cout << "Enter the new nomination name: ";
cin >> nominationName;
cout << "Enter the election symbol: ";
cin >> electionSymbol;
addNomination(nominationName, electionSymbol);
break;
case 5:
undoVote();
break;
case 0:
cout << "Exiting EVM. Thank you for participating!" << endl;
break;
default:
cout << "Invalid choice. Please try again." << endl;
}

cout << "Press Enter to continue...";


cin.ignore();
cin.get();

clearScreen();

} while (choice != 0);

return 0;
}

You might also like