Question
[Repost] Fill in the missing code for this C++ program with the following main menu options (instructions and program provided below): If any of the
[Repost] Fill in the missing code for this C++ program with the following main menu options (instructions and program provided below):
If any of the instructions below are not followed. I will automatically downvoted.
We buy:
100 shares at $20 each on day 1;
20 shares at $24 each on day 2;
200 shares at $36 each on day 3
We then sell 150 shares at $30 each on day 4.
Of these, 100 were bought on day 1, 20 were bought on day 2, and 30 were bought on day 3.
The capital gain in this case would therefore be 100*$10 + 20*$6 + 30*(-$6) = $940.
We will represent a single share of the stock by a double, which is the purchase price.
1. Buy
2. Number of Shares Held
3. Sell
4. Total Capital Gain So Far
5. Quit
If option 1 (Buy) is chosen, the user should be prompted to enter how many shares they wish to buy and at what price.
These shares should be added to the queue of currently held shares
Then, prompt the user with the main menu.
If option 2 (Number of Shares Held) is chosen, the number of shares held in the queue of shares should be printed.
Then, the user should be prompted with the main menu.
If option 3 (Sell) is chosen, the user should be prompted to enter the number of shares they wish to sell and at what price.
If the number of shares to be sold exceeds the number of shares in the queue, an error message (see code below) should be printed and the program terminated.
The program should
remove these shares from the queue; and
update the capital gain/loss; and
Then, prompt the user with the main menu.
If option 4 is chosen, the total capital gain (or loss) from all transactions so far should be displayed.
Then the user should be prompted with the main menu again.
If any other entry is made, the program should print goodbye and terminate.
To complete this program, you should fill in the missing code in the PlayingTheMarket.cpp (below). The only strings you may output are those defined in the file.
Do not modify any of the code in this program besides completing the code within the while loop to complete this programs functionally (mentioned above)!
//---------------------------------- PlayingTheMarket.cpp ---------------------------
#include
#include
#include
const std::string numberOfSharesPrompt("Number of shares: ");
const std::string pricePrompt("Share price: ");
const std::string gainsReportString("Current total capital gains: ");
const std::string sharesHeldReportString(" Number of shares in portfolio: ");
const std::string notEnoughSharesString("Insufficient shares; terminating ");
const std::string finalMessageString("Goodbye ");
int main_menu()
{
std::cout << std::endl;
int choicenum;
std::cout << "Please enter the value corresponding to your choice" << std::endl;
std::cout<< "1: Buy shares ";
std::cout<< "2: Number of Shares Held ";
std::cout<< "3: Sell shares ";
std::cout<< "4: Total Capital Gains So Far ";
std::cout<< "5: Quit ";
std::cout << " Choice: ";
std::cin >> choicenum;
return choicenum;
}
int main()
{
std::queue
int numshares;
double buyPrice;
double sellPrice;
double CapGains = 0.0;
int choice = main_menu();
std::cout << std::endl;
while(1 <= choice && choice <= 4) {
// fill in the missing code
}
std::cout << finalMessageString;
return 0;
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started