Question: PROBLEM: Create a menu driven application to keep track of your stock portfolio. Create a structure called StockInfo that holds: Company name Number of shares
PROBLEM: Create a menu driven application to keep track of your stock portfolio. Create a structure called StockInfo that holds:
Company name
Number of shares
Purchase price
Current price
The current value of a stock is calculated as:
Number of shares * (current price purchase price)
Create an array in main that can hold a maximum of 10 StockInfo objects.
Your program will have the following menu options:
1-Add Stock
2-Display Profit/Loss
3 Exit Program
For option 1
Prompt the user for info to add one new stock to the array:
Enter company name: Amgen
Number of shares? 200
Purchase price? 50.75
Current price? 75.625
Make sure there is room in the array if it is full, give a message to the user.
Otherwise, store in the next available position.
For option 2
Display a report based on all the stocks in the array as shown below:
Portfolio Report ================ Company Profit(Loss) Amgen $ 4975.00 Delta $ -1450.00 Total value $ 3525.00
Validation of number of shares and current/purchase price is optional. I will only test with valid data. Your program should make sure the menu option is valid (give a message if not), and that you do not overflow your array.
***USE FUNCTIONS to organize your code!
Main should ONLY have the loop to control the menu and calls to functions for each option:
For option1: two possibilities, choose one
addRecord needs the array and the next available position to add a new stock. Prompts for the data and adds the element to the array
or
createStock takes no input. Prompts for the data and returns a Stock object
For option 2:
displayReport needs the array and the number of ACTUAL items used in the array
You should code and test one function at a time!
Testing show one run with THIS DATA, and another with data OF YOUR OWN
use option 1 to add a stock
Company shares purchase current
Amgen 200 50.75 75.625
use option 1 to add a stock
Delta 100 111.75 97.25
Option 2 to show report
Option 1 three more times to add these stocks
Company shares Purchase Current
Cisco 400 22.00 16.50
Intuit 250 38.00 44.50
ToysRUs 300 15.90 17.95
Option 2 for report
Quit
-----------------------------------------------------------------------------------------------------------------------
this is my code so far , if someone can help me finish it
#include
#include
using namespace std;
struct StockInfo
{
string coname;
int numShares;
double PurPrice;
double CurrPrice;
};
int main()
{
const int size =2;
StockInfo portfolio[size];
int choice;
do
{
cout << endl
<< " 1 - Add a stock. "
<< " 2 - Display Profit/loss. "
<< " 3 - Exit Program. "
<< " Enter your choice and press return: ";
cin >> choice;
switch (choice)
{
case 1:
for(int i =0;i< size ;i++)
{
cout << "enter company's name please:"< cin>>portfolio[i].coname; cout << "enter the number of shares bought:"< cin >> portfolio[i].numShares; cout <<"What was the purchase price?"< cin >> portfolio[i].PurPrice; cout << "what is the current price of the share?"< cin >> portfolio[i].CurrPrice; cin.ignore(); } break; case 2: cout<<"Portfolio Report ================"< cout<<"Company\t\tProfit(Loss)"< for(int i=0; i< size; i++) { double Profitloss= portfolio[i].numShares * (portfolio[i].CurrPrice-portfolio[i].PurPrice); cout< } //Number of shares * (current price purchase price) break; case 3: //Exit the program break; default: cout << "Not a Valid Choice. "<< "Choose again. "; break; } } while(choice <3); return 0; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
