**Explanation::**

- Code is implemented in C++.
- Please read all the comments for better understanding of the code.
- Program is implemented in CodeBlocks IDE.
- Every step is well commented.
- Functions are created and their names are chosen in such a way that it becomes easy to identify it’s context.
- All variables declared have named according to context of the program.
- Output is provided below the code.

*Code in c++::*

#include<iostream>

#include<string>

#include <iomanip>

using namespace std;

void getInitialCost(double initialCost[],int numOfShares[],double buyingPrice[],int n);

void getCurrentCost(double currentCost[],int numOfShares[],double currentPrice[],int n);

void getProfit(double profit[],double currentCost[],double initialCost[],double yearlyFees[],int n);

void printData(string stockName[],double initialCost[],double currentCost[],double profit[],int n);

void totalValues(double initialCost[],double currentCost[],double profit[],int n);

void countValues(double profit[],int n);

int main(){

/*

* We need to use five arrays of size n

* which is taken as input as number of stocks.

*/

/*n is number of stocks*/

int n;

cout<<“Enter number of stocks::”;

cin>>n;

/*

* Now we declare string array named stockName

* of size n to stores names of the stock

*/

string stockName[n];

/*

* Now we declare integer array named numOfShares[]

* of size n to store number of shares.

*/

int numOfShares[n];

/*

* Now we declare double type array named buyingPrice[]

* of size n to store buying price per share.

*/

double buyingPrice[n];

/*

* Now we declare double type array named currentPrice[]

* of size n to store current price per share.

*/

double currentPrice[n];

/*

* Now we declare double type array named yearlyFees[]

* of size n to store yearly fees.

*/

double yearlyFees[n];

/*

* ============== TASK 1 ENTERING DATA INTO ABOVE ARRAYS =============

* Using for loop we enter data for each stock in each iteration.

*/

for(int i=0;i<n;i++){

cout<<“nIteration number ::”<<(i+1)<<endl;

cout<<“Enter stock name::”;

/*

* To get the string with spaces I have used following getline function

*/

std::getline(std::cin >> std::ws, stockName[i]);

cout<<“Enter number of shares::”;

cin>>numOfShares[i];

cout<<“Enter Buying price per share::”;

cin>>buyingPrice[i];

cout<<“Enter Current price per share::”;

cin>>currentPrice[i];

cout<<“Enter Yearly fees::”;

cin>>yearlyFees[i];

}

cout<<endl;

/*

* ================== TASK 2 =================

* I am declaring three arrays named initialCost[], currentCost[] and profit[]

* All are of size n and they are of type double.

* Their value are calculated using function.

*/

double initialCost[n];

double currentCost[n];

double profit[n];

/*Calling respective functions to initialize above three arrays.*/

getInitialCost(initialCost,numOfShares,buyingPrice,n);

getCurrentCost(currentCost,numOfShares,currentPrice,n);

getProfit(profit,currentCost,initialCost,yearlyFees,n);

/*

*====================== TASK 3===============

* To print I have created printData() function that prints the data in

* required format. Required array are passed as parameters.

*/

/*

* Calling now function printData();

*/

cout<<“nn TASK 3 OUTPUT “<<endl;

printData(stockName,initialCost,currentCost,profit,n);

/*

* ==============================TASK 4========================

* For task 4 I have also created on function that calculates

* total values and print in same function.

* Function name is totalValues()

*/

cout<<“nn TASK 4 OUTPUT “<<endl;

totalValues(initialCost,currentCost,profit,n);

/*

* ===============Task 5=======================

* I have created another function to get count of positive, negative and broke even

* Function name is countValues()

*/

cout<<“nn TASK 5 OUTPUT “<<endl;

countValues(profit,n);

return 0;

}

void getInitialCost(double initialCost[],int numOfShares[],double buyingPrice[],int n){

/*

* Calculates initial cost for each stock.

*/

for(int i=0;i<n;i++){

initialCost[i]=numOfShares[i]*buyingPrice[i];

}

}

void getCurrentCost(double currentCost[],int numOfShares[],double currentPrice[],int n){

/*

* Calculates current cost for each stock.

*/

for(int i=0;i<n;i++){

currentCost[i]=numOfShares[i]*currentPrice[i];

}

}

void getProfit(double profit[],double currentCost[],double initialCost[],double yearlyFees[],int n){

/*

* Calculates profit for each stock.

*/

for(int i=0;i<n;i++){

profit[i]=currentCost[i]-initialCost[i]-yearlyFees[i];

}

}

void printData(string stockName[],double initialCost[],double currentCost[],double profit[],int n){

/*

* It just print the stocks with name,initial cost, current cost and profit with

* format specifiers.

*/

cout<<“Stock Name Initial Cost Current Cost Profit”<<endl;

/*

* Following variables are used to set spacing

*/

const char separator = ‘ ‘;

const int nameWidth = 20;

const int numWidth = 20;

for(int i=0;i<n;i++){

cout << left << setw(nameWidth) << setfill(separator) << stockName[i];

cout << left << setw(numWidth) << setfill(separator) << initialCost[i];

cout << left << setw(numWidth) << setfill(separator) << currentCost[i];

cout << left << setw(numWidth) << setfill(separator) << profit[i]<<endl;

// cout<<set” “<<stockName[i]<<” “<<initialCost[i]<<” “<<currentCost[i]<<” “<<profit[i]<<endl;

}

}

void totalValues(double initialCost[],double currentCost[],double profit[],int n){

/*

* It just calculate required total values and print them

*/

double totalInitialCost=0,totalCurrentCost=0,totalProfit=0;

for(int i=0;i<n;i++){

totalInitialCost+=initialCost[i];

totalCurrentCost+=currentCost[i];

totalProfit+=profit[i];

}

cout<<“Total Initial Cost is “<<totalInitialCost<<“$”<<endl;

cout<<“Total Current Cost is “<<totalCurrentCost<<“$”<<endl;

cout<<“Total Profit is “<<totalProfit<<“$”<<endl;

}

void countValues(double profit[],int n){

/*

* CALCULATES POSITIVE NEGATIVE AND BROKE EVEN AND PRINT THEM

*/

int positiveCount=0,negativeCount=0,brokeEven=0;

for(int i=0;i<n;i++){

if(profit[i]<0){

negativeCount++;

}else if(profit[i]>0){

positiveCount++;

}else{

brokeEven++;

}

}

cout<<“Count of stocks with positive profit is “<<positiveCount<<endl;

cout<<“Count of stocks with negative profit is “<<negativeCount<<endl;

cout<<“Count of stocks with broke even profit is “<<brokeEven<<endl;

}

*Output::*