The investment company of Pickum & Loozem has been recording the trading price o
ID: 3832917 • Letter: T
Question
The investment company of Pickum & Loozem has been recording the trading price of a particular stock over a 15-day period. Write a program that queries the user for these prices and stores them in a sequential container. The program must find and display:
a. The trading range (the lowest and highest prices recorded).
b. A sequence that shows how much the price rose or fell each day.
The problem is modified from the description in the text; it is not necessary to sort the data, but standard containers and standard algorithms must be used wherever possible.
All the calculations MUST be done using standard algorithms
Explanation / Answer
executable code:
#include <iostream>
#include<iomanip>
#include<cmath>
using namespace std;
int main()
{
int numOfDays;
float posnum = 0;
cout<<"How days Sales will be entered? ";
cin>>numOfDays;
float sales[15];
float priceDifference[15];
float minSale, maxSale;
for(int i=0; i<numOfDays; i++)
{
cout << "Enter sales of day- " << i+1 <<": $";
cin >> sales[i];
if(i==0)
{
minSale=sales[i];
maxSale=sales[i];
}
else
{
if(sales[i] < minSale)
minSale=sales[i];
if(sales[i] > maxSale)
maxSale=sales[i];
}
}
cout<<" The trading range is "<<minSale<<"-"<<maxSale<<endl<<endl;
for(int i=0;i<numOfDays;i++)
{
if(i==0)
{
priceDifference[i]=sales[i];
}
else
{
priceDifference[i]=sales[i]-sales[i-1];
}
}
for(int i=0;i<numOfDays;i++)
{
if(priceDifference[i]<0)
cout<<"In Day-"<<(i+1)<<" the sales fell by $"<<priceDifference[i]<<endl;
else
cout<<"In Day-"<<(i+1)<<" the sales rose by $"<<abs(priceDifference[i])<<endl;
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.