This week, we'll be looking at how approval ratings work for political polls. I've attached a file that contains the results of a fictional Gallup poll about the approval rating for the president. The...

1 answer below »

This week, we'll be looking at how approval ratings work for political polls. I've attached a file that contains the results of a fictional Gallup poll about the approval rating for the president. The file contains the information for 100 people, including the person's name, party, income and rating. Since politial analysts are always interested in demographics (a demographic is a certain group of people), your job this week is to compute the approval ratings for a few different demographics. The groups of people that were interested in are those that are Republicans vs Democrats, and those people that make more or less than 30,000 dollars per year. Since we'll be looking at 2x2 different groups, there will be 4 total demographics that we look at. For each demographic, richer Democrats, poorer Democrats, richer Republicans, and poorer Republicans, you'll compute the AVERAGE approval rating for the president. Recall that the average is computed by adding up the total of all the ratings for a group and then dividing by the number of people that you included in the group.  Your program should work as follows. First, you need to prompt for and input a file path to the poll file. Next, you'll check to make sure that the file at that path opened correctly. If not, please report an appropriate error message and quit the program. Then, echo the contents of the file to the screen. Finally, display the averages for each of the four demographics required. The numbers you're looking for are:  Republicans under $30000: 51% Republicans over  $30000: 65% Democrats   under $30000: 40% Democrats   over  $30000: 45%  Notice that the numbers in the file are from 0-5 (since the question for the poll is worded as "strongly approve, approve, slightly approve, slightly disapprove, disapprove, or strongly disapprove") but our numbers are percentages from 1-100. To convert from the range from 0-5 to a percentage, simply multiply the result by 20.
Answered Same DayJul 15, 2021

Answer To: This week, we'll be looking at how approval ratings work for political polls. I've attached a file...

Shivani answered on Jul 17 2021
146 Votes
#include
#include
#include
using namespace std;
int main(void)
{

    // variables for storing the filename
    // and accessing the file
    char filename[50];
    ifstream inputfile;
    string fname, lname;
    string party;
    int income, rating;
    
    // variables for storing the statistics
    int rich_dem_count=0;
    int rich_dem_sum=0;
    int poor_dem_count=-0;
    int poor_dem_sum=0;
    int rich_rep_count=0;
    int rich_rep_sum=0;
    int poor_rep_count=0;
    int poor_rep_sum=0;
    
    // Getting user input for file name
    cout << "Enter the file name: ";
    cin >> filename;
    
    // open the file for reading
    inputfile.open(filename, ios::in);
    // test if file could be opened...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here