Question: Fill in the missing code for this C++ program with the following main menu options (instructions, program and sample output are provided below) and achieve
Fill in the missing code for this C++ program with the following main menu options (instructions, program and sample output are provided below) and achieve the correct output for this program:
If any of the instructions below are not followed and output for this program doesnt yield the same result as provided in the sample output. 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. The programs output must yield the same results as the sample output provided below.
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)!
Sample output for the PlayingTheMarket.cpp:
Choice: 1
Number of shares: 10
Share price: 12
Choice: 1
Number of shares: 20
Share price: 18
Choice: 1
Number of shares: 25
Share price: 20
Choice: 2
Number of shares in portfolio: 55
Choice: 3
Number of shares: 30
Share price: 35
Choice: 4
Current total capital gains: 460
//---------------------------------- 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::queue
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 sharesHeld;
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
Get step-by-step solutions from verified subject matter experts
