In: Computer Science
#include <iostream>
#include <string>
using namespace std;
class vote
{
int fgender_cnt,mgender_cnt, tcandidate_cnt,
bcandidate_cnt;
int
dregistered_cnt,rregistered_cnt,teconomy_cnt,beconomy_cnt;
int bcivil_cnt,tcivil_cnt,bcovid_cnt,tcovid_cnt;
double
Democrat_trump_per,Democrat_biden_per,Republican_trump_per,Republican_biden_per;
double fgender_trump_per,mgender_trump_per;
double fgender_biden_per,mgender_biden_per;
double
economy_trump_per,civil_trump_per,covid_trump_per;
private:
struct votenode
{
char candidate;
char registered;
char gender;
char covid;
char economy;
char civil;
votenode *next;
};
votenode *first, *previous, *current, *temp;
public:
void read_voters();
void count_voters();
void voter_stats();
void print_stats();
};
int main()
{
vote data;
data.read_voters();
data.count_voters();
data.voter_stats();
data.print_stats();
system("pause");
return 0;
}
void vote::read_voters()
{
char more = 'Y';
first = new votenode;
previous = first;
while (more == 'Y')
{
current = new votenode;
system("cls");
cout << "Enter your voter
registration (D for Democrat or R for Republican) ";
cin >>
current->registered;
cout << endl <<
"Enter your gender (M for Male or F for Female) ";
cin >>
current->gender;
cout << endl <<
"Enter the candidate you are voting for (T for Trump or B for
Biden) ";
cin >>
current->candidate;
cout << endl << "Who
do you think is doing best on economy? (T for Trump or B for Biden)
";
cin >>
current->economy;
cout << endl << "Who do
you think is doing best on civil unrest? (T for Trump or B for
Biden) ";
cin >> current->civil;
cout << endl << "Who
do you think is doing best on covid-19? (T for Trump or B for
Biden) ";
cin >> current->covid;
current->next = 0;
previous->next = current;
previous = current;
cout << endl << "Enter
more data yes/no ";
flushall();
cin >>more;
}//END OF WHILE LOOP
}//END OF READ_VOTER
void vote::count_voters()
{
cout << "Executing count_voter" <<
endl;
current = first->next;
fgender_cnt,mgender_cnt, tcandidate_cnt,
bcandidate_cnt=0;
dregistered_cnt,rregistered_cnt,teconomy_cnt,beconomy_cnt=0;
bcivil_cnt,tcivil_cnt,bcovid_cnt,tcovid_cnt=0;
while (current!= 0)
{
if(current->gender=='F')
this->fgender_cnt++;
if(current->gender=='M')
this->mgender_cnt++;
if(current->candidate=='B')
this->bcandidate_cnt++;
if(current->candidate=='T')
this->tcandidate_cnt++;
if(current->registered=='D')
this->dregistered_cnt++;
if(current->registered=='R')
this->rregistered_cnt++;
if(current->economy=='T')
this->teconomy_cnt++;
if(current->economy=='B')
this-> beconomy_cnt++;
if(current->civil=='T')
this->tcivil_cnt++;
if(current->civil=='B')
this->bcivil_cnt++;
if(current->covid=='T')
this->tcovid_cnt++;
if(current->covid=='B')
this->bcovid_cnt++;
current =
current->next;
}
}
void vote::voter_stats()
{
cout << "Executing voter_stats" <<
endl;
temp = first->next;
int
ttotal_female=0,btotal_female=0,btotal_male=0,mtotal_male=0,ttotal_male=0;
int
btotal_Democrat=0,ttotal_Republican=0,ttotal_Democrat=0,btotal_Republican=0;
while (temp!= 0)
{
//
if(temp->gender=='F'&&temp->candidate=='T')
{
ttotal_female++;
}
if(temp->gender=='F'&&temp->candidate=='B')
{
btotal_female++;
}
if(temp->gender=='M'&&temp->candidate=='T')
{
ttotal_male++;
}
if(temp->gender=='M'&&temp->candidate=='B')
{
btotal_male++;
}
//
if(temp->registered=='D'&&temp->candidate=='T')
{
ttotal_Democrat++;
}
if(temp->registered=='D'&&temp->candidate=='B')
{
btotal_Democrat++;
}
if(temp->registered=='R'&&temp->candidate=='T')
{
ttotal_Republican++;
}
if(temp->registered=='R'&&temp->candidate=='B')
{
btotal_Republican++;
}
//
this->fgender_trump_per=(ttotal_female*100)/(fgender_cnt+mgender_cnt);
this->mgender_trump_per=(ttotal_female*100)/(fgender_cnt+mgender_cnt);
this->fgender_biden_per=(btotal_male*100)/(fgender_cnt+mgender_cnt);
this->mgender_biden_per=(btotal_male*100)/(fgender_cnt+mgender_cnt);
//
this->Democrat_trump_per=(ttotal_Democrat*100)/(dregistered_cnt+rregistered_cnt);
this->Republican_trump_per=(ttotal_Republican*100)/(dregistered_cnt+rregistered_cnt);
this->Democrat_biden_per=(btotal_Democrat*100)/(dregistered_cnt+rregistered_cnt);
this->Republican_biden_per=(ttotal_Republican*100)/(dregistered_cnt+rregistered_cnt);
//
this->economy_trump_per=(teconomy_cnt*100)/(teconomy_cnt+beconomy_cnt);
this->civil_trump_per=(tcivil_cnt*100)/(tcivil_cnt+bcivil_cnt);
this->covid_trump_per=(tcovid_cnt*100)/(tcovid_cnt+bcovid_cnt);
temp=temp->next;
}
}
void vote::print_stats()
{
system("cls");
cout <<"All Voter Data Entered" <<
endl;
current = first->next;
while (current!= 0)
{
cout <<"Gender:" <<
current->gender << " Registration:" <<
current->registered <<" Candidate:" <<
current->candidate << endl;
cout<<"Economy:"<<
current->economy << " Civil:"<< current->civil
<<" Covid:"<< current->covid <<
endl<<endl;
current = current->next;
}
(bcandidate_cnt>tcandidate_cnt)?cout<<"Biden
won":cout<<"Trump won"<<endl;
cout<<"Total number of
voters"<<this->dregistered_cnt+this->rregistered_cnt<<endl;
cout<<"Total number of female
voters"<<vfgender_cnt<<endl;
cout<<"Total number of male
voters"<<this->mgender_cnt<<endl;
cout<<"Total number of
Democrats"<<this->dregistered_cnt<<endl;
cout<<"Total number of
Republicans"<<this->rregistered_cnt<<endl;
cout<<"percent of female voters for
Trump"<<this->fgender_trump_per<<endl;
cout<<"percent of male voters for
Trump"<<this->mgender_trump_per<<endl<<endl;
cout<<"percent of female voters for
biden"<<this->fgender_biden_per<<endl<<endl;
cout<<"percent of male voters for
Trump"<<this->mgender_biden_per<<endl;
cout<<"percent of democrats voters for
Trump"<<fgender_trump_per<<endl;
cout<<"percent of republicans voters for
Trump"<<mgender_trump_per<<endl;
cout<<"percent of democrats voters for
biden"<<fgender_biden_per<<endl<<endl;
cout<<"percent of republicans voters for
Trump"<<mgender_biden_per<<endl;
cout<<"percent of voters thinking Trump has done better to
manage the economy"<<economy_trump_per<<endl;
cout<<" percent of voters thinking Trump has done better to
manage the civil unrest"<<civil_trump_per<<endl;
cout<<" percent of voters thinking Trump has done better to
manage the coronavirus"<<covid_trump_per<<endl;
}