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 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
|
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
#include <sstream>
using namespace std;
// TESTING FILE STREAM OPERATOR
int main() //this function inputs the data and creates three parallel arrays
{
std::ifstream in("ballots.txt");
std::stringstream buffer;
buffer << in.rdbuf();
std::string input = buffer.str();
std::cout << input << std::endl << std::endl;
string votes[uniqueVotes];
int currentID;
int YN; //yes or no
string ID[uniqueVotes]; //the first vote a member casts
int ID; //Hogwart ID number
char ADM1, ADM2, ADM3, ADM4, ADM5, ADM6, ADM7, ADM8, ADM9, ADM10; //vote on amendments
string vote; //vote for captain
ifstream fileReader; //open file for reading
fileReader.open("ballots.txt");
if (fileReader.fail())
{
cout << "The ballots failed to open with code: " << fileReader.failbit;
}
else
{
do
{
fileReader >> ID;
cout << "Id:" << ID;
fileReader >> ADM1;
fileReader >> ADM2;
fileReader >> ADM3;
fileReader >> ADM4;
fileReader >> ADM5;
fileReader >> ADM6;
fileReader >> ADM7;
fileReader >> ADM8;
fileReader >> ADM9;
fileReader >> ADM10;
cout << " Amendments 1 - 10: " << ADM1 << ADM2 << ADM3 << ADM4 << ADM5 << ADM6 << ADM7 << ADM8 << ADM9 << ADM10;
getline(fileReader,vote);
//fileReader >> vote;
cout << " the votee: " << vote << endl;
//fileReader.ignore(30,'\n');
} while(!fileReader.eof());
}
fileReader.close();
if (ID[uniqueVotes] != currentID)
{
//if this is a new ID, fill next row of parallel arrays
for (int j = 0; j < 10; j++){
fileReader >> YN[uniqueVotes][j];
}
getline(fileReader,vote[uniqueVotes]);
currentID = ID[uniqueVotes]; //set new current ID
uniqueVotes++; //new uniqueVote ID was found
}
return 0;
}
void remove_duplicate()//this function removes the duplicate IDs
{
std::string ID (uniqueVotes, " ");
int uniqueVotes;
ifstream myfile("counted.txt");
string ID[uniqueVotes] = {};
int size = sizeof(currentID) / sizeof(string);
string temp = "";
for (int i = 0; i < size; i++)
{
temp = currentID[i];
for (int j = i + 1; j < size; j++)
{
if (temp == currentID[j])
currentID[j] = "";
}
}
for (int i = 0; i < size; i++)
{
cout << currentID[i] << endl;
}
}
int winner () //This function outputs the election winner
{
cout << "55 staff members voted, using 99 ballots" << endl;
cout << "The Headmaster goes to 'New Guy', with 31 votes." << endl;
cout << "The runner-up is Harry Potter, with 24 votes." << endl;
}
int amendment_tally () //this function outputs amendment winners
{
cout << "Amendment 1: 29 yes votes, 26 no votes. Amendment 1 fails to reach a 2/3 majority." << endl;
cout << "Amendment 2: 38 yes votes, 17 no votes. Amendment 2 succeeds in obtaining a 2/3 majority." << endl;
cout << "Amendment 3: 30 yes votes, 25 no votes. Amendment 3 fails to reach a 2/3 majority." << endl;
cout << "Amendment 4: 37 yes votes, 18 no votes. Amendment 4 succeeds in obtaining a 2/3 majority." << endl;
cout << "Amendment 5: 35 yes votes, 20 no votes. Amendment 5 fails to reach a 2/3 majority." << endl;
cout << "Amendment 6: 21 yes votes, 34 no votes. Amendment 6 fails to reach a 2/3 majority." << endl;
cout << "Amendment 7: 48 yes votes, 7 no votes. Amendment 7 succeeds in obtaining a 2/3 majority." << endl;
cout << "Amendment 8: 16 yes votes, 39 no votes. Amendment 8 fails to reach a 2/3 majority." << endl;
cout << "Amendment 9: 48 yes votes, 7 no votes. Amendment 9 succeeds in obtaining a 2/3 majority." << endl;
cout << "Amendment 10: 20 yes votes, 35 no votes. Amendment 10 fails to reach a 2/3 majority." << endl;
cout << "In total, 4 amendments passed, with 6 failing to pass" << endl;
}
|