CPPForSchool.com: Array - Single Dimension Set 1 Assignment 1
1.
Write a C++ program to find the sum and average of one dimensional integer array.
For the past 10 assignments, I have began to standardize my code format by including a boilerplate design. Also, I have began including comments as a header as well. For this assignment, I have began to further enhance my coding format, specifically by breaking chunks of the code into functions. Although it takes a bit more time to code, the flexibility it creates in regards to updating the code is quite remarkable. With that said, I will be breaking down the screenshots of my source into sizable sections for increased clarity.
***Spoiler Alert: Although I did create a program that takes the sum and average of a one dimensional integer array, it was a limited implementation. After review the sample source code, I modified it to become a more intuitive and robust system.***
For this assignment, I wanted to go a bit beyond the original requirements of building a simple array calculator, specifically coding style wise. I decided to break everything into functions and call them accordingly. This allows more flexibility in the long run. Admittedly, this is somewhat useless because I sincerely doubt that I will need to use this program. Nevertheless, practice is important for future programs that will need this sort of flexible approach.
Below is my source code.
For the past 10 assignments, I have began to standardize my code format by including a boilerplate design. Also, I have began including comments as a header as well. For this assignment, I have began to further enhance my coding format, specifically by breaking chunks of the code into functions. Although it takes a bit more time to code, the flexibility it creates in regards to updating the code is quite remarkable. With that said, I will be breaking down the screenshots of my source into sizable sections for increased clarity.
***Spoiler Alert: Although I did create a program that takes the sum and average of a one dimensional integer array, it was a limited implementation. After review the sample source code, I modified it to become a more intuitive and robust system.***
For this assignment, I wanted to go a bit beyond the original requirements of building a simple array calculator, specifically coding style wise. I decided to break everything into functions and call them accordingly. This allows more flexibility in the long run. Admittedly, this is somewhat useless because I sincerely doubt that I will need to use this program. Nevertheless, practice is important for future programs that will need this sort of flexible approach.
Below is my source code.
Once I was able to confirm the calculations and menu system worked successfully, I went ahead and began the comparison between my code and the sample source code. Once I reviewed the sample source code, I began to integrate the new code, specifically giving the ability for the user to specify all of the integers within the one dimensional array.
The function arrayCalculator has now been updated to the following:
Now the user is required to add all of the integers manually, instead of a fixed pre-loaded integer array.
Admittedly, I went way overboard with this assignment, but I enjoyed the process thoroughly. With that said, below is a screenshot of the sample source code and output. Note, the last screenshot is from my program for comparison.
Comments
Post a Comment