PLEASE USE THE SPECIFICATIO GIVEN BELOW THANK YOU An investo
PLEASE USE THE SPECIFICATIO GIVEN BELOW THANK YOU.
An investor is tracking three stocks, and has collected the daily prices for Ford and Honda on 20 consecutive days. The included array provides the 20 prices for Ford and Honda, and 8 prices for Audi. The investor only tracked the Audi stock prices for the last 8 days.
Write a C++ program to perform an analysis on the data, displaying four reports for the user.
The Analysis
Report One sample
This report displays the highest and lowest price for Ford, and the highest and lowest price for Honda. Here is an example, but you may design your own report format:
Report Two
This report displays:
The average of the 20 stock prices for Ford, and the number of days on which each stock price exceeded its average.
The average of the stock prices for Honda, and the number of days on which each stock price exceeded its average.
Display the results with appropriate labels.
Report Three
Using the functions from Reports One and Two, find the highest price for Audi, and find the average of the 8 stock prices. Display the results with appropriate labels.
Report Four
Display the difference between the first day price and the last day price for all three stocks. Write a function to calculate the difference.
Report Presentation
As your program displays the four reports:
Present the title
Present the report
Pause the screen cin.get(); or system(“pause”);
When the user presses Enter, go to the next report.
Header files
User-defined header files are useful for reducing redundant code. The stocks.h file contains all the arrays you need for this project. To incorporate these arrays into your cpp file, use a statement like this:
#include \"stocks.h\"
The program has to know where this file is located. To add the header file: right-click on Header Files in the Solution Explorer of the IDE and add the header file to the project so you don’t need to specify a drive.
The #include statement is basically like a copy/paste operation. The compiler will replace the #include line with the actual contents of the file you\'re including when it compiles the file. This way, any program that needs these arrays can include them instead of keying the array data in each program.
Here are the necessary include for this project:
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
#include \"stocks.h\"
Purpose of this project
Develop C++ program with the following new features:
Arrays and functions
String arrays
User written header files
Create a readable main function. The code for each report should have the comment: // Report 1 (for example) at the beginning of the report code. Place a blank line between each report segment. main should consist primarily of function calls.
Try to write small, reusable functions. This project ends up being shorter than you think if you design good functions. For example, one function should be used to determine the highest price for Ford, Honda, and Audi. You will be evaluated on your function and report design.
You should only have one findMax, findMin, findDaysOver, calcAvg, and calcDifference function. For example, findMax should be one function that is called when needed.
Use the power of indexing through an array with a for loop.
THIS IS COLLECTED DATA
Solution
Please find the answer to the above problem as follows:-
stock.h
#ifndef STOCK_H_INCLUDED
#define STOCK_H_INCLUDED
const int ROW = 3; // number of rows in the stock array
const int COL = 20; // number of columns in stock array
// stock 2-dimensional array
// row 0 = 20 Ford prices (Day 1 to Day 20)
// row 1 = 20 Honda prices (Day 1 to Day 20)
// row 2 = 8 Audi prices (Day 13 to Day 20)
double stock[ROW][COL] = { 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,
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,
0,0,0,0,0,0,0,0,0,0,0,0,100.41,90.45,99.30,102.99,98.54,
95.30,92.32,110.88
};
// array that supplies stock names
string name[] = { \"Ford\", \"Honda\", \"Audi\" };
double findMax(int productId);
double findMin(int productId);
int findDaysOver(int productId);
double calcAvg(int productId);
double calcDifference(int productId);
#endif // STOCK_H_INCLUDED
stock.cpp
#include<iostream>
#include<string> // include for string data
using namespace std;
#include\"stock.h\"
int main(){
cout<<\"The Stock Problem\"<<endl;
cout<<\"Report 1 \"<<\" Maximum and Minimum\"<<endl;
cout<<name[0]<<endl;
cout<<\"Max: \"<<findMax(0)<<endl;
cout<<\"Min: \"<<findMin(0)<<endl;
cout<<name[1]<<endl;
cout<<\"Max: \"<<findMax(1)<<endl;
cout<<\"Min: \"<<findMin(1)<<endl;
cin.get();
cout<<\"Report 2 \"<<\" Average and Number of Days stock price exceeded average\"<<endl;
cout<<name[0]<<endl;
cout<<\"Average: \"<<calcAvg(0)<<endl;
cout<<\"Number of Days stock price exceeded average: \"<<findDaysOver(0)<<endl;
cout<<name[1]<<endl;
cout<<\"Average: \"<<calcAvg(1)<<endl;
cout<<\"Number of Days stock price exceeded average: \"<<findDaysOver(1)<<endl;
cin.get();
cout<<\"Report 3 \"<<\" Highest Price and Average of stock price of Audi\"<<endl;
cout<<name[2]<<endl;
cout<<\"Maximum: \"<<findMax(2)<<endl;
cout<<\"Average: \"<<calcAvg(2)<<endl;
cin.get();
cout<<\"Report 4 \"<<\" Difference between first day and last day price\"<<endl;
cout<<name[0]<<endl;
cout<<\"Difference: \"<<calcDifference(0)<<endl;
cout<<name[1]<<endl;
cout<<\"Difference: \"<<calcDifference(1)<<endl;
cout<<name[2]<<endl;
cout<<\"Difference: \"<<calcDifference(2)<<endl;
cin.get();
return 0;
}
double findMax(int productId){
int i;
double maximum=0;
for(i=0;i<COL;i++){
if(stock[productId][i]>maximum){
maximum = stock[productId][i];
}
}
return maximum;
}
double findMin(int productId){
int i;
double minimum=10000;
for(i=0;i<COL;i++){
if(stock[productId][i]<minimum){
minimum = stock[productId][i];
}
}
return minimum;
}
int findDaysOver(int productId){
double average = calcAvg(productId);
int i;
int counter = 0;
for(i=0;i<COL;i++){
if(stock[productId][i]>average){
counter++;
}
}
return counter;
}
double calcAvg(int productId){
int i;
double sum=0;
double counter = 0;
for(i=0;i<COL;i++){
if(stock[productId][i]>0){
sum += stock[productId][i];
counter++;
}
}
double average = sum/counter;
return average;
}
double calcDifference(int productId){
int i;
double firstPrice = 0;
double lastPrice = 0;
for(i=0;i<COL;i++){
if(stock[productId][i]>0){
firstPrice = stock[productId][i];
break;
}
}
lastPrice = stock[productId][COL-1];
return lastPrice-firstPrice;
}



