Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hello, please help me implement the steps into my code in C++. See if the code I provided has the following steps implemented, and test

Hello, please help me implement the steps into my code in C++. See if the code I provided has the following steps implemented, and test the code to see if it works.

Steps:

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

-----------------------------------------------------

My code:

image text in transcribed

----------------------------------------------------

image text in transcribed

image text in transcribed

main.cpp ------------------------------------------------------------------ #include #include #include #include

#include "stockType.h" #include "stockListType.h"

using namespace std;

const int noOfStocks = 5;

void getData(stockListType& list);

int main() { stockListType stockList; cout

getData(stockList);

stockList.sortStockList(); stockList.printBySymbol(); cout

return 0; }

void getData(stockListType& list) { ifstream infile; string symbol; double OpenPrice; double ClosePrice; double tHigh; double tLow; double yClose; int shares; stockType temp;

infile.open("stockdat.txt");

if (!infile) { cerr

infile >> symbol; while (infile) { infile >> OpenPrice >> ClosePrice >> tHigh >> tLow >> yClose >> shares; temp.setStockInfo(symbol,OpenPrice,ClosePrice,tHigh,tLow,yClose,shares); list.insert(temp); infile >> symbol; } } --------------------------------------------------------------------------------------------- stockListImp.cpp -------------------------------------- #include #include #include #include #include "stockType.h" #include "stockListType.h"

using namespace std;

void stockListType::insert(const stockType& item) { list.push_back(item); }

void stockListType::printBySymbol() { // unsigned int i; double closingBalance = 0; cout

for (unsigned int i = 0; i

cout

void stockListType::printByGain() { // unsigned int i; cout

for (unsigned int i = 0; i

void stockListType::printReports() { printBySymbol(); cout

void stockListType::sortStockList() { sort(list.begin(), list.end());

sortByGain(); }

void stockListType::sortByGain() { bool *temp;

temp = new bool[list.size()];

// unsigned int i, j; int maxIndex;

for (unsigned int i = 0; i

for (unsigned int i = 0; i

for (unsigned int j = maxIndex + 1; j

indexByGain.push_back(maxIndex); temp[maxIndex] = true; } delete [] temp; }

----------------------------------------------------------------------------------------------------------------- stockListType.h ---------------------------------------------- #ifndef H_StockListType #define H_StockListType

#include #include

#include "stockType.h"

using namespace std;

class stockListType { public: void printBySymbol(); void printByGain(); void printReports(); void sortStockList(); void sortByGain(); void insert(const stockType& item); private: vector indexByGain; vector list; };

#endif ------------------------------------------------------------------------------------------------------------ stockType.h -------------------------------------------------- #ifndef H_stockType #define H_stockType

#include #include #include

using namespace std;

class stockType { friend ostream& 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 ==(const stockType& other) const; bool operator !=(const stockType& other) const; bool operator =(const stockType& other) const; bool operator >(const stockType& other) const; bool operator

private: string stockSymbol; double todayOpenPrice; double todayClosePrice; double todayHigh; double todayLow; double yesterdayClose; double percentChange; int noOfShares; };

#endif ------------------------------------------------------------------------------------------------------------- stockTypeImp.cpp ------------------------------------------------------- #include #include #include #include "stockType.h"

using namespace std;

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; percentChange = (todayClosePrice - yesterdayClose) / yesterdayClose; noOfShares = shares; }

string stockType::getSymbol() { return stockSymbol; }

double stockType::getPercentChange() { 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; }

stockType::stockType() { stockSymbol = ""; todayOpenPrice = 0; todayClosePrice = 0; todayHigh = 0; todayLow = 0; yesterdayClose = 0; percentChange = 0; noOfShares = 0; } stockType::stockType(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; percentChange = (todayClosePrice - yesterdayClose) / yesterdayClose; noOfShares = shares; }

bool stockType::operator ==(const stockType& other) const { return (stockSymbol == other.stockSymbol); }

bool stockType::operator !=(const stockType& other) const { return (stockSymbol != other.stockSymbol); }

bool stockType::operator

bool stockType::operator >=(const stockType& other) const { return (stockSymbol >= other.stockSymbol); }

bool stockType::operator >(const stockType& other) const { return (stockSymbol > other.stockSymbol); }

bool stockType::operator

ostream& operator

ifstream& operator>>(ifstream& inf, stockType& stock) { inf >> stock.stockSymbol>>stock.todayOpenPrice >> stock.todayClosePrice>>stock.todayHigh >> stock.todayLow>>stock.yesterdayClose >> stock.noOfShares; stock.percentChange = (stock.todayClosePrice - stock.yesterdayClose) / stock.yesterdayClose;

return inf; }

3. A list of stock objects will be implemented in a class called stockListType However, stockListType will be derived from the class listType, which should be implemented as a class template. The declaration of the listType class is provided by the following: template class listType public: bool isEmptyList() const; / Function returns a nonzero value (TRUE) if list // is empty. Otherwise it returns the value 0 (FALSE) bool isFullList() const; / Function returns a nonzero value (TRUE) if list /is full. Otherwise it returns the value0 (FALSE) void setLength (int len) / Function that sets the length of a list. // Postcondition: length 1en int showLength) const; / Function that returns the length of a list // Postcondition: returns length void search (Type searchItem) const; // Search the list for searchItem // Postcondition: Internal variable found is set // to a nonzero value (TRUE) if searchItem is found // in the list, otherwise found is set to 0 (FALSE). If the searchItem is found, the value // and location within the list is // printed to the screen, otherwise, a message // indicating that the item cannot // be found should be printed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Refactoring Databases Evolutionary Database Design

Authors: Scott Ambler, Pramod Sadalage

1st Edition

0321774515, 978-0321774514

More Books

Students also viewed these Databases questions