1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
|
#include <iostream>
#include <string>
using namespace std;
//Declare the appropriate functions...
int* FillList(int*, int&, int&);
int Totalizer(int*, int);
int* ExpandArray(int*, int, int&);
int FindAverage(int, int);
void DisplayAverage(int);
void ShowList(int*,int);
//Define the size of the DefaultSize
int DefaultSize = 3;
int main()
{
int* List = new int[DefaultSize];
int Size, MaxSize, Total, Mean;
MaxSize = DefaultSize;
int K = 0;
List = FillList(List, Size, MaxSize);
Total = Totalizer(List, Size);
cout << Total << endl;
Mean = FindAverage(Total, Size);
ShowList(List, Size);
DisplayAverage(Mean);
}
int* FillList(int* List, int& Size, int& MaxSize)
{
string IValue;
cout << "Enter Numbers Below, Stop To Quit" << endl;
for(Size = 0 ; Size < MaxSize ; Size++) {
cout << "Enter Value: ";
getline(cin, IValue);
if(IValue == "Stop")
break;
List[Size] = atoi(IValue.c_str());
if(Size == MaxSize - 1)
List = ExpandArray(List, Size, MaxSize);
}
return List;
}
int* ExpandArray(int* List, int Size, int& MaxSize)
{
int* NewList = new int[(Size + DefaultSize)];
for(int K = 0 ; K < Size ; K++)
{
NewList[K] = List[K];
cout << "NewList[ " << K << "] =" << NewList[K] << endl;
}
MaxSize += DefaultSize;
cout << "You may continue entering values..." << endl;
delete[] List;
List = NewList;
return NewList;
}
int Totalizer(int* List, int Size)
{
int Total = 0;
for(int K = 0 ; K < Size ; K++)
Total += List[K];
return Total;
}
int FindAverage(int Total, int Size)
{
if(Size > 0)
return Total / Size;
return 0;
}
void DisplayAverage(int Mean)
{
cout << "============================================" << endl;
cout << "Mean Value = " << Mean << endl;
cout << "============================================" << endl;
}
void ShowList(int* List, int Size)
{
for(int K = 0 ; K < Size ; K++)
cout << K << " --->" << List[K] << endl;
}
|