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

You have decided to buy some stock in SBU Computing, Inc. The stock currently co

ID: 3884532 • Letter: Y

Question

You have decided to buy some stock in SBU Computing, Inc. The stock currently costs $32.87 per share. Your stockbroker charges a 2% commission for each transaction (meaning that he/she receives 2% of the total amount you pay for a stock purchase). A few weeks later, the stock price has risen to $33.92 per share, so you decide to sell all of your shares. Once again, your stockbroker earns a commission equal to 2% of the amount you receive for the stock. Will you make money or lose money on the deal?

For this problem, we will write a program that reads in the number of shares to purchase from the user. It then calculates and prints the total price paid for the stock shares, the broker's commission on the purchase, the price the stock shares were sold for, the broker's commission on the sale, and your ultimate profit (or loss) on the transaction.

a) We will begin by asking the user to enter the number of stock shares to purchase (assume that the user always enters an integer value, like 5; you can't buy a fraction of a share for this program!). To do this, we need to use the input command, and convert the result to an integer. Be sure to save the result (the user's input) into a variable!

shares = int( input("How many shares do you wish to purchase? ") )

B)Next, calculate the total cost of the shares of stock:

share_cost = shares * 32.87 Replace shares with whatever variable name you used for the previous step.

C) Our broker charges a 2% commission on any transaction. We can calculate this by multiplying the cost of the shares by 0.02:

commission1 = share_cost * 0.02

D)  How much did we spend in all to buy the stock? That's just the cost of the shares plus the broker commission:

cost = share_cost + commission1

E)Add some print commands to print the results of the calculations from the previous steps.

F)Repeat the previous steps, with new variables, to calculate the amount of money we made by selling the stock at $33.92 per share. Don't forget that, this time, the broker's commission should be subtracted from our earnings!

G)Finally, calculate your final profit (or loss) by subtracting the price you initially paid from the amount you eventually made. Print this value with a descriptive message (a positive number indicates a profit, while a negative number indicates a loss).

Explanation / Answer

#include<iostream>
using namespace std;
//Main method definition
int main()
{
//To store number of shares
int noShare;
//To store share cost, commission, first cost, second cost, profit or loss
double shareCost, commission, totalCost1, totalCost2, profitLoss;
//Accept number of shares purchase
cout<<"How many shares do you wish to purchase? ";
cin>>noShare;
//Calculates share cost purchase
shareCost = noShare * 32.87;
//Calculates the commission purchase
commission = shareCost * 0.02;
//Calculates the purchasing total cost purchase
totalCost1 = shareCost + commission;
//Displays the complete information purchase share
cout<<" Share Purchase Information";
cout<<" Number of Shares: "<<noShare<<" Share Cost: "<<shareCost<<" Commission: "<<commission<<" Total Cost: "<<totalCost1;
//Calculates share cost for sale
shareCost = noShare * 33.92;
//Calculates the commission sale
commission = shareCost * 0.02;
//Calculates the purchasing total cost sale
totalCost2 = shareCost - commission;
//Displays the complete information sale share
cout<<" Share Sale Information";
cout<<" Number of Shares: "<<noShare<<" Share Cost: "<<shareCost<<" Commission: "<<commission<<" Total Cost: "<<totalCost2;
//Calculate profit or loss
profitLoss = totalCost1 - totalCost2;
//If the value is zero no profit no loss
if(profitLoss == 0)
cout<<" No Profit No Loss: "<<profitLoss;
//Value less than zero loss
else if(profitLoss < 0)
cout<<" Loss: "<<profitLoss;
//Value greater than zero profit
else
cout<<" Profit: "<<profitLoss;
}//End of main

Sample Run:

How many shares do you wish to purchase? 5

Share Purchase Information
Number of Shares: 5
Share Cost: 164.35
Commission: 3.287
Total Cost: 167.637

Share Sale Information
Number of Shares: 5
Share Cost: 169.6
Commission: 3.392
Total Cost: 166.208
Profit: 1.429

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