<> Two-Dim array help.

I have to create a program that calculates the final scores per diver, who each get five dives. I have to include the difficulty level when figuring out this score, and I need to drop the highest and lowest scores.

Now, I'm reading from a file where the values are something like:

234 :Diver number
2.3 :Difficulty
2.1 3.2 4.0 2.3 3.8 :Scores

Would I create a parallel array for the difficulty, or include it in a 2D array with the scores. Something like

score[Difficulty][individualScores]; ?

Also, would I include a findMin and findMax in a function that calculates the total, seeing as how the highest and lowest must be dropped to determine the final score?
You only need 2D if a diver does more than one difficulty level per test.

Yes, you need a find min/max function (just one, you don't need two separate functions, as you can find min and max at the same time).

If the final score is an average, you can calculate the sum of all the numbers at the same time too...

Hope this helps.
so I would input the diver numbers in one array, then the difficulty and the scores would both be in a 2d array?

There has to be a 2d array in this assignment.
I don't understand the assignment, then.

[edit] Perhaps you should post it verbatim
Last edited on
i don't understand the purpose of the `difficulty', ¿how does affect the final score?

Also, don't follow Duoas advice. Limiting the responsibilities of the functions would lead to code that is simpler to write, easier to maintain and more likely to be reused.
I suppose the smart people who write the STL got it wrong then?
http://www.cplusplus.com/reference/algorithm/minmax/

It is a mistake to always write a general-purpose solution to every problem.

And you are asking the OP to write at least three separate loops with one statement in them instead of just one loop with three statements inside. That's the only difference here.

Reuse? On a homework question? Easier to maintain? Duplicate code in many functions? Who is recommending added complexity now? And how will it stunt his future growth, productivity, or code-correctness? (It won't.)

Perhaps you should focus on the OP's actual needs first before you start shooting at other responses simply because you personally disagree with them.

"Limiting the responsibilities of a function" indeed... So then at what point does a function have a responsibility to perform the homework assignment's task?

I grow sick of the curmudgeonliness growing here...
closed account (ivDwAqkS)
why don't you use bubble sort?, it allows you to organize the array from the lowest score to the highest, so you know the the first element [0] is the lowest and the highest is the last element. you can use bubble sort with one array or multi-dimentional array.
Last edited on
Any sort of sort will do, but it depends on what the professor wants. (In beginning CS courses, the idea is often to do the work yourself, and a sort is not strictly necessary here.)
The difficulty needs to be multiplied by the scores that remain after eliminating the highest and the lowest.
> Reuse? On a homework question?
Precisely. Using previous concepts to teach new ones, make them easier to grasp.
By instance, using `min_element' in `selection_sort()'
They should be able to see it in these kind of toy problems.


> Easier to maintain? Duplicate code in many functions?
testable small units.


> I suppose the smart people who write the STL got it wrong then?
Another beautiful example (not c++) http://www.gnu.org/software/octave/doc/interpreter/Descriptive-Statistics.html#XREFstatistics
You know, I just can't stand it when people get all pompous about a subject for which they obviously know nothing -- besides their armchair philosophy about how the world should work.

Go get a degree in pedagogy and then come back and .... Oh wait, you won't because then you'll know how idiotic your arguments are.

Reuse...

As if you weren't playing semantics to begin with. Pick a meaning and stick with it. Either you are talking about code reuse (for a three line function!) or you are talking about prior knowledge review. They are separate concepts.

[For] instance, using `min_element' in `selection_sort()'

Unfortunately for that example, an unoptimized selection sort doesn't need to do more than one thing as it loops through the I unsorted set. OP's problem does. (Optimized versions do: http://www.cplusplus.com/faq/sequences/sequencing/sort-algorithms/selection-sort/#optimization)

They should be able to see it in these kind of toy problems.
toy problems are for instructional purposes... Precision to large project guidelines on beginner-level homework is overload, both for the student and for the lesson objectives.

testable small units.

On a fifty-line toy homework problem??? LOL!

Another beautiful example

Ah, yes, because if you think that is a valid counter-example then I am obviously wasting my time with you. Doing one thing nicely is pretty and all... But it still says nothing against doing multiple things nicely.

JSYK, I only bother debunking the drivel here in OP's otherwise untarnished topic so that others can begin to recognize it.
code reuse.
min_element(), max_element(), sum() are useful functions that are likely to be needed in other projects. Moreover there is very likely that they are already coded (by the OP, in previous homework)
contestant_score() has a high chance to die here.

> toy problems are for instructional purposes...
is not learning functions then.

>> testable small units.
> On a fifty-line toy homework problem??? LOL!
that it would be screw up. It would be nice to just check four of those fifty lines
Topic archived. No new replies allowed.