How close is my program to an ideal modern C++ program?
Hello!
So, I recently started watching videos on YouTube by OneLoneCoder (Javidx9). He's really great in the way he explains things out about modern C++.
Here's a few links:
YouTube
https://github.com/OneLoneCode
OneLoneCoder.com - HOME
In one of his 8 BITS OF TIPS videos, he suggested to practice from the most basic of C++ algorithms such as messing around with arrays and other stuff to learn more about modern C++.
I just wrote a few lines of code doing the most basic of things. On a scale of 1 to 10, how close is this to an ideal program written in modern C++ (I'm guessing pretty low:)).
I would love it if someone could direct/brief me with how to approach this, a step by step guide on how I should progress through my C++ learning journey, what topics should I finish before approaching something new. Any re-directions to another website would be cool to so long as I have more content to read and learn (history, functionality, uses, optimization, etc)
Here's the code that I mentioned of:
Code:
#include <iostream>
using namespace std;
float Sum_Of_All_Elements (int* , int);
float Product_Of_All_Elements (int* , int);
float Sum_In_A_Range (int* , int , int);
float Product_In_A_Range (int* , int , int);
float Minimum_In_A_Range (int* , int , int);
float Maximum_In_A_Range (int* , int , int);
void Display_A_Range (int* , int , int);
int main()
{
int iMy_Arr[] = { 1,2,3,4,5 };
cout << endl << Sum_Of_All_Elements(iMy_Arr , 5);
cout << endl << Product_Of_All_Elements(iMy_Arr , 5);
cout << endl << Sum_In_A_Range(iMy_Arr , 1 , 3);
cout << endl << Product_In_A_Range(iMy_Arr , 1 , 3);
cout << endl << Minimum_In_A_Range(iMy_Arr , 0 , 4);
cout << endl << Maximum_In_A_Range(iMy_Arr , 0 , 4);
Display_A_Range(iMy_Arr , 0 , 4);
return 0;
}
float Sum_Of_All_Elements (int* iARRAY , int iSize = 0) // Size: Sum till which element?
{
float fSum = 0;
for (int iIndex = 0 ; iIndex < iSize ; iIndex++)
fSum += iARRAY[iIndex];
return fSum;
}
float Product_Of_All_Elements (int* iARRAY , int iSize = 0) // Size: Product till which element?
{
float fProduct = 1;
for (int iIndex = 0 ; iIndex < iSize ; iIndex++)
fProduct *= iARRAY[iIndex];
return fProduct;
}
float Sum_In_A_Range (int* iARRAY , int iStart_Pos = 0 , int iEnd_Pos = 0) // iStart_Pos , iEnd_Pos: Which Indexes?
{
float fSum = 0;
for (int iIndex = iStart_Pos ; iIndex <= iEnd_Pos ; iIndex++)
fSum += iARRAY[iIndex];
return fSum;
}
float Product_In_A_Range (int* iARRAY , int iStart_Pos = 0 , int iEnd_Pos = 0) // iStart_Pos , iEnd_Pos: Which Indexes?
{
float fProduct = 1;
for (int iIndex = iStart_Pos ; iIndex <= iEnd_Pos ; iIndex++)
fProduct *= iARRAY[iIndex];
return fProduct;
}
float Minimum_In_A_Range (int* iARRAY , int iStart_Pos = 0 , int iEnd_Pos = 0) // iStart_Pos , iEnd_Pos: Which Indexes?
{
float fMin = iARRAY[iStart_Pos];
for (int iIndex = iStart_Pos ; iIndex <= iEnd_Pos ; iIndex++)
if (iARRAY[iIndex] < fMin)
fMin = iARRAY[iIndex];
return fMin;
}
float Maximum_In_A_Range (int* iARRAY , int iStart_Pos = 0 , int iEnd_Pos = 0) // iStart_Pos , iEnd_Pos: Which Indexes?
{
float fMax = iARRAY[iStart_Pos];
for (int iIndex = iStart_Pos ; iIndex <= iEnd_Pos ; iIndex++)
if (iARRAY[iIndex] > fMax)
fMax = iARRAY[iIndex];
return fMax;
}
void Display_A_Range (int* iARRAY , int iStart_Pos = 0 , int iEnd_Pos = 0) // iStart_Pos , iEnd_Pos: Which Indexes?
{
cout << endl;
for (int iIndex = iStart_Pos ; iIndex <= iEnd_Pos ; iIndex++)
cout << iARRAY[iIndex] << " ";
}
I have about 14 months of programming experience because of school... We started learning on TURBO C++ but as we progressed and learnt more, I started getting ahead of class by doing more research and have shifted to Code::Blocks for all coding purposes recently (except school projects as they're require to be done only in TURBO C++).
----------------------------------------------------------------------------
On a side note, I've given rise to a problem on my C::B Output Window. I ran one of the programs provided by OLC (Javidx9) which involves the usage of <windows.h> header file. Before running the program, I always had a scroll-able Output Window but now I have a non-scroll-able Window which is affecting the way I can view my Output. It's a non-scroll-able window for all new files/projects, the reason for which I'm not aware of. If someone knows how to fix it, I'd really appreciate some help. Thanks!