I would really like help with this program, as I can't figure out what to do. I've tried searching online for answers or something that would point me in the right direction, but this is sort of difficult for me since I'm just learning how to code. I would greatly appreciate it!
You are to write a program that will help Santa process the work done by his elves. You will be using a data file called elves.dat. There will be one line for each elf. That line will contain the name of the elf and the number of toys the elf made. You are to read from the file and place the values in parallel arrays. You do not know how many elves there are so you must read until the end of file and count. You will need a third parallel array of strings to record a rating for each elf. You should declare arrays with the capacity for 50 components.
The program should read into the arrays. It should look at the number of toys made by each elf and record a rating in a parallel array. The table below determines the ratings. The program should then print out the arrays side by side in neat, labeled columns. It should print out the total number of toys made by the elves, the number of elves who made more than 500 toys, the name of the elf who made the most toys, and the name of the elf who made the least toys. Each calculation should have a function of its own. NO output should be done in functions that do calculations. All output should be done in one output function. Remember to always pass the number of elements in the array with the array to functions.
Toys Made........Rating
500 or more: ***** 5 stars
between 300 and 499: *** 3 stars
between 200 and 299: * 1 star
under 200: - none
Here's the information in elves.dat:
Smiley 662
Curley 88
Clementine 335
Jasper 105
Lucinda 775
Brunhilda 103
Florence 441
Oskar 820
Snowflake 990
Bernard 690
Punch 298
Chuckie 10
Frosty 102
Snowman 311
April 830
Merry 299
Sunshine 331
Buddy 1234
Carol 271
Misty 111
Harold 52
Henry 292
Twinkle 308
Starlight 703
Burr 112
Angelica 444
Bluenose 689
Harry 254
Twinkle 259
Stardust 121
Greensleeves 453
Noel 312
Happy 209
Yukon 534
Snowcap 190
Northpole 598
And here's my code, I feel like a have a very basic understanding, but I know I'm not even close! I would appreciate any help, I really need it.
#include <iostream>
#include <fstream>
#include <cstring>
using namespace std;
int main() {
ifstream inFile;
inFile.open("elves.dat");
string elfName[50];
int ToysMade[50];
int count = 0;
int i;
//Read file until you've reached the end
while (!inFile.eof()){
inFile >> elfName;
inFile >> ToysMade;
count++;}
cout << "Elf: " << elfName <<endl;
cout << "Toys made: " << ToysMade <<endl;
inFile.close();
return 0;
}
Based on what you stated: this is how I would design the program. I could have even made it simpler looking by using a
struct
orclass
, but I'm gathering you are not that far in your course of training. Even this might be a bit more advanced than what is being asked. You did mentionparallel arrays
. Instead ofarrays
I'm usingstd::vectors
in place of it. You can easily swap out thevectors
with regulararrays
, however the functions for doing the calculations would change since I'm usinglibrary
functions that work on containers. Withraw arrays
you would have to do a bunch offor
&while
loops
andcomparison
checks while also doingbounds
checks
of thosearrays
. Your overall program would look similar to this.elves.dat
Edit - If you want to do something a little fancy in the display function. Change the
displayStats()
function to this: