Here's the directions: I'll note the code where I'm currently having issues. I haven't tested the calculations because I missed something with the first half of the code and I don't know what I'm missing. I'm sorry if this is a headache Thanks for the help.
In this assignment, you will develop a C++ program that calculates gain or loss of a stock you purchased. Go to the website “Yahoo! Finance” and select a technology stock for your assignment. Some examples of technology stocks include Apple, Cisco, IBM, Teradata, etc….
In your program, the user will enter the following pieces of information:
• the name of the stock
• the stock symbol
• the number of shares purchased
• the purchase price
• the commission paid
Requirements for Your Program:
Here are additional requirements for your program:
1. Have the user enter the company name and stock symbol
2. Have the user enter the number of shares purchased
3. Have the user enter the price per share, sharePrice.
4. Calculate the sharesCost which is the number of shares * price per share
5. When you purchase stock you need to pay a commission based on the number of shares purchased times the purchase price. Multiply the commission rate times shareCost.
6. Add the sharesCost to the commission to calculate total cost of purchase
7. After holding the stock for a period of time you may want to sell. Use a random number generator to simulate a percentage change in your sale price. The generator will generate a number between 1 and 100 but since you want a percentage, divide the number generated by 100. See pages 127-129 for how to create a random number and do not forget to seed the random number generator.
8. To determine if the change in the stock value is positive or negative (the stock market can go down or up), toss a coin to generate a random outcome (gain or loss). Below is the code for flipping a coin.
9. Multiply percentage from step 7 by the profitLoss which will make the percentage positive or negative.
10. Multiple percentage from step 9 by the sharePrice and add it back to the sharePrice. Your formula will look like this NewSharePrice = (percentGain * sharePrice) + sharePrice. percentGain was calculated in step 9.
11. Calculate the new value of your shares multiple the newSharePrice times the number of shares.
12. Now you are going to sell your shares. When you sell stock you need to pay commission to your broker. The commission on the sale needs to be recalculated (commission times the new value of your stock). The profit (or loss) you make will be what you paid for the stock (including the commission) minus what you netted from the sale (the new value of your shares minus the commission).
13. Did you make money or lose money on your stock purchase? Calculate your gain or loss.
14. Your rate of return is your profit divided by the original cost. This percentage could be negative (if your stock decreased in value) or positive (if your stock increased in value).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
|
#include <iostream>
#include <string>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <ctime>
using namespace std;
int main()
{
double stockSymbol, shares, sharePrice, commissionRate, shareCost, totalCost, commission;
double percentGain, newSharePrice, newValue, sellCommission, profit, returnRate;
int percentChange, profitLoss, flip;
string companyName;
const int MAX = 100, MIN = 1;
cout << "\nPurchase Transaction: ";
cout << "\nEnter company name: ";
cin.ignore();
getline(cin, companyName);
cout << "\nEnter stock symbol: ";
cin >> stockSymbol;
//The program won't allow me to enter any in for price per share and number of shares
cout << "\nEnter the number of shares purchased: ";
cin >> shares;
cout << "\nEnter purchase price per share: ";
cin >> sharePrice;
cout << "\nEnter commission rate ex 1% as 0.01";
cin >> commissionRate;
commission = commissionRate * sharePrice;
shareCost = shares * sharePrice;
totalCost = (commission * shareCost) + shareCost;
cout << setprecision(1) << fixed;
cout << "\nCost of shares = $" << shareCost;
cout << "\nCommission rate = " << commissionRate;
cout << "\nCommission charged = $" << commission;
cout << "\nTotal cost of purchase = $" << totalCost;
// I'm not sure if I'm entering the percentChange in correctly
unsigned seed = time(0);
srand(seed);
percentChange = (rand() % (MAX - MIN + 1)) + MIN / 100;
//I entered the flip code verbatim what the directions said (I'm not sure that looks correct)
flip = rand() % 2 + 1;
if (flip == 1)profitLoss = 1;
else profitLoss = -1;
percentGain = percentChange * profitLoss;
newSharePrice = (percentGain * sharePrice) + sharePrice;
newValue = newSharePrice * shares;
sellCommission = commission * newValue;
//#12 The profit ,loss> section of the directions is confusing, I'm not sure what my professor is asking for.
profit =
returnRate = profit / sharePrice;
cout << "\nThe simulated projected profit <loss> of the sale of your shares is";
cout << "\nNew share price is $" << newSharePrice;
cout << "\nNew value of your stock is $" << newValue;
cout << "\nAfter selling " << companyName << "\nyou recieved $" << sellCommission;
cout << "\nThe profit <loss> is $" <<
system("pause");
return (0);
}
|