Question

In: Computer Science

You are to use your code from part A of this assignment and add to it....

You are to use your code from part A of this assignment and add to it. In this part of the project, you are to do the following:
1. In the count_voters function you are to add code to:
• Count the number of votes for Trump
• Count the number of votes for Biden
• Count the number of females
• Count the number of males
• Count the number of Democrats
• Count the number of Republicans
• Count the number of females for Trump
• Count the number of females for Biden
• Count the number of males for Trump
• Count the number of males for Biden
• Count the number of Democrats for Trump
• Count the number of Republicans for Biden
• Count the number of voters who think Trump has done a better job to manage the economy
• Count the number of voters who think Trump has done a better job to manage the civil unrest
• Count the number of voters who think Trump has done a better job to manage the coronavirus
2. In the voter_stats function you are add code to calculate the following:
• percent of female voters for Trump
• percent of female voters for Biden
• percent of male voters for Trump
• percent of male voters for Biden
• percent of Democrats voting for Trump
• percent of Republicans voting for Biden
• percent of voters thinking Trump has done better to manage the economy
• percent of voters thinking Trump has done better to manage the civil unrest
• percent of voters thinking Trump has done better to manage the coronavirus
3. In the print_stats function, you are to add code to also print the following:
• Print the Candidate who won
• Total number of voters
• Total number of female voters
• Total number of male voters
• Total number of Democrats
• Total number of Republicans
• percent of female voters for Trump
• percent of female voters for Biden
• percent of male voters for Trump
• percent of male voters for Biden
• percent of Democrats voting for Trump
• percent of Republicans voting for Biden
• percent of voters thinking Trump has done better to manage the economy
• percent of voters thinking Trump has done better to manage the civil unrest
• percent of voters thinking Trump has done better to manage the coronavirus
All of the required data, counts, percentages etc… are to be private members of the class, NOT the linked list. Therefore, no data will be passed among functions in this code.
Be careful to define the data correctly, counts are integer and percentages are double. You must also use variable names that are easy to follow as to what they mean. For example, call the females for Trump, int trump_females;
You could have multiple loops within the count_voter function to search the linked list multiple times. There is code on blackboard to show how to search the list. You should do one count at a time and print it in the print_stats function to make sure it works. Then move on to the next one.
You are to copy your code to word along with a screen print of the final output copied to the same word document.

Here is part A:

#include <iostream>
#include <string>
using namespace std;

class vote
{
private:
struct votenode
{
char candidate;
char registered;
char gender;
char covid;
char economy;
char civil;
votenode *next;
};
votenode *first, *previous, *current;

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()
{
string more = "yes";
first = new votenode;
previous = first;
while (more == "yes")
{
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 ";
cin >>more;
}//END OF WHILE LOOP
}//END OF READ_VOTER

void vote::count_voters()
{
cout << "Executing count_voter" << endl;
}

void vote::voter_stats()
{
cout << "Executing voter_stats" << endl;
}

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;
}
}

Solutions

Expert Solution

#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;


}


Related Solutions

For this programming assignment, you will use your previous code that implemented a video game class...
For this programming assignment, you will use your previous code that implemented a video game class and objects with constructors. Add error checking to all your constructors, except the default constructor which does not require it. Make sure that the high score and number of times played is zero or greater (no negative values permitted). Also modify your set methods to do the same error checking. Finally add error checking to any input requested from the user. #include <iostream> #include...
For Part 2 of this assignment, you will use the “Assignment 1 – Linear Kinematics Data”...
For Part 2 of this assignment, you will use the “Assignment 1 – Linear Kinematics Data” excel file. In the data set you are provided with vertical position and time data for a person’s vertical center of mass motion for an unspecified movement task. You will utilize excel in all (well, some…) of its glory to calculate the vertical velocity and vertical acceleration data from the position and time data provided in the excel file. Again you will use the...
Also please add comments on the code and complete in C and also please use your...
Also please add comments on the code and complete in C and also please use your last name as key. The primary objective of this project is to increase your understanding of the fundamental implementation of Vigenere Cipher based program to encrypt any given message based on the Vignere algorithm. Your last name must be used as the cipher key. You also have to skip the space between the words, while replicating the key to cover the entire message. Test...
C++ CODE Change your code from Part A to now present a menu to the user...
C++ CODE Change your code from Part A to now present a menu to the user asking them for an operation to perform on the text that was input. You must include the following functions in your code exactly as provided. Additionally, you must have function prototypes and place them above your main function, and the function definitions should be placed below the main function. Your program should gracefully exit if the user inputs the character q or sends the...
In this assignment, you will use a LOC counting tool to count the lines of code...
In this assignment, you will use a LOC counting tool to count the lines of code of the tool itself. 1. There are several open source free tools for LOC counting such as CLOC and SLOC. 2. Run the tool to count the lines of code of the source files of the tool (usually in the src directory). 3. Submit a report which includes: a. Description of the tool 1. Name 2. Creator 3. Language(s) it is written 4. URL...
Part 2: Use MySQL Workbench to add a table to your database on the class server...
Part 2: Use MySQL Workbench to add a table to your database on the class server and name the table “Person”. Include these fields in the Person table: Field Name Description Data Type Sample Value LoginID User’s login name varchar(10) Bob FirstName User’s first name varchar(50) Bob LastName User’s last name varchar(50) Barker picUrl Filename of the user’s picture varchar(50) bob.gif Bio User’s biography varchar(255) Bob is the best! LoginID should be the Primary Key of the table. Add at...
make multiply function with ‘add’ command, Convert to mips code Don’t use ‘mult’ Use 'add' multiple...
make multiply function with ‘add’ command, Convert to mips code Don’t use ‘mult’ Use 'add' multiple times Get input from key-board and display the result in the console window
The first part of this lab is making your stack generic. Take the code from your...
The first part of this lab is making your stack generic. Take the code from your working StringStack class and paste it into the GenericStack class. Change the name of the constructors to match the new name of the class (this has been done to this point), then modify the whole class so it uses generics, and can store any type that a programmer asks for. Until you successfully complete this, the main method will give you nasty compiler errors....
USE GENERICS TO WRITE THE JAVA CODE FOR THIS ASSIGNMENT In this assignment, rewrite two of...
USE GENERICS TO WRITE THE JAVA CODE FOR THIS ASSIGNMENT In this assignment, rewrite two of the following sorting methods (Insertion Sort, Selection Sort, Quick Sort, and Merge Sort) to sort ArrayList of objects using Comaprable interface. (60 points)
Project 10-1 Convert lengths In this assignment, you’ll add code to a form that converts the...
Project 10-1 Convert lengths In this assignment, you’ll add code to a form that converts the value the user enters based on the selected conversion type. The application should handle the following conversions: From To Conversion Miles - Kilometers: 1 mile = 1.6093 kilometers Kilometers - Miles: 1 kilometer = 0.6214 miles Feet - Meters: 1 foot = 0.3048 meters Meters - Feet: 1 meter = 3.2808 feet Inches - Centimeters: 1 inch = 2.54 centimeters Centimeters - Inches: 1...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT