Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hello everyone I am in need of an answer and the process you did to get the answ

ID: 640768 • Letter: H

Question

Hello everyone I am in need of an answer and the process you did to get the answer. It has to do with C++ Programming: from problem analysis to program design, Chap 13 programming exercise #19. I need to write a program to help a local stock trading company. There needs to be a stock object called stockType, (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 volume
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

Explanation / Answer

#ifndef StockType

#define StockType

#include <iostream>

#include <fstream>

#include <string>

#include <iomanip>

using namespace std;

class stockType

{

     friend ostream& operator<< (ostream&, const stockType&);

     friend ifstream& operator>> (ifstream&, stockType&);

public:

     void setStockInfo(string symbol, double openPrice,

          double closeProce, double high,

          double Low, double prevClose,

          int shares);

     string getSymbol();

     double getPercentChange();

     double getOpenPrice();

     double getClosePrice();

     double getHighPrice();

     double getLowPrice();

     double getPrevPrice();

     int getnoOfShares();

     stockType();

     stockType(string symbol, double openPrice,

          double closeProce, double high,

          double Low, double prevClose,

          int shares);

     bool operator ==(stockType other);

     bool operator !=(stockType other);

     bool operator <=(stockType other);

     bool operator >=(stockType other);

     bool operator >(stockType other);

     bool operator <(stockType other);

private:

     string stockSymbol;

     double todayOpenPrice;

     double todayClosePrice;

     double todayHigh;

     double todayLow;

     double yesterdayClose;

     double percentChange;

     int noOfShares;

};

//default constructor

stockType::stockType()

{

     stockSymbol = "***";

     todayOpenPrice = 0.00;

     todayClosePrice = 0.00;

     todayHigh = 0.00;

     todayLow = 0.00;

     yesterdayClose = 0.00;

     noOfShares = 0;

}

//constructor

stockType::stockType(string symbol, double openPrice,

     double closeProce, double high,

     double Low, double prevClose,

     int shares)

{

          setStockInfo(symbol, openPrice, closeProce, high, Low, prevClose, shares);

}

void stockType::setStockInfo(string symbol, double openPrice,

     double closeProce, double high,

     double low, double prevClose,

     int shares){

          stockSymbol = symbol;

          todayOpenPrice = openPrice;

          todayClosePrice = closeProce;

          todayHigh = high;

          todayLow = low;

          yesterdayClose = prevClose;

          noOfShares = shares;

}

string stockType::getSymbol(){

     return stockSymbol;

}

double stockType::getPercentChange(){

     percentChange = ((todayClosePrice - yesterdayClose) / yesterdayClose) * 100;

     return percentChange;

}

double stockType::getOpenPrice(){

     return todayOpenPrice;

}

double stockType::getClosePrice(){

     return todayClosePrice;

}

double stockType::getHighPrice(){

     return todayHigh;

}

double stockType::getLowPrice(){

     return todayLow;

}

double stockType::getPrevPrice(){

     return yesterdayClose;

}

int stockType::getnoOfShares(){

     return noOfShares;

}

//Overload the relational operators.

bool stockType::operator==(stockType other)

{

     return (stockSymbol.compare(other.stockSymbol)== 0);

}

bool stockType::operator<(stockType other){

     return (stockSymbol.compare(other.stockSymbol) < 0);

}

bool stockType::operator<=(stockType other) {

     return (stockSymbol.compare(other.stockSymbol) <= 0);

}

bool stockType::operator>(stockType other){

     return (stockSymbol.compare(other.stockSymbol) > 0);

}

bool stockType::operator>=(stockType other){

     return (stockSymbol.compare(other.stockSymbol) >= 0);

}

bool stockType::operator!=(stockType other){

     return (stockSymbol.compare(other.stockSymbol) != 0);

}

//Overload the stream insertion operator <<

ostream& operator<< (ostream& osObject, stockType &stock)

{

    

     osObject << stock.getSymbol()<<setw(10)<<stock.getOpenPrice()

          <<setw(10)<<stock.getClosePrice()<<setw(10)<<stock.getHighPrice()

          <<setw(10)<<stock.getLowPrice()<<setw(10)<<stock.getPrevPrice<<setw(10)

          <<stock.getPercentChange()<<setw(10)<<stock.getnoOfShares()<<endl;

     return osObject;

}

//Overload the stream extraction operator >>

ifstream& operator>> (ifstream& isObject, stockType& stock){

     isObject >> stock.stockSymbol;

     isObject>>stock.todayOpenPrice;

     isObject>>stock.todayClosePrice;

     isObject>>stock.todayHigh;

     isObject>>stock.todayLow;

     isObject>>stock.yesterdayClose;

     isObject>>stock.noOfShares;

    

     return isObject;

}

#endif

#ifndef StockListType

#define StockListType

#include "listType.h"

#include "StockType.h"

class stockListType: public listType<stockType>

{

public:

     void printBySymbol();

     void printByGain();

     void printReports();

     void sort();

     void sortByGain();

     stockListType();

     stockListType(int size);

private:

     int *sortIndicesGainLoss;

};

#endif

#ifndef listType

#define listType

#include <iostream>

#include <cassert>

using namespace std;

template <class elemType>

class listType

{

public:

     bool isEmpty() const;

    

     bool isFull() const;

    

          int getLength() const;

    

     int getMaxSize() const;

    

     void sort();

    

     void print() const;

          void insertAt(const elemType& item, int position);

    

     listType(int listSize=100);

    

     ~listType() ;

protected:

     int maxSize;

     int length;

     elemType *list;

};

template <class elemType>

bool listType<elemType>::isEmpty() const

{

     return (length == 0);

}

template <class elemType>

bool listType<elemType>::isFull() const

{

     return (length == maxSize);

}

template <class elemType>

int listType<elemType>::getLength() const

{

     return length;

}

template <class elemType>

int listType<elemType>::getMaxSize() const

{

     return maxSize;

}

//Constructor; the default array size is 50

template <class elemType>

listType<elemType>::listType(string, double, double, double, double, double, int)

{

     maxSize = listSize;

     length = 0;

     list = new elemType[maxSize];

}

template <class elemType>

listType<elemType>::~listType() //destructor

{

     delete [] list;

}

template <class elemType>

void listType<elemType>::sort() //selection sort

{

     int i, j;

     int min;

     elemType temp;

     for (i = 0; i < length; i++)

     {

          min = i;

          for (j = i + 1; j < length; ++j)

              if (list[j] < list[min])

                   min = j;

          temp = list[i];

          list[i] = list[min];

          list[min] = temp;

     }//end for

}//end sort

template <class elemType>

void listType<elemType>::print() const

{

     int i;

     for (i = 0; i < length; ++i)

          cout << list[i] << " ";

     cout << endl;

}//end print

template <class elemType>

void listType<elemType>::insertAt(const elemType& item,

     int position)

{

     assert(position >= 0 && position < maxSize);

     list[position] = item;

     length++;

}

#endif

#include <iostream>

#include <cstring>

#include "listType.h"

#include "StockType.h"

#include "StockListType.h"

using namespace std;

int main() {

    

     stockListType stockList;

     stockType stockTemp;

     stockTemp.setStockInfo("IBD", 68.00, 71.00, 72.00, 67.00, 75.00, 15000);

     stockList.insertAt(stockTemp, 0);

     stockTemp.setStockInfo("MSET", 120.00, 140.00, 145.00, 140.00, 115.00, 30920);

     stockList.insertAt(stockTemp, 1);

     stockTemp.setStockInfo("AOLK", 80.00, 75.00, 82.00, 74.00, 83.00, 5000);

     stockList.insertAt(stockTemp, 2);

     stockTemp.setStockInfo("CSCO", 100.00, 102.00, 105.00, 98.00, 101.00, 25000);

     stockList.insertAt(stockTemp, 3);

     stockTemp.setStockInfo("ABC", 123.45, 130.95, 132.00, 125.00, 120.50, 10000);

     stockList.insertAt(stockTemp, 4);

    

     //print intList

        stockList.print();

       

     cout << "***********    First Investor's Heaven   ***********" << endl;

     cout << "***********   Financial Report   ***********" << endl;

     cout << "Stock    Today                                    Previous      Percent" << endl;

     cout << "Symbol     Open     Close      High        Low          Close          Gain          Volume" << endl;

     cout << "------     ----     -----      ----       ----- --------          -------      --------" << endl;

     stockList.print();

    

     //cin.get();

     return 0;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote