Question: in c++ please can you change the code to run as the following sequence in the picture with in put and output adding and subtracting.

in c++ please can you change the code to run as the following sequence in the picture with in put and output adding and subtracting.

#include

#include

using namespace std;

// Base Currency class

class Currency {

private:

// Attributes

int wholePart;

int fractionalPart;

public:

// Default Constructor

Currency() : wholePart(0), fractionalPart(0) {}

// Constructor based on one single input of type double

Currency(double input) {

if (input

throw string("Cannot create a negative value currency object");

}

wholePart = (int)input;

fractionalPart = (int)((input - wholePart) * 100);

}

// Copy Constructor

Currency(const Currency& other) : wholePart(other.wholePart), fractionalPart(other.fractionalPart) {}

// Assignment

Currency& operator=(const Currency& other) {

wholePart = other.wholePart;

fractionalPart = other.fractionalPart;

return *this;

}

// Destructor

~Currency() {}

// Setters

void setWholePart(int whole) {

wholePart = whole;

}

void setFractionalPart(int fractional) {

fractionalPart = fractional;

}

// Getters

int getWholePart() {

return wholePart;

}

int getFractionalPart() {

return fractionalPart;

}

// Add method

void add(Currency& other) {

wholePart += other.wholePart;

fractionalPart += other.fractionalPart;

if (fractionalPart >= 100) {

wholePart += 1;

fractionalPart -= 100;

}

}

// Subtract method

void subtract(Currency& other) {

if (wholePart

throw string("Cannot have negative currency value");

}

wholePart -= other.wholePart;

fractionalPart -= other.fractionalPart;

if (fractionalPart

wholePart -= 1;

fractionalPart += 100;

}

}

// Is Equal method

bool isEqual(Currency& other) {

return (wholePart == other.wholePart && fractionalPart == other.fractionalPart);

}

// Is Greater method

bool isGreater(Currency& other) {

return (wholePart > other.wholePart || (wholePart == other.wholePart && fractionalPart > other.fractionalPart));

}

// Print method

void print() {

cout

if (fractionalPart

cout

}

cout

}

};

// Derived Krone class

class Krone : public Currency {

private:

string name;

public:

Krone() : Currency(), name("Krone") {}

Krone(double input) : Currency(input), name("Krone") {}

Krone(const Krone& other) : Currency(other), name(other.name) {}

Krone& operator=(const Krone& other) {

Currency::operator=(other);

name = other.name;

return *this;

}

~Krone() {}

string getName() {

return name;

}

// Override print method

void print() {

Currency::print();

cout

}

};

// Derived Soum class

class Soum : public Currency {

private:

string name;

public:

Soum() : Currency(), name("Soum") {}

Soum(double input) : Currency(input), name("Soum") {}

Soum(const Soum& other) : Currency(other), name(other.name) {}

Soum& operator=(const Soum& other) {

Currency::operator=(other);

name = other.name;

return *this;

}

~Soum() {}

string getName() {

return name;

}

// Override print method

void print() {

Currency::print();

cout

}

};

int main() {

try {

// Declare array of 2 Currency references

Currency* currencies[2];

// Set first reference to Soum object and second reference to Krone object, both of zero value

currencies[0] = new Soum(0);

currencies[1] = new Krone(0);

// Perform sequence of operations

double input;

cout

cin >> input;

currencies[0]->add(*new Soum(input));

cout

cin >> input;

currencies[1]->add(*new Krone(input));

cout

currencies[0]->print();

cout

currencies[1]->print();

cout

cin >> input;

currencies[0]->subtract(*new Soum(input));

cout

currencies[0]->print();

cout

currencies[1]->print();

cout

if (currencies[0]->isEqual(*currencies[1])) {

cout

} else {

cout

}

cout

if (currencies[0]->isGreater(*currencies[1])) {

cout

} else {

cout

}

// Delete the objects

delete currencies[0];

delete currencies[1];

} catch (string& e) {

cout

}

return 0;

}

in c++ please can you change the code to run as the

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!