HELP IN C++ ONLY USING CODEBLOCKS Lab 8F: Write a program to get the stock marke
ID: 3690783 • Letter: H
Question
HELP IN C++ ONLY
USING CODEBLOCKS
Lab 8F:
Write a program to get the stock market for 3 different stocks of your choice for the 12 months of year 2014 into a 2-D array (two-dimensional array) of doubles. Make use of random number generation concept to generate stock values automatically (limit values from 30 to 700).Do this part in a function called initArray(). In addition, you need to develop the following functions.
A function to calculate and display the total value of all stocks as well as total value of each of the stocks for the year 2014. Test the function by calling it in the main function.
Total value of all stocks for year 2014 is: $XX.XX
Total value of stock XXX for year 2014 is: $XX.XX
And so on…
A function to calculate and display the average monthly value of all of the stocks as well as the average value of each of the stocks for the year 2014. Test the function by calling it in the main function.
Average value of all stocks for year 2014 is: $XX.XX
Average value of stock XXX for year 2014 is: $XX.XX
And so on…
A function to calculate and display the average monthly value of the 3 stocks for each month. Again, test the result in the main.
The average stocks value for month 1 is: $XX.XX
The average stocks value for month 2 is: $XX.XX
And so on…
A function to calculate and display the month with the highest (and the month with the lowest) value for all of the stocks for the entire year. Test the function in the main.
The month with the highest value of stocks for year 2014 is: X
The month with the lowest value of stocks for year 2014 is: X
A function to calculate and display the stock with the lowest value of all of the stocks for each month. Test your function and show the results.
Stock XXX had the lowest stocks value for month 1: $YY.ZZ
Stock XXX had the lowest stocks value for month 2: $YY.ZZ
,and so on…
A function to calculate and display the stock with the highest value of all of the stocks for each month. Test your function and show the results.
Stock XXX had the highest stocks value for month 1: $YY.ZZ
Stock XXX had the highest stocks value for month 2: $YY.ZZ
,and so on…
Create a menu() function to display all the above options (and an exit option). Test the main program again.
What do you think is the difference between top-down design and bottom-up design of large programs? Which method do you think it was? How about the method that we used to do before?
Explanation / Answer
#include <iostream>
#include <string>
using namespace std;
void initArray();
double totalstacks();
double avgmnth();//average month//
double aavgmnth();//again avg month//
double mnthhgst();//month higest//
double lstval();//lowest value//
double array[3][12];
int main()
{
initArray();
cout<<"Total stacks are:"<<totalstacks();
cout<<"avg month stacks are:"<<avgmnth();
cout<<"again avg month stacks are:"<<aavgmnth();
cout<<"month higest stacks are:"<<mnthhgst();
cout<<"lowest month stacks are:"<<lstval();
return 0;
}
void initArray()
{
int i,int j;
for(i=0;i<3;i++)
{
for(j=0;j<12;j++)
array[i][j]=random(700);//random number system reads from 0 to 300//
}
}
double toatalstacks()
{
double tstacks=0.00;
for(int i=0;i<3;i++)
{
for(int j=0;j<12;j++)
{
tstacks=tstacks+array[i][j];
}
}
return tstacks;
}
double avgmnth()
{
double avgmnth=0.00;
for(int i=0;i<3;i++)
{
for(int j=0;j<12;j++)
{
}
}
avgmnth=avgmnth+array[i][j];
double avgmnth =totalstack()/36;
return avgmnth;
}
double aavgmnth()
{
double aavgmnth=0.00;
for(int i=0;i<3;i++)
{
for(int j=0;j<12;j++)
{
}
double avgmnth =totalstack()/36;
return aavgmnth;
}
return aavgmnth;
}
double mnthhgst()
{
double mnthhgst=0.00,max=0;
for(int i=0;i<3;i++)
{
for(int j=0;j<12;j++)
{
mnthhgst=mnthhgst+array[i][j];
if(max<a[i][j])
{
max=a[i][j];
}
}
}
return max;
}
double lstval()
{
double lstval=0.00,min=0;
for(int i=0;i<3;i++)//i is for rows//
{
for(int j=0;j<12;j++)//j is for columns//
{
lstval=lstval+array[i][j];
if(max<a[i][j])
{
max=a[i][j];
}
}
}
return min;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.