Hello, I really need some help with my assignment any help is appreciated Assignment: Write a program to process a file containing some formatted data for a local election.   The input data file name...


Hello, I really need some help with my assignment any help is appreciated


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



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.






ARR_SIZE

size of the array.


The number of candidates in file will not exceed the

ARR_SIZE
.


When iterating over the candidates’ list, do not iterate over the entire array, but just over the records where data is filled in.




score


(votes)

– number of votes earned by candidate.




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 th




+
e 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[])
– 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:






where

sc


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.83%



      Mary        Blue        2003      8.29%



      Bill      Warren        1588      6.57%



    Robert      Powell        5332     22.07%



     Laura        Rose        3341     13.83%



     Peter       Green        3343     13.83%



    Thomas    Anderson        1622      6.71%



 Catherine     Johnson        2004      8.29%



   Barbara       Moore        1589      6.58%






ALL CANDIDATES:



     First        Last       Votes     % Score



----------  ----------  ----------  ----------



      Bill      Warren        1588      6.57%



   Barbara       Moore        1589      6.58%



    Thomas    Anderson        1622      6.71%



      Mary        Blue        2003      8.29%



 Catherine     Johnson        2004      8.29%



     Laura        Rose        3341     13.83%



      John       Smith        3342     13.83%



     Peter       Green        3343     13.83%



    Robert      Powell        5332     22.07%






winner:



FIRST NAME: Robert



LAST NAME:  Powell



VOTES:      5332



% GAINED:   22.07%






lowest score:



FIRST NAME: Bill



LAST NAME:  Warren



VOTES:      1588



% GAINED:   6.57%









ALL CANDIDATES:



     First        Last       Votes     % Score



----------  ----------  ----------  ----------



      Bill      Warren        1588      7.00%



   Barbara       Moore        1589      7.00%



    Thomas    Anderson        1622      7.00%



      Mary        Blue        2003      8.00%



 Catherine     Johnson        2004      8.00%



     Laura        Rose        3341     14.00%



      John       Smith        3342     14.00%



     Peter       Green        3343     14.00%



    Robert      Powell        5332     22.00%





The I/O examples and spacing should be followed as per the example.







Code Skeleton:



#include


#include


#include


#include


#include


#include




using
namespace
std;



const int ARR_SIZE
=
100;



void readFile(string,
Candidate[]);


void displayList(Candidate[]);


void sortByVotes(Candidate[]);


void displayCandidate(Candidate);


Candidate getWinner(Candidate[]);


Candidate getLast(Candidate[]);


void calculateScores(Candidate[]);


void roundScores(Candidate[]);






int main(int argc, char *argv[])
{



}



void readFile(string inFileName,
Candidate candidates[])
{



}



void displayList(Candidate candidates[])
{



}



void sortByVotes(Candidate candidates[])
{



}



void displayCandidate(Candidate cand)
{



}



Candidate getWinner(Candidate candidates[])
{



}



Candidate getLast(Candidate candidates[])
{



}



void calculateScores(Candidate candidates[])
{



}



void roundScores(Candidate candidates[])
{



}








May 18, 2022
SOLUTION.PDF

Get Answer To This Question

Submit New Assignment

Copy and Paste Your Assignment Here