Answered step by step
Verified Expert Solution
Question
1 Approved Answer
FILES BELOW: INPUT FILE 2: CS 202 - Assignment #1 Purpose: Refresh concepts regarding C++ simple 10. arrays, functions, and variable scoping, and compilation/linking. Wednesday
FILES BELOW:
INPUT FILE 2:
CS 202 - Assignment #1 Purpose: Refresh concepts regarding C++ simple 10. arrays, functions, and variable scoping, and compilation/linking. Wednesday (1/29) Due: Points: 25 Assignment: Write a program to process a file containing some formatted data for a local election. The input data file name is obtained from the command line. The input format for each line is: F=firstname, L=lastname, v=votes 99 LITTLE BUGS IN THE CODE 99 LITTLE BUGS TAKE ONE DOWN PATCH IT AROUND Read only valid lines into the array. The input file given to you is intentionally faulty. For reference, a correct line is as follows: F=John, L=Smith, V=3342 The line errors that your program needs to detect, are as follows: Incorrect token/ separator. For example: F=Stan, L=Smithv=4429 (comma missing). Lines with this error need to be ignored. Space in token. For example: F=Thomas, X=Anderson, v=1622. Lines with this error need to be read, fixed, data included in your data set. Empty lines should be ignored. IN THE CODE Submission: When complete, submit the ast01.cpp source file: A copy of the source file via the class web page (assignment submission link) by class time on the due date. You may re-submit as many times as desired. As per the syllabus, late assignments will be accepts with 24 hours of the original due date with reduced points. Specifically, 2% per hour which means 48% loss in 25 hours after which case it becomes 0 points. Please ensure that you follow the Required Coding Style & Documentation Revised Spring 2020. All program submissions must have the correct file type, be named correctly, and include the required comment block at the top of the main program file. Makefile: A simple makefile is provided. Assuming the program is named ast01.cpp, the following command is how to compile and link: ed@ed-vm$ make Which will create the executable file, ast01. Function Descriptions: The following are detailed descriptions of the required data structures. ARR_SIZE - size of the array. o The number of candidates in file will not exceed the ARR_SIZE. o When iterating over the candidates list, do not iterate over the entire array, but just over the records where data is filled in. o score (votes) - number of votes earned by candidate. o pScore - percentage score calculated using formula (1) Declare array of structs (size ARR_SIZE): struct Candidate { string first; string last; int votes; double pScore; The following are detailed descriptions of the required functions. void readFile(Candidate candidates []) - reads the input file, fills the candidates [] array. Hint: use substr and find functions. Set pScore to 0. void displayList(Candidate candidates []) - prints the array of Candidate structs. One candidate per one line, include all fields. Use setw() to display nice looking list. The filed sizes are 10 for each with two spaces between each on the display. void displayCandidate(Candidate cand) - prints the complete information about the candidate. . Candidate getWinner(Candidate candidates[]) - returns single struct element: candidate with highest score. Candidate getLast(Candidate candidates (1) - returns single struct element: candidate with lowest score. void sortByVotes(Candidate candidates []) - function sorts the candidates [] array by number of votes, the order in candidates[] array is replaced. void calculateScores(Candidate candidates[]) - calculates the percentage score for each candidate. Use the following formula: Sc pScore = X 100% ES=1 Sc where so is the score for candidate c and C is the number of candidates void roundScore(Candidate &cand) - updates single element, passed by reference. Function is rounding the pScore (example: 74.29% is rounded to 74%, 74.64% is rounded to 75%). ---------- Example Execution An example execution of the program is as follows: ed@vm ./ast01 elections1.txt ALL CANDIDATES: First Last Votes & Score ---------- John Smith 3342 13.838 Mary Blue 2003 8.298 Bill Warren 1588 6.578 Robert Powell 5332 22.078 Laura Rose 3341 13.838 Peter Green 3343 13.838 Thomas Anderson 1622 6.718 Catherine Johnson 2004 8.298 Barbara Moore 1589 6.588 ALL CANDIDATES: Pirst Last Bill Barbara Thomas Mary Catherine Laura John Peter Robert Warren Moore Anderson Blue Johnson Rose Smith Green Powell Votes ----- 1588 1589 1622 2003 2004 3341 3342 3343 5332 * Score ------- 6.578 6.58% 6.718 8.298 8.298 13.838 13.838 13.838 22.078 winner: FIRST NAME: Robert LAST NAME: Powell VOTES: 5332 * GAINED: 22.078 lowest score: FIRST NAME: Bill LAST NAME: Warren VOTES: 1588 % GAINED: 6.57% ALL CANDIDATES: Pirst Last Votes Bill Barbara Thomas Mary Catherine Laura John Peter Robert Warren Moore Anderson Blue Johnson Rose Smith Green Powell 1588 1589 1622 2003 2004 3341 3342 3343 5332 8 Score -------- 7.008 7.008 7.008 8.008 8.008 14.008 14.008 14.008 22.008 The I/O examples and spacing should be followed as per the example. Testing A script file to execute the program on a series of predefined inputs will be provided. Please follow the I/O examples. The test utility should be downloaded into the working directory. The script file will require execute privilege (i.e., chmod +x altst). The test script, named altst. here can be executed as follows: ed@vm$ ./altst ast01 The test script compares the program output to predefined expected output (based on the example I/O). Note, the ed@vm is the prompt on my machine. Code Skeleton: #includeStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started