Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Language is ADA You will write a program which compares the opinions of a voter to the opinions of a group of political candidates, and

Language is ADA

You will write a program which compares the opinions of a voter to the opinions of a group of political candidates, and which finds the candidates who best match the voter's opinions.

The input to your program will be a list of answers that a voter and the candidates have given to 10 yes/no questions. An answer of 1 means yes, -1 means no, and 0 means that the person isundecided.

The input will begin with a list of 10 integers (1, 0, or -1), indicating the answers given by the voter. This will be followed by a sequence of entries of this form:

The name of the candidate. A list of 10 integers (1, 0, or -1), indicating the answers given by the candidate.

For each candidate, the program will compute an agreement score as follows:

agreement_score = (the number of questions for which the voter and the candidate gave the same nonzero answer) - (the number of questions for which the voter and the candidate gave different nonzero answers)

Questions on which either the voter or the candidate was undecided (answer = 0) do not contribute toward the agreement score.

Example: If the voter gave answers

1 1 -1 0 0 1 1 1 1 -1 

and the candidate gave answers

0 1 1 1 0 1 1 1 1 -1

then the agreement score is 5: the voter and candidate agree on 6 questions (the second question and the last five questions), and they disagree on one (the third question); 6 - 1 = 5. The first, fourth, and fifth questions do not contribute anything toward the score, since they involveundecided answers.

The output of the program will be a list of the names of the candidates who have the highest agreement score. That is, find the highest agreement score in the group, and then report the names of all the candidates who have that score.

Sample calculations

Example 1:

Note: In the input, the first line is the voters' answers, and the remaining lines are for the candidates.

Input:

0 0 0 1 1 1 -1 -1 -1 1 Adams 1111111111 Grant -1-1-1-1-1-1-1-1-1-1 Polk 1-1 1-1 1-1 1-1 1-1 Jackson 1 0 1 0 1 0 1 0 1 0 Taft 0-1 0-1 0-1 0-1 0-1 Ford 1111000000 Madison 0 0 0 1 -1 0 0 -1 1 1

Output:

Adams, Ford, Madison 

Rationale: These are the agreement scores for the candidates:

Adams: Grant: Polk: Jackson: Taft: Ford: Madison: 

4-3=1 3-4=-1 2-5=-3 1-2=-1 1-3=-2 1-0=1 3-2= 1

The highest agreement score is 1. Adams, Ford, and Madison all have this agreement score.

Example 2:

Input:

-1 -1 -1 -1 -1 1 1 1 1 1 Wilson -1-1-1-1-1-1-1-1-1-1 Taylor -1 -1 -1 1 1 1 1 1 1 1 Monroe -1-1-1 1 1-1-1 1 1 1

Output:

Taylor

Rationale: These are the agreement scores for the candidates:

Wilson: 5 - 5 = 0 Taylor: 8 - 2 = 6 Monroe: 6 - 4 = 2 

The highest agreement score is 6. Taylor has this score.

Write an Ada program to solve the homework problem described above.

The input will contain a line of 10 integers (each 1, 0, or -1), representing the opinions of the voter. This is followed by a positive integer N on a line by itself, indicating the number of candidates. This is followed by N pairs of lines: The name of the candidate is a single integer on a line by itself. Immediately following is a line containing 10 integers (each 1, 0, or -1), representing the opinions of that candidate.

You are guaranteed that there will be at least one candidate and that there will be no more than 25 candidates.

You are also guaranteed that the names of the candidates will be consecutive integers, starting at 1. That is, the first candidate will be named 1, the second is 2, and so on.

The output will be the name(s) of the candidate(s) with the highest agreement score.

Examples:

Input:

0 0 0 1 1 1 -1 -1 -1 1 7 1 1111111111 2

-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 3 1-1 1-1 1-1 1-1 1-1 4 1010101010 5

0-1 0-1 0-1 0-1 0-1 6 1111000000 7

0 0 0 1 -1 0 0 -1 1 1 

Output:

1 6 7

Input:

-1 -1 -1 -1 -1 1 1 1 1 1 3 1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 2 
-1 -1 -1 1 1 1 1 1 1 1 3 -1 -1 -1 1 1 -1 -1 1 1 1 

Output:

2

Assume that the input will be correctly formatted; your program does not need to check for formatting errors.

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

Step: 3

blur-text-image

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

Practical Database Programming With Visual C# .NET

Authors: Ying Bai

1st Edition

0470467274, 978-0470467275

More Books

Students also viewed these Databases questions