Thanks.
Cooplis
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <iostream>
#include <conio.h>
void high_low(double, double);
double arr1 = 20;
double arr3 = 8;
void bubble_srt(double stock1[], double n);
using namespace std;
int main()
{
int index;
int size;
double Avg1;
double Avg2;
int index_of_min;
int number_used;
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
{
cout << " REPORT 1 \n\n";
sort(stock1, stock1+20);
sort(stock2, stock2+20);
{
for (int i=0; i<1; i++) {
cout << "The 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.
{
cout << "\n\n REPORT 2 \n\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: \n"<< arr1;
{
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
cout << "\n\n REPORT 3 \n\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";
}
}
system("pause");
//Report 4 - The 16 five-day moving averages for stock1 and stock2 with
//appropriate headings. Moving average means find the average for prices 1 to 5
//in a stock list and then the average for prices 2 to 6, etc.
cout << "\n\n REPORT 4 \n\n";
void bubble_srt(double, double);
{
int i;
cout << "Before the sort:\n"; // Show array elements before sort
for(i = 0; i < 19; i++)
cout << stock2[i]<< "\n";
cout << " \n";
}
void bubble_srt(double stock1, double arr1); // Sort the array
int i;
{
printf("After the sort:\n"); // Show results after the sort
for(i = 0; i < 20; i++)
cout << stock2[i]<< "\n";
cout<<("\n");
}
system("PAUSE");
}
// Pause the screen
This post has been edited by cooplis: 20 November 2007 - 05:55 AM

New Topic/Question
Reply




MultiQuote






|