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++).