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

The profit from the sale of a stock can be calculated asfollows: Profit= ((NS x

ID: 3617107 • Letter: T

Question

The profit from the sale of a stock can be calculated asfollows:

Profit= ((NS x SP) - SC) - ((NS x PP) + PC)

where NS is the number of shares, SP is the sale price per share,SC is the sale commission paid, PP is the purchase price per share,and PC is the purchase commission paid. If the calculation yields apositive value, than the sale of the stock resulted in a profit. Ifthe calculation yields a negative number, than the sale resulted ina loss.

Write a function that accepts as arguments the number of shares,the purchase price per share, the purchase commission paid, thesale price per share, and the sale commission paid. The functionshould return the profit (or loss) from the sale of stock.

Demonstrate the function in a program that asks the user to enterthe necessary data and displays the amount of the profit orloss.

Explanation / Answer


#include<iostream> using namespace std;
double calProfit(double ns,double sp, double sc, double pp,double pc); int main() { double ns, sp, sc, pp, pc;
cout<<"Enter the number of Shares: "; cin>>ns;
cout<<" Enter the Price per Share: "; cin>>sp;
cout<<" Enter the Sale Commission Paid: "; cin>>cs;
cout<<" Enter the Purchase Price per Shares: "; cin>>pp;
cout<<" Enter the Price of Purchase commission paid:"; cin>>pc;
double amount=calProfit(ns,sp,cs,pp,pc);
if(amoun<0) cout<<" Total Lose="<<amount; else cout<<"Profit="<<amount;

system("pause"); return 0; }

double calProfit(double ns,double sp, double sc, double pp,double pc) { double Profit= ((NS x SP) - SC) - ((NS x PP) + PC); return Profit; } #include<iostream> using namespace std;
double calProfit(double ns,double sp, double sc, double pp,double pc); int main() { double ns, sp, sc, pp, pc;
cout<<"Enter the number of Shares: "; cin>>ns;
cout<<" Enter the Price per Share: "; cin>>sp;
cout<<" Enter the Sale Commission Paid: "; cin>>cs;
cout<<" Enter the Purchase Price per Shares: "; cin>>pp;
cout<<" Enter the Price of Purchase commission paid:"; cin>>pc;
double amount=calProfit(ns,sp,cs,pp,pc);
if(amoun<0) cout<<" Total Lose="<<amount; else cout<<"Profit="<<amount;

system("pause"); return 0; }

double calProfit(double ns,double sp, double sc, double pp,double pc) { double Profit= ((NS x SP) - SC) - ((NS x PP) + PC); return Profit; }