Storm Trooper Recruitment (using parallel arrays)
You will need to declare the following arrays:
string names[SIZE] - stores the names of all the candidates
bool targets[SIZE][TRGTS] - a 2D array that stores each candidates successful/failed target at- tempts, i.e. targets, targets, targets,...,targets[TRGTS - 1] denotes which targets the first candidate hit/missed, TRGTS will be a constant with the value of 10
double targetWeights[TRGTS] - stores the weights for each target to be used to compute each can- didates overall scores
double scores[SIZE] - stores the score of each candidate (score is computed using the
Where SIZE is a constant that contains 20 (you can assume that the file will not have more than 20 entries).
You will also need to implement the following functions
int readData(string, bool[TRGTS], double) - reads in the stormtroopers from a data file, the function prompts for an input file name and re-prompts if file not found, then reads each line and stores the data into the correct array at the appropriate location, you will maintain a counter that counts the number of lines in the storm trooper file, the file format is
NAME T1 T2 T3 T4 T5 T6 T7 T8 T9 T10
Where each Ti will be a string that contain ”Hit” or ”Miss” (might need to format), and so you will store true for hit and false for miss into the correct position of the bool matrix.
Additionally, this function will prompt and read for a second input file, this second file contains TRGTS
amount of doubles to be stored in the double array (the third parameter)
After everything has been read from both files, return the counter that was used in the first file that denotes the amount of stormtroopers read.
double computeScore(bool[TRGTS], double, int) - returns the score of the stormtrooper re- sults, takes in the targets array, the scores array, and the index of the stormtrooper whose score the function is trying to compute, to compute the score, you multiply the value at the same respective index from the double array with the bool array
void outputStormTroopers(string, bool[TRGTS], double, int) - outputs all the storm troopers in the list nicely formatted (refer to the sample output), function takes in the names of the stormtroopers, all the stormtroopers target data, overall score, and the amount of stormtroopers
void outputOneStormTrooper(string, bool, double) - outputs a single storm trooper, function takes the name, target data, and score for a single storm trooper, notice that the bool array is a one dimensional array in this function scope
Contents of main
Allocate your variables, constants, arrays, and any other variables you might use
Call readData function and assign the value it returns into a variable, say amtStormTroopers
Use a counter controlled loop that runs amtStormTroopers number of times, the body of the loop will call computeScore which will be assigned into the correct position of scores array
Call outputStormTroopers function to output all the storm troopers
Find the top 3 stormtroopers (the 3 storm troopers with the highest scores), YOU CANNOT SORT THE ARRAY FIRST, AND TO GET FULL CREDIT, YOU MUST HAVE JUST ONE LOOP, IF YOU NEED MORE THAN ONE LOOP YOU MIGHT HAVE A SLIGHT PENALTY, HOWEVER SORTING THE ARRAY WILL BE A MUCH LARGER PENALTY
Once the top 3 stormtroopers are found, output them, use the outputOneStormTrooper function 3 times
You must write the functions listed earlier, you cannot modify the function prototypes, you may add additional functions if needed however
$ g ++ Assignment.cpp - Wall - Wextra - pedantic$ ./ a. out
Please enter storm trooper results file : storm Trooper Invalid file !
Please enter storm trooper results file : StarWars . txt Invalid file !
Please enter storm trooper results file : Storm TrooperData . txt Stormtrooper data read successfully
Enter target weights: targets. txt Invalid file!
Enter target weights: Storm TroopersAlwaysMiss . txt Invalid file!
The ready solutions purchased from Library are already used solutions. Please do not submit them directly as it may lead to plagiarism. Once paid, the solution file download link will be sent to your provided email. Please either use them for learning purpose or re-write them in your own language. In case if you haven't get the email, do let us know via chat support.
Get Free Quote!
256 Experts Online