Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

the goal is to write a C++ function that will provide a simplified form of poll aggregation. You will be given four arrays, all of

the goal is to write a C++ function that will provide a simplified form of poll aggregation. You will be given four arrays, all of the same length, representing:

  • the polling history for Party A (numbers between 0 and 100%),

  • the polling history for Party B (numbers between 0 and 100%),

  • the polling history for Party C (numbers between 0 and 100%) and

  • the weight that should be given to each poll.

These four arrays correspond to columns on the Calculated Politics website(https://www.calculatedpolitics.com/project/2019-canada-election/). For example, the polling results for Week 3 of an election campaign are found at index 3 in each of the first three arrays; the importance of that poll is found at index 3 of the fourth array. Given this information, your function should do two things:

  1. Compare the poll-by-poll results and store a character for the leading party in a fifth array that will be provided to you. For example, if partyA[3] is greater than partyB[3] and partyC[3], you should store an 'A' character in results[3].

  2. Calculate an overall result using a weighted sum of each partys results. For example, if the weighted sum of party As results is higher than that of parties B and C, your function should return an 'A'.

image text in transcribed

* Predict the winner of an election among three parties, using a weighted * aggregation of historic polls. * @param[in] a * @param[in] b * @param[in] C * @param[in] pollWeights how much weight is placed on each poll the poll-by-poll results for Party A [%] the poll-by-poll results for Party B [%] the poll-by-poll results for Party C [%] Opre sum of pollWeights is 1 * @param[out] *@param *ereturns resultspoll-by-poll expected winner len overall predicted winner ('A, B' or 'C) @post every element in result is A Bor 'C length of all arrays passed to the function char predictWinner (const double a[], const double b[l, const double c[l, const double pollWeights[], char results[], int len): * Predict the winner of an election among three parties, using a weighted * aggregation of historic polls. * @param[in] a * @param[in] b * @param[in] C * @param[in] pollWeights how much weight is placed on each poll the poll-by-poll results for Party A [%] the poll-by-poll results for Party B [%] the poll-by-poll results for Party C [%] Opre sum of pollWeights is 1 * @param[out] *@param *ereturns resultspoll-by-poll expected winner len overall predicted winner ('A, B' or 'C) @post every element in result is A Bor 'C length of all arrays passed to the function char predictWinner (const double a[], const double b[l, const double c[l, const double pollWeights[], char results[], int len)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Graph Databases In Action

Authors: Dave Bechberger, Josh Perryman

1st Edition

1617296376, 978-1617296376

More Books

Students also viewed these Databases questions

Question

=+Where do you want to live and work?

Answered: 1 week ago