In: Computer Science
In C++
Design a program to calculate the stock purchasing and selling transactions.
1. ask the user to enter the name of the stock purchased, the number of share purchased, and the price per share purchased
2. assume the buyer pays 2% of the amount he paid for the stock purchase as broker commission
3. assume that the buyer sold all stocks. Ask the user to enter the price per share sold.
4. assume the buyer will pay another 2% of the amount he received for selling the stock as broker commission
the program will calculate and display:
1. the amount of money he paid for the stock purchase
2. the amount of commission he paid to the broker for purchase transaction
3. the amount he sold the stock for
4. the amount of commission he paid to the broker for purchase selling
5. the possible profit he made after selling his stock and paying the two commissions to the broker
Requirements:
1. program well documented
#include <iostream>
using namespace std;
int main()
{
string name;
int number,bPrice,sPrice,bTotal,sTotal;
int sCommision,bCommision,profit;
//readin the stack details
cout<<"Enter the name of the stock: ";
cin>>name;
cout<<"Enter number of shares purchased: ";
cin>>number;
cout<<"Price of each share : ";
cin>>bPrice;
// calculating the total amount for stock purchase
bTotal=bPrice * number;
// finding the broker commission
bCommision=bTotal*0.02;
//reading the selling price
cout<<"Enter the price of share sold: ";
cin>>sPrice;
// finding the total amount he got
sTotal=sPrice*number;
// finding the commission
sCommision=sTotal*0.02;
// finding the profit
profit=sTotal-bTotal;
//removing the 2 broker commission from the profit
profit=profit-bCommision;
profit=profit-sCommision;
//printing the details
cout<<"Total amount paid for stock purchase :
"<<bTotal<<endl;
cout<<"Amount paid for Broker for stock purchase :
"<<bCommision<<endl;
cout<<"Amount after selling the stock :
"<<sTotal<<endl;
cout<<"Profit : "<<profit;
}