I have written some code that executes fine, but I am looking to further optimize the code with any nuanced methods that I probably haven't learned yet in my classes. I am willing to look up and study any methods mentioned. What I learned from reading this forum is that there are a lot of beginner methods taught in schools that aren't really efficient.
Why aren't students taught this right off the bat?
The curriculum is outdated, most instructors want to revisit as much pain on students teaching outdated and antiquated programming methods as they suffered through....
Maybe instructors just don't know what modern C++ (C++11 or later) has to offer.
The debate about what best to teach a without any prior knowledge beginning C++ student rages on.
C++ is not the best beginner's programming language, the learning curve is quite high for barest minimum proficiency, but it is one of the more common ones.
Too often some new concept being taught could require an idea that is something to be taught later.
I am someone that believes teaching what the C++ Standard Library has to offer first should be a priority. Learn to use C++ containers such as std::vector instead of starting off with regular arrays, etc.
Later intermediate and advanced courses can delve into how to deal with legacy code, craft a custom container, etc.
Ah, okay. I had no idea such a function existed. That makes things easier. Why aren't students taught this right off the bat?
That's the £1,000,000 question...
However, to find the max element you find it within the input loop - not as a separate loop. Also, just to find the maximum you don't actually need to store the individual numbers. Consider:
I agree, I have learned a lot from this forum that trumps what I leaned in classes. I would like to think that these courses are trying to teach the students how to understand how the language works on a conceptual level. But there are a lot of things that they could teach us from the start, like how using namespace std; isn't good practice.
well, you learned something in the class as well. The trick is getting past outdated info and 'do it yourself' classroom stuff towards 'what can it do for me' and 'what is the current way'. Using namespace std was highly recommended for a while, until people realized the issues and reversed that.
sure, max element can do it for you, but you hopefully learned how to do it yourself, or at least how to approach it? Its a simple problem, good for a student to get a handle on looping through the data and finding something etc. What if you needed to find the second largest element? Or the median? Can you do those now? For every built in algorithm, there are dozens of nearly identical problems that are not in the toolset. You can either do something weird and usually inefficient to make the built in ones work (eg sort it and take the next to last works, but its slower than doing it yourself) or you can roll one out that does what you need. I consider the algorithms to be handy, ultra commonplace shortcuts to stuff that I really should be able to do myself, and recommend you take them with that mentality. Use them, absolutely, but know how to re-create them too.