yes, several of them.
do you know struct? basic idea is to make a user defined type that holds the info you need from the file (which does not appear to be necessary, actually) and to make an array of *those*
rough pseudo code ... there is a bit to do to set this up though...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
struct data
{
string complex_name;
double rent[some_max_number];
};
data d[number_of_complex];
for(...)
{
file >> d[complex_id].complex_name;
for(...some_max_number...)
{
file >> d[complex_id].rent[index]; //if each line has different number of numbers, when you run out of values on your line, you will want to zero out the rest of the rent[] array so sum of zeros == 0.
}
}
|
alternately you can just, as you process the file, total up the values and store the single total. Or as I said above, no array, just track the biggest value as you go, and print it at the end.
there are many other ways to do this. this is an overly simple direct approach.
do you see it?
open file.
read main. main is now the biggest (first one seen logic).
main's total is 10k.
read... clay. clay's total is 21k, clay is now biggest. save 'clay' and '21k'
read .. king. king's total is 10k. it is not bigger.
... end of file.
print: clay was biggest one found at 21k.
we didn't have to store main and king after we found clay, we only ever stored 1 item, and compared it to the current item each time, at the end, you know the answer.