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
|
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
double FindMax(double stock[], int size);
double FindMin(double stock[], int size);
double CalcAvg(double stock[], int n);
double FindDaysOver(double stock[], int n, int avg);
double CalcAvg(double stock[], int number, int day);
int main(){
double stock1[20] = {34.25, 40.50, 36.50, 40.00,
30.25, 30.25, 35.50, 36.00,
34.25, 37.00, 34.00, 35.00,
36.25, 34.25, 40.50, 41.50,
41.50, 40.00, 36.50, 45.50};
double stock2[20] = {40.25, 38.50, 34.50, 33.50,
30.50, 29.75, 37.50, 36.00,
34.75, 38.00, 34.25, 37.00,
34.25, 37.50, 34.50, 38.50,
37.50, 37.25, 38.25, 37.50};
double stock3[8] = {100.41, 90.45, 99.30, 102.9,
98.54, 95.30, 92.32, 110.88};
int day, number;
//Display the title.
cout << "\n The Stock Problem ";
cout << "\n ---------------------------------------------------";
//Report One
cout << "\n\n Report One - Mabximums & Minimums" << endl;
cout << "\n Stock One ";
cout << "\n The Highest Price: " << FindMax(stock1, 20);
cout << "\n The Lowest Price: " << FindMin(stock1, 20) << endl;
cout << "\n Stock Two ";
cout << "\n The Highest Price: " << FindMax(stock2, 20);
cout << "\n The Lowest Price: " << FindMin(stock2, 20) <<endl;
system("pause");
//End of Report One
//Report Two
cout << "\n Report Two - Averages & Days Exceeding Average" << endl;
cout << "\n Stock One ";
cout << "\n Average: " << CalcAvg(stock1, 20);
cout << "\n Number of Days: " << FindDaysOver(stock1, 20, CalcAvg(stock1, 20)) << endl;
cout << "\n Stock Two ";
cout << "\n Average: " << CalcAvg(stock2, 20);
cout << "\n Number of Days: " << FindDaysOver(stock2, 20, CalcAvg(stock2, 20)) << endl;
system("pause");
//End of Report Two
//Report Three
cout << "\n Report Three - Stock Three: Maximum & Average" << endl;
cout << "\n Stock Three ";
cout << "\n Average: " << CalcAvg(stock3, 8);
cout << "\n Number of Days: " << FindDaysOver(stock3, 8, CalcAvg(stock3, 8)) << endl;
system("pause");
//End of Report Three
//Report Four
cout << "\n Report Four - Average of Stocks" << endl;
cout << "\n Enter the Number of Values to Average: ";
cin >> number;
cout << "\n Enter the Day to Start On: ";
cin >> day;
cout << "\n The Average for " << number << " Values Starting on Day " << day << " is: ";
cout << "\n Stock 1 = " << CalcAvg(stock1, number, day);
cout << "\n Stock 2 = " << CalcAvg(stock2, number, day);
cout << "\n Stock 3 = " << CalcAvg(stock3, number, day) << endl;
system("pause");
//End of Report Four
return 0;
}
double FindMax(double stock[], int size){
double max = stock[0];
for(int i = 1; i < size; i++){
if (stock[i] > max)
{max = stock[i];}
}
return max;
}
double FindMin(double stock[], int size){
double min = stock[0];
for (int i = 1; i < size; i++){
if (stock[i] < min)
{min = stock[i];}
return min;
}
}
double CalcAvg(double stock[], int n){
int total = 0;
for(int i = 0; i < n; i++)
{total = total + stock[i];}
double average = total/n;
return average;
}
double CalcAvg(double stock[], int number, int day){
int total = 0;
for (int i = day; i < day + number; i++)
{total = total + stock[i];}
double average = total/number;
return average;
}
double FindDaysOver(double stock[], int n, int avg){
int ctr = 0;
for(int i = 0; i < n; i++){
if (avg < stock[i])
ctr ++;
}
return ctr;
}
|