Assignment Help| The Portfolio class Already implemented parts:Constructors
The Portfolio classAlready implemented parts:Constructors
(implemented)
display function.
(implemented)
Operator and conversion overloads
Portfolio can be casted to a double (double type). The result would be the value of the Portfolio m_value. This operator can not modify the Portfolio object.
Portfolio can be casted to C-string (const char* type). The result would be the name of the stock m_stock. This operator can not modify the Portfolio object.
Portfolio can be casted to a char (char type). The result would be the type of investment m_type. This operator can not modify the Portfolio object.
Portfolio can be casted to a bool (boolean type). This will return TRUE if the type of the investment m_type is Growth ‘G’ or Value ‘V or Investment ‘I’. For any other types, it will return FALSE.
A double can be added to the value of the Portfolio m_value using += operator; if the Portfolio does not evaluate TRUE or the double value is negative, the action is omitted. Reference of the Portfolio is returned after the operation.
A double can be subtracted from the value of the Portfolio m_value using -= operator; if the Portfolio does not evaluate TRUE or the double value is negative, the action is omitted. Reference of the Portfolio is returned after the operation.
The bool operator ~() will return true if m_value is negative. This operator can not modify the Portfolio object.
overload the << operator* (left shift operator) to move $dollar investment value m_value from Portfolio in the right to the left. After this operation, the total investment value of the Portfolio on the left will be the sum of both Portfolios. The Portfolio on the right is set to empty.
It is not allowed to invest values from a Portfolio back to itself. If any of the two portfolios don’t evaluate to TRUE, no action should be taken.
- overload the >> operator* (right shift operator) to move $dollar investment value m_value from Portfolio in the left to the right. After this operation, the total investment value of the Portfolio in the right will be the sum of both Portfolios. The Portfolio on the left is set to empty.
It is not allowed to invest values from a Portfolio back to itself. If any of the two portfolios don’t evaluate to TRUE, no action should be taken.
Binary helper operators
create a binary stand alone helper + operator that accepts a constant Portfolio reference at left and another constant Portfolio reference at right and returns a double value.
The double value should be the sum of the m_values of the two Flights.
If any of the two Portfolios don’t evaluate to TRUE, then zero is returned.
create a binary stand alone helper += operator that accepts a double reference at left and a constant Portfolio reference at right and returns a double value.
The $dollar investment value of the right operand (Portfolio reference) should be added to the left operand (double reference)
Then the value of the double reference is returned.
The tester program.
The tester program tests all the operator overloads and the output should be as follows:
+----------------------------------------------------------------+
Portfolio | EMPTY | | Value: 0 | Type: E
Portfolio | Active | Fitzer | Value: 400000 | Type: G
Portfolio | Active | Honda | Value: 500000 | Type: I
Portfolio | Active | RIM | Value: 140000 | Type: V
Portfolio | EMPTY | | Value: 0 | Type: E
Portfolio | Active | Nvdia | Value: 95000 | Type: G
+----------------------------------------------------------------+
Total Investment in Honda and Nvdia is: 595000
Total Investment in Fitzer and RIM is: 540000
+----------------------------------------------------------------+
Total Investment in Fitzer and Nvdia is: 495000
+----------------------------------------------------------------+
Portfolio | EMPTY | | Value: 0 | Type: E
Portfolio | Active | Fitzer | Value: 495000 | Type: G
Portfolio | EMPTY | | Value: 0 | Type: E
Portfolio | Active | RIM | Value: 640000 | Type: V
Portfolio | EMPTY | | Value: 0 | Type: E
Portfolio | EMPTY | | Value: 0 | Type: E
+----------------------------------------------------------------+
+----------------------------------------------------------------+
Portfolio | EMPTY | | Value: 0 | Type: E
Portfolio | Active | Fitzer | Value: 495000 | Type: G
Portfolio | EMPTY | | Value: 0 | Type: E
Portfolio | Active | RIM | Value: 640000 | Type: V
Portfolio | EMPTY | | Value: 0 | Type: E
Portfolio | EMPTY | | Value: 0 | Type: E
+----------------------------------------------------------------+
+----------------------------------------------------------------+
Portfolio | EMPTY | | Value: 0 | Type: E
Portfolio | Active | Fitzer | Value: 400000 | Type: G
Portfolio | EMPTY | | Value: 0 | Type: E
Portfolio | Active | RIM | Value: 700000 | Type: V
Portfolio | EMPTY | | Value: 0 | Type: E
Portfolio | EMPTY | | Value: 0 | Type: E
+----------------------------------------------------------------+
Modify the tester program to test all the different circumstances/cases of the application if desired and note that the professor’s tester may have many more samples than the tester program here.
main.cpp
/* ------------------------------------------------------
Workshop 5 part 2
Module: N/A
Filename: main.cpp
Version 1.0
Date: 24/11/2021
Author: Asam Gulaid
Revised by: Fardad Soleimanloo
Revision History
-----------------------------------------------------------
Initials Date Reason
F.S. 07/02/2022 Peer Review
-----------------------------------------------------------*/
#include <iostream>
#include "Portfolio.h"
using namespace std;
using namespace sdds;
void displayPortfolios(const Portfolio* Portfolios, int num) {
cout << "+----------------------------------------------------------------+" << endl;
for (int i = 0; i < num; i++) {
Portfolios[i].display() << endl;
}
cout << "+----------------------------------------------------------------+" << endl;
}
int main() {
double total;
Portfolio Portfolios[] = {
{300000, "Fitzer", 'F'}, // invalid
{400000, "Fitzer", 'G'},
{500000, "Honda", 'I'},
{140000, "RIM", 'V'},
{-500000, "Nortel", 'V'}, // invalid
{95000, "Nvdia", 'G'},
};
displayPortfolios(Portfolios, 6);
cout << " Total Investment in " << (const char*)(Portfolios[2]) << " and " << (const char*)(Portfolios[5]) << " is: " << (total = Portfolios[2] + Portfolios[5]) << endl;
cout << " Total Investment in " << (const char*)(Portfolios[1]) << " and " << (const char*)(Portfolios[3]) << " is: " << double(Portfolios[1]) + double( Portfolios[3]) << endl;
cout << "+----------------------------------------------------------------+" << endl;
total = 0;
total += Portfolios[1];
total += Portfolios[5];
cout << " Total Investment in " << (const char*)(Portfolios[1]) << " and " << (const char*)(Portfolios[5]) << " is: " << total << endl;
Portfolios[2] >> Portfolios[3];
Portfolios[1] << Portfolios[5];
displayPortfolios(Portfolios, 6);
Portfolios[5] += 250005.50;
Portfolios[4] -= 150000.50;
displayPortfolios(Portfolios, 6);
Portfolios[3] += 60000.50;
Portfolios[1] -= 95000.00;
displayPortfolios(Portfolios, 6);
return 0;
}
Portfolio.cpp
/* ------------------------------------------------------
Workshop 5 part 2
Module: Portfolio
Filename: Portfolio.cpp
Version 1.0
Date: 24/11/2021
Author: Asam Gulaid
Revised by: Fardad Soleimanloo
Revision History
-----------------------------------------------------------
Initials Date Reason
F.S. 07/02/2022 Peer Review
-----------------------------------------------------------*/
#define _CRT_SECURE_NO_WARNINGS
#include "Portfolio.h"
using namespace std;
namespace sdds {
Portfolio::Portfolio() {
emptyPortfolio();
}
void Portfolio::emptyPortfolio()
{
m_value = 0;
m_stock[0] = 0;
m_type = 'E';
}
Portfolio::Portfolio(double value, const char* stock, char type) {
emptyPortfolio();
if (value >= 0 && ( type == 'V' || type == 'G' || type == 'I') ) {
m_value = value;
m_type = type;
strcpy(m_stock, stock);
}
}
void Portfolio::dispPortfolio() const{
cout << " ";
cout.width(10);
cout << (const char*)(*this);
cout << " | ";
cout << "Value: ";
cout.width(10);
cout << double(*this);
cout << " | ";
cout << " Type: ";
cout << char(*this);
}
std::ostream& Portfolio::display() const {
if (~*this) {
cout << " Portfolio | Bad-NG |";
dispPortfolio();
}
else if (*this) {
cout << " Portfolio | Active |";
dispPortfolio();
}
else {
cout << " Portfolio | EMPTY |";
dispPortfolio();
}
return cout;
}
}
Portfolio.h
/* ------------------------------------------------------
Workshop 5 part 2
Module: Portfolio
Filename: Portfolio.h
Version 1.0
Date: 24/11/2021
Author: Asam Gulaid
Revised by: Fardad Soleimanloo
Revision History
-----------------------------------------------------------
Initials Date Reason
F.S. 07/02/2022 Peer Review
-----------------------------------------------------------*/
#ifndef SDDS_Portfolio_H_
#define SDDS_Portfolio_H_
#include <iostream>
#include <string>
namespace sdds {
class Portfolio {
double m_value = 0;
char m_stock[16];
char m_type;
public:
};
}
#endif // SDDS_Portfolio_H_