C++Program 3 Input: The inputs are the two files ev10.csv and elect12.csv File 1
ID: 3576026 • 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
#include #include #include #include int main() { using namespace std; ifstream in; in.open("Data.txt"); assert(in.is_open()); vector values; const int MAXSIZE = 4; char thisVal[MAXSIZE]; while(in.getline(thisVal,MAXSIZE,',')) { values.resize(values.size() + 1); values.back() = new char[MAXSIZE]; strcpy(values.back(), thisVal); } in.close(); for (char* cp: values) coutRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.