Question

In: Computer Science

We need a Stock and Bond trading application. Here is what is required: Create Menu with...

We need a Stock and Bond trading application. Here is what is required:

Create Menu with the options organized as below:

 ********************************************************************************
     A. Buy Bonds                B. Sell Bonds
     C. Buy Stocks               D. Sell Stocks       E. Short Stock Sale

   X. Exit

Here are the steps involved.

  1. Create a char variable named menuChoice.
  2. Display the menu as described above.
  3. Prompt for the menu choice (A-E,X) (Assume the input will be uppercased).
  4. Use an IF statement to validate that the choices are within A through E or is X. If not, display "Invalid choice" and issue a return 5; statement.
  5. Using a Switch statement, display the following for the given choices.
    1. User selected Buy Bonds
    2. User selected Sell Bonds
    3. User selected Buy Stocks
    4. User selected Sell Stocks
    5. User selected Short Stock Sale

                  X. Done!

       6. The program will end after Step 5 is completed.

Solutions

Expert Solution

Working code implemented in C++ and appropriate comments provided for better understanding.

Source Code for main.cpp:

//An application for Stock and Bond Trading.

//Declare our included libraries
#include <iostream>   //for using cout & cin
#include <chrono> //for using microseconds & seconds
#include <thread> //for using sleep_for


//Simplistic approach using switch casing.

int main()   //Usually I would not stick everything into main, but for the sake of learning we shall.
{
   //Declare variables.
   char menuChoice;
   bool isRunning = true;
   enum choices{A, B, C, D, E, X};

   //Declare our loop.
   while(isRunning)   //While the program is running, loop.
   {
       std::this_thread::sleep_for(std::chrono::seconds{ 5 }); //Sleep for 5 seconds.
       system("cls");
       std::cout << "A. Buy Bonds\tB. Sell Bonds\nC. Buy Stocks\tD. Sell Stocks\nE. Short Stock Sale\tX. Exit\nPlease input the letter corresponding with your choice: ";   //Output Choices
       std::cin >> menuChoice;   //Input user choice.

       if(menuChoice == 'A' || menuChoice == 'B' || menuChoice == 'C' || menuChoice == 'D' || menuChoice == 'E'
           || menuChoice == 'X' )   //Check for inputs to match parameters.
       {
           switch (1)   //Begin Switch Statement.
           {
           case 1: if (menuChoice == 'A')   //Cases 1 - 6, check if input matches parameter.
           {
               std::cout << "\nUser Selected Buy Bonds";   //Output.
               break;   //Break.
           }
           case 2: if (menuChoice == 'B')
           {
               std::cout << "\nUser Selected Sell Bonds";
               break;
           }
           case 3: if (menuChoice == 'C')
           {
               std::cout << "\nUser Selected Buy Stocks";
               break;
           }
           case 4: if (menuChoice == 'D')
           {
               std::cout << "\nUser Selected Sell Stocks";
               break;
           }
           case 5: if (menuChoice == 'E')
           {
               std::cout << "\nUser Selected Short Stock Sale";
               break;
           }
           case 6: if (menuChoice == 'X')
           {
               std::cout << "\nX. Done!";
               isRunning = false;   //Make isRunning false, end the loop.
               //Adding a break here is redundant.
           }
           }
       }
       else
       {
           std::cout << "\nInvalid Choice.\n";
           return 5;
       }
   }
  
   return 0;
}

Sample Output Screenshots:


Related Solutions

We need to create basic program that will simply display a menu and allow the user...
We need to create basic program that will simply display a menu and allow the user to select one of the choices. The menu should be displayed such that each option will be numbered, as well as have one capital letter so as to indicate that either the number or the designated letter can be entered to make their choice. Once the choice is made, the sub-menu for that selection should be displayed. Colors with an odd number of letters...
Use C++ to create an application that provide the menu with two options TemperatureConverter_Smith.cpp MENU CONVERTER...
Use C++ to create an application that provide the menu with two options TemperatureConverter_Smith.cpp MENU CONVERTER TEMPERATURE – JAMES SMITH Convert Fahrenheit temperature to Celsius Convert Celsius temperature to Fahrenheit Exit CASE 1: Convert Fahrenheit temperature to Celsius -Display the message to ask to enter Fahrenheit degree from the keyboard -Use the following formula to convert to Celsius degree         Celsius Temperature = (Fahrenheit Temperature – 32) * 5/9 ; -Display the output as below: TemperatureConverter_Smith.cpp TEMPERATURE CONVERTER – JAMES...
C++ Linkedlist Create a food menu so the customer can see what we are selling, if...
C++ Linkedlist Create a food menu so the customer can see what we are selling, if the users place order that not on the menu, prompt the users to enter again. Food code and food must be matched when users enter.
I need to create a code in C++ that first has a menu animation of game...
I need to create a code in C++ that first has a menu animation of game Pacman, a score label in the map, and a bar that have the lives of pacman in the map.
Use menu based functionality and validation loops to create a new customer bonus fruit package application...
Use menu based functionality and validation loops to create a new customer bonus fruit package application for the Dirt to Dish discount produce company. The program you create will prompt the user to enter a number to select one of three bonus pack options: 1 for Apple pack 2 for Orange pack 3 for Banana pack **Use input validation to ensure a valid option has been selected before proceeding. Use variables to keep track of how many of each fruit...
A stock that does not pay a dividend is trading at $73.50. A riskless bond that...
A stock that does not pay a dividend is trading at $73.50. A riskless bond that will pay $100 after a year is trading at $97. A European call option on the stock with strike price of $65 and one year to maturity is trading at $5.00. Propose an arbitrage strategy and prove that it is an arbitrage strategy.
A stock that does not pay dividend is trading at $73.1. A riskless bond that will...
A stock that does not pay dividend is trading at $73.1. A riskless bond that will pay $100 after a year is trading at $97. A European call option on the stock with strike price of $64 and one year to maturity is trading at $5.8. Propose an arbitrage strategy and prove that it is an arbitrage strategy.
I need to convert the following into C++. The general idea is to create an application...
I need to convert the following into C++. The general idea is to create an application that can support 10 ID's and 10 grades. It needs to calculate the grade average of said ID, and determine if it is an below or above a certain average, ergo A or C. string[10] studentIDArray int[10] gradeArray int averageGrade for(int i = 0; i < gradeArray; i++) { averageGrade += gradeArray[i] } averageGrade = averageGrade / sizeof(gradeArray) for(int i = 0; i <...
Stock that doesn't pay a dividend is trading at $5. A riskless bond that will pay...
Stock that doesn't pay a dividend is trading at $5. A riskless bond that will pay $100 after a year is trading at $94. A European call option on the stock with strike price of $60 and one year to maturity is trading at $6.1. Devise an arbitrage strategy and prove that it works in all scenarios.
MUST BE DONE IN C (NOT C++)) Here, we will create a structure that resembles a...
MUST BE DONE IN C (NOT C++)) Here, we will create a structure that resembles a university’s profile (you can pick any university name, just so long as the program runs properly). The structure must contain 5 members: - One member for number of undergraduate students - One member for number of graduate students - One member for number of classrooms - One member for the name of the university (an array) - One member for the term (fall, summer...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT