Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please Use C++ as programming language but I need the program to be divided into

ID: 3799932 • Letter: P

Question

Please Use C++ as programming language but I need the program to be divided into header and source file (.h and .cpp) (Use Visual Studios) Thank you!

(Polling) The Internet and the web enable people to network, join a cause, and so on. The presidential candidates in 2012 used the Internet to get out their messages and raise money. In this exercise, you'll write a polling program that allows users to rate five social-consciousness issues from 1 to 10 (most important). Pick five causes (e.g., political issues, global environmental issues. Use a one- dimensional string array topics to store the causes. To summarize the survey responses, use a 5-row, 10-column two-dimensional array responses (of type int), each row corresponding to an element in the topics array When the program runs, it should ask the user to rate each issue. Have your friends and family respond to the survey. Then have the program display a summary of the results, including: a) Atabular report with the five topics down the left side and the 10 ratings across the top, listing in each column the number of ratings received for each topic. b) To the right of each row, show the average of the ratings for that issue. c) Which issue received the highest point total? Display both the issue and the point total. d) Which issue received the lowest point total? Display both the issue and the point total.

Explanation / Answer

//poll.h
#include<iostream>
#include<stdio.h>
#include<string>

using namespace std;
class Polls
{
public:
Polls();
void conduct(); // conducts voting for a candidate
void printDetails(); // prints the tally for the votes conducted so far
void printHighest(); // prints the issue with the highest score
void printLowest(); // prints the issue with lowest score.
void printAverage(); // prints the average votes received by each issue.


string issue[6];
int votes[6][11];
int sum[6];
int voterCount;

};

/*######################## poll.cpp ###############3*/

#include<iostream>
#include<stdio.h>
#include<string>
#include "poll.h"

Polls::Polls()
{
/*issue[0] = "1";
issue[1] = "2";
issue[2] = "3";
issue[3] = "4";
issue[4] = "5";
*/
for(int i = 1; i <= 5; ++i) { // Entering the issues
cout <<" Enter issue "<<i <<endl;
cin >> issue[i - 1];
}

for(int i = 0; i < 5; ++i) // initializing the variables
for(int j = 0; j <= 10; ++j)
Polls::votes[i][j] = 0;
for(int i = 0; i < 5; ++i)
Polls::sum[i] = 0;
voterCount = 0;

}

void Polls::conduct()
{
int tmp;

cout <<"Welcome. Please rate the following issues from 1 to 10(being important) ";
voterCount++;
cout <<"For issue "<<issue[0]<<endl;
l0: ;
cin >> tmp;
if(tmp < 1 || tmp > 10) {
cout <<"Enter a number between 1 to 10 ";
goto l0;
}
votes[0][tmp]++;
sum[0] += tmp;

cout <<"For issue "<<issue[1]<<endl;
l1: ;
cin >> tmp;
if(tmp < 1 || tmp > 10) {
cout <<"Enter a number between 1 to 10 ";
goto l1;
}
votes[1][tmp]++;
sum[1] += tmp;

cout <<"For issue "<<issue[2]<<endl;
l2: ;
cin >> tmp;
if(tmp < 1 || tmp > 10) {
cout <<"Enter a number between 1 to 10 ";
goto l2;
}
votes[2][tmp]++;
sum[2] += tmp;

cout <<"For issue "<<issue[3]<<endl;
l3: ;
cin >> tmp;
if(tmp < 1 || tmp > 10) {
cout <<"Enter a number between 1 to 10 ";
goto l3;
}
votes[3][tmp]++;
sum[3] += tmp;

cout <<"For issue "<<issue[4]<<endl;
l4: ;
cin >> tmp;
if(tmp < 1 || tmp > 10) {
cout <<"Enter a number between 1 to 10 ";
goto l4;
}
votes[4][tmp]++;
sum[4] += tmp;

}

void Polls::printDetails()
{
cout <<" ############### Votes Tally ################## ";
for(int i = 0; i < 5; ++i) {
cout <<issue[i] <<" -> ";
for(int j = 1; j <= 10; ++j)
cout << votes[i][j] <<" ";
cout << endl;
}

}

void Polls::printAverage()
{
cout <<" ############### Average Votes Tally ################## ";
for(int i = 0; i < 5; ++i)
cout << issue[i] <<" -> "<< (double)sum[i] / (1.0 * voterCount)<<endl;

}

void Polls::printHighest()
{

int maxx = sum[0];
int pr = 0;
for(int i = 0; i < 5; ++i) {
if(sum[i] > maxx) {
maxx = sum[i];
pr = i;
}
}
cout <<"Maximum votes are collected by issue "<<issue[pr] << endl;
}
void Polls::printLowest()
{
int minn = sum[0];
int pr = 0;
for(int i = 0; i < 5; ++i) {
if(sum[i] < minn) {
minn = sum[i];
pr = i;
}
}
cout <<"Minimum votes are collected by issue "<<issue[pr] << endl;
}


int main()
{
Polls obj;

cout <<"Enter 1 for voting. Enter 2 for printing the current tally. Enter 3 for printing the average tally. Enter 4 for printing the maximum voted issue. Enter 5 for least voted issue. Enter any other character to exit. ";
int choice;
cout << endl << endl;

while(true) {
cout <<"Enter choice ";
cin >> choice;

if(choice == 1) {
obj.conduct();
} else if(choice == 2) {
obj.printDetails();
} else if(choice == 3) {
obj.printAverage();
} else if(choice == 4) {
obj.printHighest();
} else if(choice == 5) {
obj.printLowest();
} else
break;
}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote