Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Can someone help me with this pointers assingment for C++? You have been assigne

ID: 3682757 • Letter: C

Question

Can someone help me with this pointers assingment for C++?

You have been assigned to write a program that will track and analyze the daily stock prices for the Total Computer Care (TCC) company. To accomplish this task, you will create a dynamic array of values based on the number of prices the user wants to track. The program should then perform the analysis listed below for the data and display the results for the user. Your program should perform the following steps to accomplish the task: Prompt the user for the number of days to track the stock. Create an array of doubles containing the specified number of values to be entered, Have the user enter the price of the stock for each day. Your code should not allow the entry of negative prices. Use a function to display all of the stock prices. Using a second function to determine the average price of the stock for the time period. Display the average with a heading. Using another function, determine the number of days the stock price differed by more than $2.00 within a 2 day consecutive period. Display the results. Within another function, change the stored stock price of the last 4 array elements to half of their original value to reflect a stock split. Display the array stock prices reflecting the changes using the function created in step c. Use the following guidelines when developing your code: Implementation of all your code should be done using pointer notation except for the initial creation of the array. Error checking should be done for negative stock entries. A ¢ Output should be aligned and formatted to 2 decimal places. Include descriptive comments including comments for your functions. Use test data to check your numbers.

Explanation / Answer

#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
#include <cstdlib>
#include <vector>
#include <algorithm>
using namespace std;


void getAverage(double *arr, int size) // finding average
{
int sum = 0;   
double avg;

for (int i = 0; i < size; ++i)
{
sum += arr[i];
}

avg = double(sum) / size;

cout << "Average stock price is: "<< avg << endl;
}


void print (double *arr , int size) // printing the updated array
{
cout << "Stock prices are: ";
for (int i = 0; i < size; ++i)
{
std::cout << std::fixed;
cout << setprecision(2) << arr[i] << endl; // 2 decimal places output
}
}

void difference (double *arr, int size) // find if difference is more than 2.
{
int count = 0;
for (int i = 0; i < size-1 ; ++i)
{
if(arr[i+1] - arr[i] > 2.00) count++;
}
cout << "Number of days the stock price differed by more than $2.00: " << count << endl;
}

void stocksplit (double *arr, int size)
{
cout << "Stock split..... ";
for (int i = size-1; i > size -5; i--) // stock split function
{
arr[i] = arr[i]/2;
}

cout << "After Stock split ";
}

int main()
{
int days;
cout << "Enter number of days to track the stock: ";
cin >> days;

double * stock_price = new double[days]; // dynamic array using pointer
double prices;
cout << "Enter stock prices: ";
for (int i = 0; i < days; ++i)
{
cin >> prices;
while(prices < 0)
{
cout << "Price should be greater than 0, Enter again: ";
cin >> prices;
}
stock_price[i] = prices;
}

print(stock_price,days);
getAverage(stock_price,days);
difference(stock_price,days);
stocksplit(stock_price,days);
print(stock_price,days);

return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote