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

C++Program 3 Input: The inputs are the two files ev10.csv and elect12.csv File 1

ID: 3577333 • Letter: C

Question

C++Program 3

Input:

The inputs are the two files ev10.csv and elect12.csv

File 1: ev10.csv

55    CA
38    TX
29    FL
29    NY
20    IL
20    PA
18    OH
16    GA
16    MI
15    NC
14    NJ
13    VA
12    WA
11    AZ
11    IN
11    MA
11    TN
10    MD
10    MN
10    MO
10    WI
9     AL
9     CO
9     SC
8     KY
8     LA
7     CT
7     OK
7     OR
6     AR
6     IA
6     KS
6     MS
6     NV
6     UT
5     NE
5     NM
5     WV
4     HI
4     ID
4     ME
4     NH
4     RI
3     AK
3     DE
3     DC
3     MT
3     ND
3     SD
3     VT
3     WY

File 2: elect12.csv

795696      1255925     22717 2074338     AL
122640      164676      13179 300495      AK
1025232     1233654     40368 2299254     AZ
394409      647744      27315 1069468     AR
7854285     4839958     344304      13038547    CA
1323102     1185243     61177 2569522     CO
905083      634892      18985 1558960     CT
242584      165484      5853 413921      DE
267070      21381 5313 293764      DC
4237756     4163447     72976 8474179     FL
1773827     2078688     47535 3900050     GA
306658      121015      7024 434697      HI
212787      420911      18576 652274      ID
3019512     2135216     87286 5242014     IL
1152887     1420543     51104 2624534     IN
822544      730617      29019 1582180     IA
440726      692634      26611 1159971     KS
679370      1087190     30652 1797212     KY
809141      1152262     32662 1994065     LA
401306      292276      19598 713180      ME
1677844     971869      57614 2707327     MD
1921290     1188314     58163 3167767     MA
2564569     2115256     51136 4730961     MI
1546167     1320225     70169 2936561     MN
562949      710746      11889 1285584     MS
1223796     1482440     51087 2757323     MO
201839      267928      14281 484048      MT
302081      475064      17234 794379      NE
531373      463567      19978 1014918     NV
369561      329918      11493 710972      NH
2125101     1477568     37623 3640292     NJ
415335      335788      32635 783758      NM
4485741     2490431     104987      7081159     NY
2178391     2270395     56586 4505372     NC
124827      188163      9637 322627      ND
2827709     2661437     91701 5580847     OH
443547      891325      0     1334872     OK
970488      754175      64607 1789270     OR
2990274     2680434     82962 5753670     PA
279677      157204      9168 446049      RI
865941      1071645     26532 1964118     SC
145039      210610      8166 363815      SD
960709      1462330     35538 2458577     TN
3308124     4569843     115884      7993851     TX
251813      740600      25027 1017440     UT
199239      92698 7353 299290      VT
1971820     1822522     60147 3854489     VA
1755396     1290670     79450 3125516     WA
238269      417655      14514 670438      WV
1620985     1407966     39483 3068434     WI
69286 170962      8813 249061      WY

Assignment:

To do an object oriented implementation, you should first identify your ADTs. At a minimum, you should have the following ADTs:

The electoral vote input file. This ADT should include as private data members all of the information in the input file. Note that you may have vectors/etc as elements of the class. You are required to have an overloaded >> function which inputs data from the file into this class. Additionally, your class should have a constructor that takes a filename (string) as argument to initialize the members.

The analog of the above for the election results input file.

Any other ADTs you wish to have.

Determine and implement suitable public and private functions for all classes. Note that you are NOT allowed to break the object oriented philosophy and access private members directly, and thus should have accessor/mutator functions for all relevant data.

Place each of the two required classes in their own files. You may choose to put additional classes in one file or by themselves, though a file that covers too many separate concerns is bad structure (also see grading below). Also write a makefile to create your executable file.

Task:

Print the national results, along with the [unweighted] average margin of victory for the winner (P). For example (in a 3 state nation), if P had won the popular vote by 10, 20, and -15 points, P's average margin would be 5%. Also determine the states where P had the best and worst winning margins.

Print a message to the screen as follows (N should be a double):

P won the national election with N% of the popular vote and a margin of N points.
P received N electoral votes.
P had an unweighted average victory margin of N points.
P's best state was XX, where he won by N points.
P's worst state was XX, where he lost by N points.

These are the exact same outputs

Explanation / Answer

import java.io.*;

import java.util.*;

public category ID3

the category to represent a knowledge purpose consisting of numAttributes values

of attributes */

class DataPoint

};

/* the category to represent a node within the decomposition tree.

*/

class TreeNode

};

TreeNode root = new TreeNode();

public int getSymbolValue(int attribute, String symbol)

return index;

}

public int []getAllValues(Vector information, int attribute) {

Vector values = new Vector();

int num = information.size();

for (int i=0; i< num; i++) {

DataPoint purpose = (DataPoint)data.elementAt(i);

String image =

(String)domains[attribute].elementAt(point.attributes[attribute] );

int index = values.indexOf(symbol);

if (index < 0)

}

int []array = new int[values.size()];

for (int i=0; i< array.length; i++) {

String image = (String)values.elementAt(i);

array = domains[attribute].indexOf(symbol);

}

values = null;

return array;

}

public Vector getSubset(Vector information, int attribute, int value) set = new Vector();

int num = information.size();

for (int i=0; i< num; i++) {

DataPoint purpose = (DataPoint)data.elementAt(i);

if (point.attributes[attribute] == value) set.addElement(point);

}

return subset;

}

public double calculateEntropy(Vector data) {

int numdata = information.size();

if (numdata == 0) come 0;

int attribute = numAttributes-1;

int numvalues = domains[attribute].size();

double total = 0;

for (int i=0; i< numvalues; i++) {

int count=0;

for (int j=0; j< numdata; j++) {

DataPoint purpose = (DataPoint)data.elementAt(j);

if (point.attributes[attribute] == i) count++;

}

double chance = one.*count/numdata;

if (count > 0) total += -probability*Math.log(probability);

}

return sum;

}

public mathematician alreadyUsedToDecompose(TreeNode node, int attribute)

if (node.parent == null) come false;

return alreadyUsedToDecompose(node.parent, attribute);

}

public void decomposeNode(TreeNode node) {

double bestEntropy=0;

boolean selected=false;

int selectedAttribute=0;

int numdata = node.data.size();

int numinputattributes = numAttributes-1;

node.entropy = calculateEntropy(node.data);

if (node.entropy == 0) return;

for (int i=0; i< numinputattributes; i++) {

int numvalues = domains.size();

if ( alreadyUsedToDecompose(node, i) ) continue;

double averageentropy = 0;

for (int j=0; j< numvalues; j++) set = getSubset(node.data, i, j);

if (subset.size() == 0) continue;

double subentropy = calculateEntropy(subset);

averageentropy += subentropy *

subset.size();

}

averageentropy = averageentropy / numdata; //

Taking the weighted average

if (selected == false) else {

if (averageentropy < bestEntropy)

}

}

if (selected == false) return;

int numvalues = domains[selectedAttribute].size();

node.decompositionAttribute = selectedAttribute;

node.children = new TreeNode [numvalues];

for (int j=0; j< numvalues; j++)

for (int j=0; j< numvalues; j++)

node.data = null;

}

public int readData(String filename) throws Exception catch ( Exception e) {

System.err.println( "Unable to open information file: " + computer file name + " " + e);

return 0;

}

BufferedReader bin = new BufferedReader(new InputStreamReader(in) );

String input;

while(true) {

input = bin.readLine();

if (input == null) {

System.err.println( "No information found within the information file: " + computer file name +

" ");

return 0;

}

if (input.startsWith("//")) continue;

if (input.equals("")) continue;

break;

}

StringTokenizer tokenizer = new StringTokenizer(input);

numAttributes = tokenizer.countTokens();

if (numAttributes <= 1) {

System.err.println( "Read line: " + input);

System.err.println( "Could not obtain the names of attributes within the

line");

System.err.println( "Expecting a minimum of one input attribute and one

output attribute");

return 0;

}

domains = new Vector[numAttributes];

for (int i=0; i < numAttributes; i++) domains = new Vector();

attributeNames = new String[numAttributes];

for (int i=0; i < numAttributes; i++)

while(true)

root.data.addElement(point);

}

bin.close();

return 1;

}

public void printTree(TreeNode node, String tab) ME = new ID3();

int standing = Pine Tree State.readData("c:\in.txt");

if (status <= 0) return;

me.createDecisionTree();

}

}

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