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

I posed this question earlier and got the following code, which didn\'t compile.

ID: 3628522 • Letter: I

Question

I posed this question earlier and got the following code, which didn't compile. First, would like to know which part of this is step c? If it could be isolated and corrected, I'd really appreciate it - need it tomorrow (yikes!) I can be more specific about the question if you send a private message if you don't have the book. (Group project - don't want to sink the other students!) Thank you.

#ifndef H_myString
#define H_myString
#include

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 arry that holds the string
int strLength;
//data member to store the length of the string

};
#include #include
#include
#include
#include "myString.h"
using namespace std;

//overload the assignment operator
const newString& newString::operator=(const newString &rightStr)
{ if(this != &rightStr) //avoid self-copy
{ delete [] strPtr;
strLength = rightStr.strLength;
strPtr = new char[strLength + 1];
assert(strPtr != NULL);
strcpy(strPtr, rightStr.strPtr);
}
return *this;
}

//constructor; conversion from the char string
newString::newString(const char *str)
{
strLength = strlen(str);
strPtr = new char[strLength + 1]; //allocate memory to store char string
assert(strPtr != NULL);
strcpy(strPtr, str); //copy string into strPtr
}
//default constructor to initialize the string to null
newString::newString()
{
strLength = 0;
strPtr = new char[1];
assert(strPtr != NULL);
strcpy(strPtr, "");
}

//copy constructor
newString::newString(const newString& rightStr)
{
strLength = rightStr.strLength;
strPtr = new char[strLength + 1];
assert(strPtr != NULL);
strcpy(strPtr, rightStr.strPtr);
}
//destructor
newString::~newString()
{ delete [] strPtr;
}

char& newString::operator[] (int index)
{
assert(0 <= index && index < strLength);
return strPtr[index];
}
const char& newString::operator[](int index) const
{
assert(0 <- index && index < strLength);
return strPtr[index];
}
bool newString::operator==(const newString& rightStr) const
{
return (strcmp(strPtr, rightStr.strPtr) == 0);
}

bool newString::operator!=(const newString& rightStr) const
{
return (strcmp(strPtr, rightStr.strPtr) != 0);
}

bool newString::operator<=(const newString& rightStr) const
{
return (strcmp(strPtr, rightStr.strPtr) <= 0);
}

bool newString::operator<(const newString& rightStr) const
{ return (strcmp(strPtr, rightStr.strPtr) < 0);
}

bool newString::operator>=(const newString& rightStr) const
{ return (strcmp(strPtr, rightStr.strPtr) >= 0);
}
bool newString::operator>(const newString& rightStr) const
{
return (strcmp(strPtr, rightStr.strPtr) > 0);
}

//Friend functions
ostream& operator<< (ostream &out, const newString &rightStr)
{ out << rightStr.strPtr;
return out;
}
istream& operator>> (istream &in, newString &rightStr)
{
char temp[81]; in >> setw(81) >> temp;
rightStr = temp;
return in;
}

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);
int operator ==(stockType &other);
int operator !=(stockType &other);
int operator <=(stockType &other);
int operator >=(stockType &other);
int operator >(stockType &other);
int operator <(stockType &other);
private:
newString stockSymbol;
double todayOpenPrice;
double todayClosePrice,todayHigh,todayLow;
double yesterdayClose;
double percentChange;
int noOfShares;

};

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

{
out << setprecision(2) << fixed << right;
out << setw(6) << obj.stockSymbol;
out << setw(8) << obj.todayOpenPrice;
out << setw(8) << obj.todayClosePrice;
out << setw(8) << obj.todayHigh;
out << setw(8) << obj.todayLow;
out << setw(10) << obj.yesterdayClose;
out << setw(8) << obj.getPercentChange() << "%";
out << setw(8) << obj.noOfShares;
out << endl;
return out;
}
ifstream& operator>> (ifstream &in, stockType &obj)
{
in >> obj.stockSymbol;
in >> obj.todayOpenPrice;
in >> obj.todayClosePrice;
in >> obj.todayHigh;
in >> obj.todayLow;
in >> obj.yesterdayClose;
in >> obj.noOfShares;
return in;
}
void stockType::setStockInfo(newString symbol, double openPrice, double closePrice, double high, double low, double prevClose,int shares)
{
stockSymbol = symbol;
todayOpenPrice = openPrice;
todayClosePrice = closePrice;
todayHigh = high;
todayLow = low;
yesterdayClose = prevClose;
noOfShares = shares;
}
newString stockType::getSymbol()
{
return stockSymbol;
}
double stockType::getPercentChange()
{
double rslt = 0.0;
rslt = (todayClosePrice - yesterdayClose) / yesterdayClose * 100;
return rslt;
}

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.0;
todayClosePrice = 0.0;
todayHigh = 0.0;
todayLow = 0.0;
yesterdayClose = 0.0;
noOfShares = 0;
}
stockType::stockType(newString symbol, double openPrice, double closePrice, double high,double low, double prevClose, int shares)
{
stockSymbol = symbol;
todayOpenPrice = openPrice; todayClosePrice = closePrice;
todayHigh = high;
todayLow = low;
yesterdayClose = prevClose;
noOfShares = shares;}
int stockType::operator ==(stockType &other)
{ return (stockSymbol == other.stockSymbol);
}
int stockType::operator !=(stockType &other){
return (stockSymbol != other.stockSymbol);}
int stockType::operator <=(stockType &other)
{ return (stockSymbol <= other.stockSymbol);}
int stockType::operator >=(stockType &other){
return (stockSymbol >= other.stockSymbol);}
int stockType::operator >(stockType &other){
return (stockSymbol > other.stockSymbol);}
int stockType::operator <(stockType &other){
return (stockSymbol < other.stockSymbol);}
class stockListType: public listType

{

public:

void printBySymbol();
void printByGain();
void printReports();
void sort();
void sortByGain();

stockListType();
stockListType(int size);

private:

int *indexByGain;

};

void stockListType::printBySymbol()

{
sort();
printReports();
}

void stockListType::printByGain()

{

sortByGain();

//Output file contents to screen

cout << "********* First Investor's Heaven *********" << endl;
cout << "********* Financial Report *********" << endl;
cout << "Stock" << " Today" << " Previous Percent" << endl;

cout << left << setw(6) << "Symbol" << setw(8) << " Open" << setw(8) << " Close" << setw(8) << " High";
cout << setw(8) << " Low" << setw(10) << " Close" << setw(8) << " Gain" << setw(8) << " Volume" << endl;
cout << setw(6) << "------" << setw(8) << " ------" << setw(8) << " ------" << setw(8) << " ------";
cout << setw(8) << " ------" << setw(10) << " --------" << setw(8) << " ------" << setw(8) << " ------" << endl;

//Iterate through list and print contents
int i;
for(i = 0; i < length; ++i)
cout << elements[indexByGain[i]] << endl;


//cout << "Closing Assets: $??????.??" << endl;

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

cout << endl;

}

void stockListType::printReports()

{

//Output file contents to screen

cout << "********* First Investor's Heaven *********" << endl;
cout << "********* Financial Report *********" << endl;
cout << "Stock" << " Today" << " Previous Percent" << endl;

cout << left << setw(6) << "Symbol" << setw(8) << " Open" << setw(8) << " Close" << setw(8) << " High";
cout << setw(8) << " Low" << setw(10) << " Close" << setw(8) << " Gain" << setw(8) << " Volume" << endl;
cout << setw(6) << "------" << setw(8) << " ------" << setw(8) << " ------" << setw(8) << " ------";
cout << setw(8) << " ------" << setw(10) << " --------" << setw(8) << " ------" << setw(8) << " ------" << endl;

//Iterate through list and print contents

int i;
for(i = 0; i < length; ++i)
cout << elements[i] << endl;

//cout << "Closing Assets: $??????.??" << endl;
cout << "-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*" << endl;
cout << endl;

}

void stockListType::sort()

{
listType::sort();
}

void stockListType::sortByGain()

{
int i, j;
int temp;
indexByGain = new int[length];

//Pre-populate the index array

for(int cntr = 0; cntr < length; cntr++)
{

indexByGain[cntr] = cntr;
}

//Sort by the percentage change
for (i = 0; i

{
for (j = i + 1; j < length; j++)
{
if (elements[indexByGain[j]].getPercentChange() > elements[indexByGain[i]].getPercentChange())
{
temp = indexByGain[i];
indexByGain[i] = indexByGain[j];
indexByGain[j] = temp;
}
}
}//end for
}


stockListType::stockListType()

{
indexByGain = new int[50];
}

stockListType::stockListType(int size)

{
indexByGain = new int[size];
}

Main Program:

//Program to test the class listType

#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(100);
cout << fixed << showpoint;
cout << setprecision(2);

getData(stockList);

stockList.sort();

stockList.printBySymbol();

cout << endl;

stockList.printByGain();

cout << " Press any key to end...";

getch();

return 0;
}

void getData(stockListType& list)

{
ifstream infile;

char fileName[50];

cout << "Enter input file name: ";
cin >> fileName;
cout << endl;

infile.open(fileName);

if (!infile)

{
cout << "Input file does not exist. Program terminates." << endl;
return;
}

list.setLength(noOfStocks);

list.getList(infile);

}

Explanation / Answer

Dear, The c option is Driver program main method which i gave yu already . If facing any Debugging problem make sure that all the files myString.h,myString.cpp,ListType.h , ListType.cpp,stockType.h,StockType.cpp,stockListType.h,stockListType.cpp anf Main program in same directory. Place a text file with following data ABC 123.45 130.95 132.00 125.00 120.50 10000
MSET 120.00 140.00 145.00 140.00 115.00 30920
AOLK 80 75 82 74 83 5000
CSCO 100 102 105 98 101 25000
IBD 68 71 72 67 75 15000
Still any clarification come back Hope this will help you Still any clarification come back Hope this will help you