C programming Stock Market Write a program to help a local s
C++ programming
(Stock Market) Write a program to help a local stock trading company automate its systems. The company invests only in the stock market. At the end of each trading day, the company would like to generate and post the listing of its stocks so that investors can see how their holdings performed that day. We assume that the company invests in, say, 10 different stocks. The desired output is to produce two listings, one sorted by stock symbol and another sorted by percent gain from highest to lowest. The input data is provided in a file in the following format: symbol openingPrice closingPrice todayHigh todayLow prevClose vol ume For example, the sample data is: MSMT 112.50 115.75 116.50 111.75 113.50 6723823 CBA 67.50 75.50 78.75 67.50 65.75 378233 The first line indicates that the stock symbol is MSMT, today\'s opening price w 112.50, the closing price was 115.75, today\'s high price was 116.50, today\'s lo price was 111.75, yesterday\'s closing price was 113.50, and the number of shar currently being held is 6723823. The listing sorted by stock symbols must be of the following form: Financial Report Stock Symbol Open Close High Low Previous Percent Close Today Gain Volume ABC 123.45 130.95 132.00 125.00 120.50 867% 964% 0.99% 5·33% 10000 5000 25000 15000 30920 AOLK80.00 75.00 82.00 74.00 83.00 CSCO 100.00 102.00 105.00 98.00 101.00 IBD 68.00 71.00 72.00 67.00 75.00 MSET 120.00 140.00 145.00 140.00 115.00 21.74% Closing Assets: $9628300.00 Develop this programming exercise in two steps. In the first step (part a), design and implement a stock object. In the second step (part b), design and implement an object to maintain a list of stocks a. (Stock Object) Design and implement the stock object. Call the class that captures the various characteristics of a stock object stockType. The main components of a stock are the stock symbol, stock price, and number of shares. Moreover, we need to output the opening price,Solution
#ifndef STOCKTYPE_H
#define STOCKTYPE_H
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
class stockType
{
public:
stockType(string symbol=\"\", double openPrice=0.0, double closePrice=0.0, double highPrice=0.0,
double lowPrevPrice=0.0, double closePrevPrice=0.0, int shares=0);
friend istream& operator>>(istream& ins, stockType& stock);
friend ostream& operator<<(ostream& outs, const stockType& stock);
//sets the variables
void setStockInfo(string syms, double open, double close, double high,
double lowPrev, double closePrev, int no_of_shares);
//calculates the gain
void calculateGain(double closeP, double prevP);
bool operator==(const stockType& stock1) const;
bool operator!=(const stockType& stock1) const;
bool operator<=(const stockType& stock1) const;
bool operator<(const stockType& stock1) const;
bool operator>=(const stockType& stock1) const;
bool operator>(const stockType& stock1) const;
//member functions
string getSymbols()const {return symbols;}
double getOpenPrice()const {return open_price;}
double getClosePrice()const {return close_price;}
double getHighPrice()const {return high_price;}
double getLowPrevPrice()const {return low_prev_price;}
double getClosePrevPrice()const {return close_prev_price;}
double getShares()const {return no_shares;}
double getGain()const {return gain;}
private:
string symbols;
double open_price, close_price, high_price, low_prev_price, close_prev_price, gain;
int no_shares;
};
#include \"stockType.h\"
stockType::stockType(string symbol, double openPrice, double closePrice, double highPrice,
double lowPrevPrice, double closePrevPrice, int shares)
{
setStockInfo(symbol, openPrice, closePrice, highPrice, lowPrevPrice, closePrevPrice, shares);
}
void stockType::setStockInfo(string syms, double open, double close, double high,
double lowPrev, double closePrev, int no_of_shares)
{
symbols = syms;
open_price = open;
close_price = close;
high_price = high;
low_prev_price = lowPrev;
close_prev_price = closePrev;
no_shares = no_of_shares;
}
istream& operator>>(istream& ins, stockType& stock)
{
ins>>stock.symbols;
ins>>stock.open_price;
ins>>stock.close_price;
ins>>stock.high_price;
ins>>stock.low_prev_price;
ins>>stock.close_prev_price;
ins>>stock.no_shares;
stock.calculateGain(stock.close_price, stock.close_prev_price);
return ins;
}
ostream& operator<<(ostream& outs, const stockType& stock)
{
outs<<stock.getSymbols()
<<fixed<<showpoint<<setprecision(2)
<<setw(10)<<stock.getOpenPrice()<<setw(10)
<<stock.getClosePrice()<<setw(10)
<<stock.getHighPrice()<<setw(10)
<<stock.getLowPrevPrice()<<setw(11)
<<stock.getClosePrevPrice()
<<setw(10)<<stock.getGain()<<\"%\"<<setw(13)
<<stock.getShares()<<endl<<endl;
return outs;
}
void stockType::calculateGain(double closeP, double prevP)
{
gain = ((closeP - prevP)/(prevP)*100);
}
bool stockType::operator==(const stockType& stock1) const
{
return (symbols==stock1.symbols);
}
bool stockType::operator!=(const stockType& stock1) const
{
return (symbols!=stock1.symbols);
}
bool stockType::operator>=(const stockType& stock1) const
{
return (symbols>=stock1.symbols);
}
bool stockType::operator>(const stockType& stock1) const
{
return (symbols>stock1.symbols);
}
bool stockType::operator<=(const stockType& stock1) const
{
return (symbols<=stock1.symbols);
}
bool stockType::operator<(const stockType& stock1) const
{
return (symbols<stock1.symbols);
}
#ifndef stockListType_H
#define stockListType_H
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include \"stockType.h\"
using namespace std;
class stockListType
{
public:
stockListType()
{
}
void insert(const stockType& item);
void sortStockSymbols();
void sortStockGain();
void printStockSymbols();
void printStockGain();
private:
vector<int> indexByGain;
vector<stockType> list;
};
#endif
#include <algorithm>
#include \"stockListType.h\"
void stockListType::insert(const stockType& item)
{
list.push_back(item);
}
void stockListType::printStockSymbols()
{
int k = 0;
double closing_assets = 0;
cout<<\"***************** First Investor\'s Heaven ******************************\"<<endl<<endl;
cout<<\" Financial Report \"<<endl;
cout<<\"********************************************************************************\"<<endl<<endl;
cout<<\"Stock Today Previous Percent\"<<endl<<endl;
cout<<\"Symbol Open Close High Low Close Gain Volume\"<<endl;
cout<<\"------ ------ ------ ------ ------- ------- ------- -------\"<<endl;
for (k=0; k<list.size(); k++)
{
cout<<list[k]<<endl;
closing_assets =+(list[k].getClosePrice()*list[k].getShares());
}
cout<<endl<<\"****************************************\";
cout<<endl<<\"* Closing Assests: \"<<closing_assets<<endl;
cout<<\"****************************************\"<<endl;
}
void stockListType::printStockGain()
{
int k = 0;
double closing_assets =0;
cout<<\"***************** First Investor\'s Heaven ******************************\"<<endl<<endl;
cout<<\" Financial Report \"<<endl;
cout<<\"********************************************************************************\"<<endl<<endl;
cout<<\"Stock Today Previous Percent\"<<endl<<endl;
cout<<\"Symbol Open Close High Low Close Gain Volume\"<<endl;
cout<<\"------ ------ ------ ------ ------- ------- ------- -------\"<<endl;
for (k=0; k<list.size(); k++)
{
cout<<list[k]<<endl;
closing_assets = closing_assets + (list[k].getClosePrice()*list[k].getShares());
}
cout<<endl<<\"****************************************\";
cout<<endl<<\"* Closing Assests: \"<<closing_assets<<endl;
cout<<\"****************************************\"<<endl;
}
void stockListType::sortStockSymbols()
{
sort(list.begin(), list.end());
}



