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

Following a suggestion to be more specific - (hope it fits) Here is the exercise

ID: 3628277 • Letter: F

Question

Following a suggestion to be more specific - (hope it fits) Here is the exercise:

 

 

 

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     67283

 

 

 

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 was 112.50, the closing price was 115.75, today's high price was 116.50, today's low price was 111.75, yesterday's closing price was 113.50 and the number of shares currently being held is 6723823.

 

 

 

 The listing sorted by stock symbols must be of the following form:

 

 

 

(It shows an 8-column form with the overall heading of First Investor's Heaven, and beneath that, Financial Report with column headings of Stock Symbol; Open; Close; High; (Today is centered over Close and High);  Low; Previous Close; Percent Gain and Volume.  It then has rows with the name of the stock symbol and figures in each column.  The bottom row is Closing Assets with a figure)

 

 

 

Develop this programming exercise in two steps.  In the first step (part a), design and implement a stock object.  (That part is already done and working fine).  In the second step (part b) design and implement an object to maintain a list of stocks.  (Just about done - but there's some problems.  The code is:

#ifndef H_listType
#define H_listType

#include <cstdlib>
#include <iostream>
#include <cassert>

using namespace std;

template <class elemType>
class listType
{  //class template to create an array and perform various functions
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 = 50);
    ~listType();

protected:
    int maxSize;
    int length;
    elemType *list;
};

template <class elemType>
bool listType<elemType>::isEmpty() const
{  //function to check if array is empty
     return (length == 0);
}
          
template <class elemType>
bool listType<elemType>::isFull() const
{  //function to check if array is full
     return (length == maxSize);
}

template <class elemType>
int listType<elemType>::getLength() const
{  //function to get length
    return length;
}

template <class elemType>
int listType<elemType>::getMaxSize() const
{  //function to get maxSize
    return maxSize;
}

template <class elemType>
listType<elemType>::listType(int listSize)
{  //default constructor
    maxSize = listSize;
    length = 0;
    list = new elemType[maxSize];
}

template <class elemType>
listType<elemType>::~listType()
{  //destructor
    delete [] list;
}

template <class elemType>
void listType<elemType>::sort()
{  //sort function
     int i, j;
     int min;
     elemType temp;
    
     for(i = 0; i < length; i++)
     {
         min = i;
         for(j = i; j < length; ++j)
            if (list[j] < list[min])
               min = j;
         temp = list[i];
         list[i] = list[min];
         list[min] = temp;
     }
}

template <class elemType>
void listType<elemType>::print() const
{  //print function
     int i;
     for(i = 0; i < length; ++i)
        cout << list[i] << " ";
     cout << endl;
}

template <class elemType>
void listType<elemType>::insertAt(const elemType& item, int position)
{  //insert function
     assert(position >= 0 && position < maxSize);
     list[position] = item;
     length++;
}

#endif

//Some problems from here on

#include <ostream>
#include <string>

using namespace std;

int main ()

{
   
    class stockListType: public listType<stockType>
    {
    public:
            struct stockType
        {
            string stockSymbol;
            double open;
            double close;
            double high;
            double low;
            double previousClose;
            double percentGain;
            double volume;
        };
       


        void arrayInput (int myArray)
        {
            int counter = 0;
            int arrayOfStruct = myArray;
           
            for(counter = 0; counter < 50; counter++)
                infile >> arrayOfStruct[counter].stockSymbol
                infile >> arrayOfStruct[counter].open
                infile >> arrayOfStruct[counter].close
                infile >> arrayOfStruct[counter].high
                infile >> arrayOfStruct[counter].low
                infile >> arrayOfStruct[counter].previousClose
                infile >> arrayOfStruct[counter].percentGain
                infile >> arrayOfStruct[counter].volume;
        }

        void sortTndices ()
        {
            int i = 0;

            for (i = 0; i < 50; i++)
                if (myArray[i] < myArray[i++])

        }

        void printIndices (mystruct)
        {
            int i = 0;
            for(i = 0; i < 50; i++)
                cout << mystruct.stocksymbol << mystruct.open;
                cout << mystruct.close << mystruct.high;
                cout << mystruct.low << mystruct.previousClose;
                cout << mystruct.percentGain << mystruct.volume << endl;
        }

    }
    system ("pause");
        return 0;
}

 

 

 

Step c:  Write a program that uses these two classes to automate the company's analysis of stock data.  This is what I need most.

 

 

 

Thank you.

Explanation / Answer

#ifndef H_myString

#define H_myString

#include <iostream>

using namespace std;

class newString

{

         //overload the stream insertion and extraction operators

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

    friend istream& operator>> (istream&, newString&);

public:

    const newString& operator=(const newString& rightStr);

            //overload the assignment operator

    newString(const char *);

            //constructor; conversion from the char string

    newString();

            //default constructor to initialize the string to null

    newString(const newString& rightStr);

            //copy constructor

    ~newString();

            //destructor

    char &operator[] (int);

    const char &operator[](int) const;

          //overload the relational operators

    bool operator==(const newString& rightStr) const;

    bool operator!=(const newString& rightStr) const;

    bool operator<=(const newString& rightStr) const;

    bool operator<(const newString& rightStr) const;

    bool operator>=(const newString& rightStr) const;

    bool operator>(const newString& rightStr) const;

private:

    char *strPtr; //pointer to the char array

                   //that holds the string

    int strLength;   //data member to store the length

                             //of the string

};

//overload the assignment operator

StockType class            

class stockType

{

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

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

public:

      void setStockInfo(newString symbol, double openPrice,

                              double closeProce, double high,

                              double Low, double prevClose,

                              int shares);

      newString getSymbol();

      double getPercentChange();

      double getOpenPrice();

      double getClosePrice();

      double getHighPrice();

      double getLowPrice();

      double getPrevPrice();

      int getNoOfShares();

      stockType();

      stockType(newString symbol, double openPrice,

                  double closeProce, double high,

                  double Low, double prevClose,

                  int shares);

};

ostream& operator<< (ostream &out, stockType &obj)

{

double stockType::getHighPrice()

{

      return todayHigh;

}

double stockType::getLowPrice()

{      return todayLow;}