Help my teacher wants more functions. I tried to combine the sort feature it didn't work and the average feature, I just can't get it.
Thanks.
CODE
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <iostream>
#include <conio.h>
void DisplayTitle(void);
int averages(int stock1[20], int stock2[20], int stock3[8], double arr1);
void high_low(double, double);
double arr1 = 20;
double arr3 = 8;
void bubble_srt(double stock3[], double n);
void bubble_srt(double stock1[], double n);
using namespace std;
int main()
{
int index;
int size;
double Avg1;
double Avg2;
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,34.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.99,
98.54, 95.30, 92.32, 110.88};
//Report 1 - show highest and lowest numbers in array
{
DisplayTitle();
cout<< "1\n";
sort(stock1, stock1+20);
sort(stock2, stock2+20);
{
for (int i=0; i<1; i++) {
cout << "\nThe highest number in Stock 1 is " << stock1[19] <<" \n";
cout << "The lowest number in Stock 1 is " << stock1[0] <<" \n\n\n";
cout << "The highest number in Stock 2 is " << stock2[19] <<" \n";
cout << "The lowest number in Stock 2 is " << stock2[0] <<" \n\n\n";
}
system("pause\n");
//Report 2 - The average of each set of 20 stocks and the number of days,
//on which each stock price exceeded its average price.
{
DisplayTitle();
cout<<"2\n";
int count = 0;
int count1=0;
{
int j = 20;
for (j = 0; j < 20; j++)
if(stock1[j] > stock2[j]) ++count;
int k = 20;
for (k = 0; k < 20; k++)
if(stock2[k] < stock1[k]) ++count1;
}
cout << "Number of days Stock1 exceeded Stock2: "<<count;
cout << "\n";
cout << "Number of days Stock2 exceeded Stock1: "<<count1;
cout << "\n\n";
cout << "Number in Array: "<< arr1;
cout << "\n\n";
{
double sum = 0;
double average = 0;
for (int i = 0; i < 20; ++i)
sum+=stock1[i];
average = sum/arr1;
cout<<"Stock1 Average:"<<average;
cout << "\n\n";
}
}
double sum = 0;
double average1 = 0;
for (int i = 0; i < 20; ++i)
sum+=stock2[i];
average1 = sum/arr1;
cout<<"Stock2 Average:"<<average1;
cout << "\n\n";
}
}
system("pause");
//Report 3 - Using the functions from Reports 1 and 2, find the lowest
//and highest price in the stock3 array, and find the average of the stocks in
//the following array of 8 prices above.
//Sort the stock3 array and display in ascending order with this report
DisplayTitle();
cout<< "3\n";
{
int i;
sort(stock3, stock3+8);
for (int i=0; i<1; i++) {
cout << "The highest number in Stock 3 is " << stock3[7] <<" \n";
cout << "The lowest number in Stock 3 is " << stock3[0] <<" \n\n\n";
}
double sum = 0;
double average3 = 0;
for (int i = 0; i < 8; ++i)
sum+=stock3[i];
average3 = sum/arr3;
cout<<"Stock3 Average:"<<average3;
cout << "\n\n";
void bubble_srt(double stock3, double arr1); // Sort the array
cout<<("Stock 3 in ascending order:\n"); // Show results after the sort
for(i = 0; i < 8; i++)
cout << stock3[i]<< "\n";
cout<<("\n");
}
system("pause");
//Report 4 - Stock 1 values and how much each stock price differs from the
// average.
//
DisplayTitle();
cout<< "4\n";
{
double sum = 0;
double average = 0;
for (int i = 0; i < 20; ++i)
sum+=stock1[i];
average = sum/arr1;
cout<<"Stock1 Average:"<<average;
cout << "\n\n";
void bubble_srt(double stock1, double arr1); // Sort the array
{
int i;
cout<<("Difference of Stock 1 in ascending order:\n"); // Show results after the sort
for(i = 0; i < 20; i++)
cout <<stock1[i] << setw(15) <<stock1[i] - average <<"\n";
}
system("PAUSE");
}
}
void DisplayTitle()
{
cout << "\n Report ";
}
This post has been edited by cooplis: 21 Apr, 2008 - 07:58 AM