Question: A Node ADT which will have two attributes - a data attribute and a pointer attribute. Remember the Node has to be an ADT, so

A Node ADT which will have two attributes - a data attribute and a pointer attribute. Remember the Node has to be an ADT, so that it can hold any kind of data.

You can choose to use this node as both a data and a head-pointing node or as a simple data node in which case you will need a new head pointing node.

A Singly Linked List ADT which will be composed of one or more of your nodes. Implement the most common linked-list behaviors as explained in class - new list, add anywhere, delete anywhere, find anywhere, count of items in the list, empty the list, etc.

Finally, implement a Stack ADT derived from your singly linked list which will implement the most common Stack operations like push, pop, isempty etc. and only expose them, i.e. a Stack object should not allow LinkedList behaviors to be executed on it.

Ensure that your Node, List and Stack ADTs are mimimal and cohesive with adequate walls around them. Define interfaces as needed, so you can reuse them in all your subsequent assignments.

Then write a main that will demonstrate the capabilities of you Stack ADT with different types of data - numbers, strings and your "USD" currency objects from Lab 1. Make sure that your currency files are not edited to fit the needs of this lab - I have the previous ones to compare.

Remember the template class code cannot be split into .h and .cpp files - you need to define them in one file and you can give it the .h extension. Create separate code files for Node, List and Stack ADTs.

This is my currency class:

Currency.cpp:

#include "Currency.h"

using namespace std;

//Constructors

Currency::Currency()

{

iWV = 0;

iFV = 0;

}

Currency::Currency(const int& iLocalWV, const int& iLocalFV)

{

iWV = iLocalWV;

iFV = iLocalFV;

}

void Currency::setiWV(const int& iLocalWV)

{

iWV = iLocalWV;

}

void Currency::setiFV(const int& iLocalFV)

{

iFV = iLocalFV;

}

const int& Currency::getiWV()

{

return iWV;

}

const int& Currency::getiFV()

{

return iFV;

}

const string& Currency::getsCName()

{

return sCName;

}

const string& Currency::getsFName()

{

return sFName;

}

//Miscellanous Functions

void Currency::simplify()

{

if (iFV < 0)

{

iWV -= ((abs(iFV) / 100) + 1);

iFV = 100 - (abs(iFV) % 100);

}

if (iFV>= 100)

{

iWV += (iFV / 100);

iFV = iFV % 100;

}

}

Currency.h

#ifndef CURRENCY_H

#define CURRENCY_H

#include //required for abs() function

#include

using namespace std;

class Currency

{

protected:

int iWV, iFV;

string sCName, sFName;

public:

//Constructors

Currency();

Currency(const int&, const int&);

//Mutators

void setiWV(const int&);

void setiFV(const int&);

//Accessors

virtual const int& getiWV();

virtual const int& getiFV();

virtual const string& getsCName();

virtual const string& getsFName();

// simplify function

void simplify();

};

#endif

CurrencyType.cpp

#include "CurrencyType.h"

//Constructors

USD::USD()

{

sCName = "USD";

sFName = "Cent(s)";

}

USD::USD(const string& sLocalCName, const string& sLocalFName)

{

sCName = sLocalCName;

sFName = sLocalFrName;

}

USD::USD(const int& iLocalWV, const int& iLocalFV)

{

sCName = "USD";

sFrlName = "Cent(s)";

iWV = iLocalWV;

iFV = iLocalFV;

}

USD::USD(const string& sLocalCName, const string& sLocalFName, const int& iLocalWV, const int& iLocalFV)

{

sCName = sLocalCName;

sFName = sLocalFName;

iWV = iLocalWV;

iFV = iLocalFV;

}

//Mutators

void USDr::setiWV(const int& iLocalWV)

{

iWV = iLocalWV;

}

void USDr::setiFV(const int& iLocalFV)

{

iFV = iLocalFV;

}

const string& USD::getsCName()

{

return sCName;

}

const string& USD::getsFName()

{

return sFName;

}

//Overloaded Operators

ostream &operator << (ostream& strm, const USD &obj)

{

if (obj.iFV < 10)

{

strm << obj.iWV << " " << obj.sCName << " " << "0" << obj.iFV << " " << obj.sFName;

}

else

strm << obj.iWV << " " << obj.sCName << " " << obj.iFrV << " " << obj.sFName;

return strm;

}

USD USD::operator + (const USD& right)

{

USD temp = right;

temp.iWV = iWV + right.iWV;

temp.iFV = iFV+ right.iFV;

temp.simplify();

return temp;

}

USD USD::operator - (const USD &right)

{

USD temp = right;

temp.iWV = iWV- right.iWV;

temp.iFV = iFV - right.iFV;

temp.simplify();

if (temp.iWV < 0)

{

temp.setiWV(0);

temp.setiFV(0);

string s_SubtractionError = " Error: Subtraction results in negative value. Operation cancelled. ";

throw (s_SubtractionError);

return temp;

}

else

return temp;

}

CurrencyType.h

#ifndef CURRENCY_TYPE_H

#define CURRENCY_TYPE_H

#include

#include

#include "Currency.h"

using namespace std;

class USD: public Currency

{

protected:

string sCName, sFlName;

public:

//Constructors

USD();

USD(const string&, const string&);

USD(const int&, const int&);

USD(const string&, const string&, const int&, const int&);

//Mutators

void setiWV(const int&);

void setiFV(const int&);

//Accessors

const string& getsCName();

const string& getsFName();

//Overloaded Operators

friend istream &operator >> (istream& strm, USD& obj)

{

cout << obj.sCName << ": ";

strm >> obj.iWV;

cout << obj.sFName << ": ";

strm >> obj.iFValue;

obj.simplify();

return strm;

}

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

USD USD::operator + (const USD& right);

USD USD::operator - (const USD&);

};

#endif

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!