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 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
|
#include <iostream>
#include <fstream>
using namespace std;
void welcome();
string getData ();
void readData (string &, float []) ;
void returnHighest(float [], int, int&);
void returnLowest(float [], int, int&);
void calculations (float [], float &, float &, int) ;
void sortArray(float [], int, float&) ;
void printResults () ;
int main ()
{
int count = 0, indexL, indexH;
float data[50], average, median, total;
string name;
welcome ();
name = getData();
readData(name, data);
returnHighest(data, 50, indexH);
returnLowest(data, 50, indexL);
calculations (data, average, total, 50);
sortArray(data, 50, median);
ofstream results;
results.open("results.txt");
results << "Day " << indexL + 1 <<" Had The Lowest Sales With $ " <<data[indexL]<<endl<<endl;
results << "Day " << indexH + 1 <<" Had The Highest Sales With $ " <<data[indexH]<<endl<<endl;
results << "The Average Of All 50 Days Is $ " << average<<endl<<endl;
results << "The Median Of All 50 Items Is $ " <<median<<endl<<endl;
results << "The Total Of All 50 Days Is $ " << total <<endl <<endl;
results << "The Items In Ascending Order "<<endl;
for(count = 0; count < 50; count ++)
results << data[count]<<endl;
results.close();
cout<<"results.txt Has Been Created Containing:"<<endl;
cout<<"- The Day With The Lowest Sales"<<endl;
cout<<"- The Day With The Highest Sales"<<endl;
cout<<"- The Average Of All Data"<<endl;
cout<<"- The Median Of The Data"<<endl;
cout<<"- The Total Of All The Data"<<endl;
cout<<"* The Data Has Also Been Sorted Into Ascending Order *"<<endl<<endl;
system("pause");
return 0;
}
void welcome ()
{
cout<<"========================================="<<endl;
cout<<"== Welcome To The Sales Amount Program =="<<endl;
cout<<"========================================="<<endl<<endl;
cout<<"This Program Lets You :"<<endl;
cout<<"(*)"<<endl;
cout<<" - Create A File."<<endl<<endl;
cout<<" - Input The Sales For 50 Days Into That File."<<endl;
cout<<"(*)"<<endl<<endl;
cout<<"Then The Program Calculates :"<<endl;
cout<<"(**)"<<endl;
cout<<" - The Day With The Lowest/Highest Sales Amount."<<endl<<endl;
cout<<" - The Total Sales For All Days."<<endl<<endl;
cout<<" - The Average Sales For All Days."<<endl<<endl;
cout<<" - The Contents Sorted In Ascending Order."<<endl<<endl;
cout<<" - The Median Value Of The Contents."<<endl;
cout<<"(**)"<<endl<<endl;
return ;
}
string getData ()
{
float contents [ 50 ], none[50];
int count = 0;
string UserFileName, EndFileName, CompleteFile;
cout<<"Please Name The File To Store The Sales In : ";
getline(cin,UserFileName);
EndFileName = ".txt";
CompleteFile = UserFileName + EndFileName;
ofstream daySales;
daySales.open(CompleteFile.c_str());
for(count = 0; count <50; count ++)
{
cout << " What Are The Sales For Day " << count+1 << "? $" ;
cin >> contents[count];
daySales << contents[count]<<endl;
}
daySales.close ();
return CompleteFile;
}
void readData (string & name, float numb [])
{
int count = 0, counterMax = 60;
ifstream openFile;
openFile.open(name.c_str());
while(count < counterMax && openFile >> numb [count])
{
count ++;
}
openFile.close();
}
void returnHighest(float MyArray [], int size, int & indexH)
{
int count = 0;
float value = MyArray [ 0 ];
for(count = 1; count < 50; count ++)
{
if(MyArray[count] > value)
value = MyArray[count];
}
indexH = count;
}
void returnLowest(float MyArray [], int size, int & indexL)
{
int count = 0;
float othervalue = MyArray[0];
for(count = 1; count < size; count ++)
{
if(MyArray[count] < othervalue)
othervalue = MyArray[count];
}
indexL = count;
}
void calculations (float ary [], float& average, float& total, int size)
{
int count = 0;
for(count = 0; count < size; count ++)
{
total += ary [ count ];
}
average = total / size;
}
//Sorting List Into Ascending Order
void sortArray(float array [], int size, float& median)
{
bool swap;
float temp;
do
{
swap = false;
for (int count = 0; count < (size - 1); count ++)
{
if(array[count] > array [count +1])
{
temp = array[count];
array[count] = array[count + 1];
array[count+1] = temp;
swap = true;
}
}
}
while (swap);
median = (array[25] + array[26])/2;
}
|