Problem with executing classes

closed account (LNAM4iN6)
I've been at this for hours, but I just can't seem to get a class function to execute. The code entails a lot more, but as of know I am just trying to get the code to work for case A. Please help I am at a complete loss as to how to make this work! I was hoping it would work after I fixed the compiling errors but no luck!
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
#include<iostream>
#include<iomanip>
#include<fstream>
#include<string>
#include<vector>
using namespace std;

class countyElectionResults{

        friend ostream &operator<<(ostream &, countyElectionResults);

public:

        countyElectionResults();
        countyElectionResults(string);
        bool loadFile(string);
        string getCountyName();
        vector<char> getVotes();
        void showVotes();
        int getNullifierVotes();
        int getFielditeVotes();
        int getOtherVotes();
        int getTotalVotes();

private:

        string countyName;
        vector<char> votes;
        int nullifierVotes;
        int fielditeVotes;
        int otherVotes;
        void countVotes();
};
countyElectionResults::countyElectionResults() {

        countyName = " ";
        nullifierVotes = 0;
        fielditeVotes = 0;
        otherVotes = 0;
}

countyElectionResults::countyElectionResults(string filename) {

ifstream textfile;
char possibilities;

cout << "Enter the county file to process: ";
cin >> filename;
textfile.open(filename.c_str());
if (!textfile){
        cout << "File not found. Please enter a valid file." << endl;
        }

getline(textfile, countyName);

while (textfile >> possibilities) {
        votes.push_back(possibilities);
        switch(possibilities){
                case 'N':
                case 'n':
                nullifierVotes++;
                break;
                case 'F':
                case 'f':
                fielditeVotes++;
                break;
                default:
                otherVotes++;
                break;
}}
return;
}

vector<char> countyElectionResults::getVotes(){
        return votes;
}

int countyElectionResults::getNullifierVotes(){
        return nullifierVotes;
}

int countyElectionResults::getFielditeVotes(){
        return fielditeVotes;
}

int countyElectionResults::getOtherVotes(){
        return otherVotes;
}

int main() {

char choice;
countyElectionResults(name);

do {
cout << "Add a county election file             A" << endl;
cout << "Show election totals on screen         P" << endl;
cout << "Search for county results              S" << endl;
cout << "Exit the program                       Q" << endl << endl;
cout << "Please enter your choice: ";
cin >> choice;

switch (choice){
{       case 'A':
        case 'a':
        countyElectionResults countyElectionResults(name);
        break; }
{       case 'P':
        case 'p':
        cout << " " << endl;
        break; }
{       case 'S':
        case 's':
        cout << " " << endl;
        break; }
{       case 'Q':
        case 'q':
        cout << "Ending program..." << endl;
        break;  }
{       default:
        cout << "Not a valid choice" << endl;
        break; }
}
}
while   ((choice != 'Q')&&(choice != 'q'));

return 0;
}
What behaviour are you seeing at the moment? What behaviour are you expecting to see?
Topic archived. No new replies allowed.