Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <fstream>
- #include <string>
- #include <iomanip>
- using namespace std;
- class Precinct {
- public:
- int sum = 0;
- void add(int sumA) {
- this->sum = this->sum + sumA;
- }
- };
- class ElectionData {
- public:
- string elector;
- int pre1;
- int pre2;
- int pre3;
- int ElectorSum;
- void setData(string tempElector, int tempPre1, int tempPre2, int tempPre3) {
- this->elector = tempElector;
- this->pre1 = tempPre1;
- this->pre2 = tempPre2;
- this->pre3 = tempPre3;
- this->ElectorSum = pre1 + pre2 + pre3;
- }
- void resetElector(string newTempElector) {
- this->elector = newTempElector;
- }
- int P1() {
- return this->pre1;
- }
- int P2() {
- return this->pre2;
- }
- int P3() {
- return this->pre3;
- }
- string getData() {
- string tempString = " ";
- tempString += elector;
- tempString += " ";
- tempString += to_string(pre1);
- tempString += " ";
- tempString += to_string(pre2);
- tempString += " ";
- tempString += to_string(pre3);
- return tempString;
- }
- };
- string Elector;
- int a, b, c;
- vector <ElectionData> ElectionDataVector;
- int i = 0;
- void main() {
- ifstream fileInput;
- fileInput.open("C:\\temp\\mp4election.txt");
- while (!fileInput.eof())
- {
- fileInput >> Elector >> a >> b >> c;
- ElectionData *tempElection = new ElectionData;
- tempElection->setData(Elector, a, b, c);
- ElectionDataVector.push_back(*tempElection);
- }
- Precinct PreA, PreB, PreC;
- for (ElectionData CurrentElection : ElectionDataVector) {
- PreA.add(CurrentElection.P1());
- PreB.add(CurrentElection.P2());
- PreC.add(CurrentElection.P3());
- }
- cout << "\t" << "\t" << "\t" << "\t" << "\t" << "\t" << "Total " << endl;
- for (ElectionData CurrentElection : ElectionDataVector) {
- cout << setw(25) << left << CurrentElection.elector << CurrentElection.pre1 << "\t" << CurrentElection.pre2 << "\t" << CurrentElection.pre3 << "\t" << CurrentElection.ElectorSum << endl;
- }
- cout << setw(25) << left << "Total: " << PreA.sum << "\t" << PreB.sum << "\t" << PreC.sum << endl;
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment