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

Please help me on this data abstraction c++ program: Create a currency class (an

ID: 3687207 • Letter: P

Question

Please help me on this data abstraction c++ program:

Create a currency class (and any derived classes you may need for up to 5 individual currencies) with four attributes - currency name, whole parts and fractional parts and fractional's name such that 100 fractional parts equals 1 whole part, e.g. Pound, 1, 55, pence or Euro, 3, 33, cent.

Define overloaded operators to add or subtract different currency objects - care should be taken that you can only perform these operation on objects of the same currency. Also, take care that fractional parts roll into whole parts.

Define an overloaded input stream operator to accept values of any currency as well as an overloaded output stream operator to write out the value of the currency..

Initialize your currency objects demonstrating polymorphic construction. Your constructors should also use initialization lists.

Define a Wallet class that will contain the 5 individual currency types you define and will implement the following - number of individual currency types, check if a currency type exists in the wallet, add money by currency, remove money by currency, remove all currencies, check if wallet is empty.

To add or remove money into/from wallet, check if currency exists in the wallet. If so, add or remove the amount specified.

Your main should allow the user to add a maximum of 5 different currency types to the wallet in the form of the base currency array - some examples are Dollar and cent, Euro and cent, Pound and pence, Ruble and kopeck. Then use a random number generator to add and remove currency values between 0 and 99 for both the whole and fractional values. You can think about using ENUMs for the currency types to be generated. Finally, output the total value and name of the currencies in your wallet. Finally empty the wallet and print relevant information about the operation.

Explanation / Answer

main.cpp
// Names: Randy Manzanarez, Willis Wang
// Lab 1
// Assume when people pass in enum and money they pass in the right money type for the enum so no pass in (DOLLAR, Pounds object) will return false
// Assume all money object gets memory from the heap
// if sub more than have will become 0 w 0 p but have to remove that with option 3 since like to show it has been handled

#include <iostream>
#include <cstdlib>
#include <ctime>
#include "Wallet.h"

using namespace std;

//function to get a new money object
Currency* getMoney(int c2){
   unsigned seed = time(0);
   srand(seed);
   int whole = rand()%100;
   int part = rand()%100;
   if(c2 == 1){
       return new Dollar(whole, part);
   }else if(c2 == 2){
       return new Pounds(whole, part);
   }else if(c2 == 3){
       return new Euros(whole, part);
   }else if(c2 == 4){
       return new Pesos(whole, part);
   }else if(c2 == 5){
       return new Rubles(whole, part);
   }else if(c2 == 6){
       return new Yen(whole, part);
   }else if(c2 == 7){
       return new Franc(whole, part);
   }else if(c2 == 8){
       return new Colon(whole, part);
   }else if(c2 == 9){
       return new Rupee(whole, part);
   }else if(c2 == 10){
       return new Shekel(whole, part);
   }
}
//get the Enum for money
MonType getType(int c2){
   if(c2 == 1){
       return DOLLAR;
   }else if(c2 == 2){
       return POUNDS;
   }else if(c2 == 3){
       return EUROS;
   }else if(c2 == 4){
       return PESOS;
   }else if(c2 == 5){
       return RUBLES;
   }else if(c2 == 6){
       return YEN;
   }else if(c2 == 7){
       return FRANC;
   }else if(c2 == 8){
       return COLON;
   }else if(c2 == 9){
       return RUPEE;
   }else if(c2 == 10){
       return SHEKEL;
   }
}

int main(){
   int c1 = 0, c2 = 0;
   Wallet wallie;
   do{
       cout << endl;
       cout << "Welcome to your Wallet! (Wallie)" << endl;
       cout << "1. Add Random Ammounts of Money" << endl;
       cout << "2. Sub Random Ammounts of Money" << endl;
       cout << "3. Fully Remove One Type of Money" << endl;
       cout << "4. Display Contents of Wallet" << endl;
       cout << "5. Empty Wallet" << endl;
       cout << "6. Quit" << endl;
       cin >> c1;
       cout << endl;
       if(c1 >= 1 && c1 <= 3){
           cout << "Select Currency Type" << endl;
           cout << "1. Dollar" << endl;
           cout << "2. Pounds" << endl;
           cout << "3. Euros" << endl;
           cout << "4. Pesos" << endl;
           cout << "5. Rubles" << endl;
           cout << "6. Yen" << endl;
           cout << "7. Franc" << endl;
           cout << "8. Colon" << endl;
           cout << "9. Rupee" << endl;
           cout << "10. Shekel" << endl;
           cin >> c2;
           cout << endl;
       }
       if(c1 == 1 && c2 >= 1 && c2 <= 10){
           Currency* temp = getMoney(c2);
           //display how much is being added
           cout << "Adding ";
           temp->toString();
           cout << " to Wallie" << endl;
           //will always add so dont need to check
           wallie.addCurrency(getType(c2), temp);
       }else if(c1 == 2 && c2 >= 1 && c2 <= 10){
           Currency* temp = getMoney(c2);
           cout << "Attempting to remove ";
           temp->toString();
           cout << "from Wallie" << endl;
           if(!wallie.subCurrency(getType(c2), temp)){
               cout << "There is no money of type that type cannot subtract!" << endl;
           } else {
               cout << "Succesfully Removed" << endl;
           }
       }
       else if(c1 == 3 && c2 >= 1 && c2 <= 10){
           //if the object being removed exists
           if(wallie.exists(getType(c2))){
               Currency* temp = wallie.getCurrency(getType(c2));
               cout << "Removing ";
               temp->toString();
               cout << endl;
               wallie.removeCurrency(getType(c2));
           }else{
               cout << "Currency of that Type does not Exist!" << endl;
           }
       }
       else if(c1 == 4){
           //can only display if wallet is not empty
           if(!wallie.isEmpty()){
               wallie.displayAll();
           }else{
               cout << "Wallie is Empty!!!" << endl;
           }
       }
       else if(c1 == 5){
           wallie.removeAll();
           cout << "All Types of Currency Removed" << endl;
       }else if(c1 == 6){
           //destructor handles the mem
           cout << "Bye Bye Wallie" << endl;
       }else{
           //if user selects an invalid option
           cin.clear();
           cin.ignore();
           cout << "Not a Valid Input" << endl;
       }
   }while(c1 != 6);
   return 0;
}

Money.cpp
#include <iostream>
#include "Money.h"

Dollar::Dollar(int whol, int par){
   //setting the values right
   whole = whol;
   parts = par;
   wholeName = "Dollar";
   partsName = "Cent";
   makeGood();
}
void Dollar::makeGood(){
   //if parts is negative
   if(parts < 0){
       //int div and the -1 to account for negative
       whole += (parts/100 - 1);
       //gives parts a value between 0 and 100
       parts = 100 + (parts%100);
   }else{
       //int div
       whole += (parts/100);
       //gives parts its value between 0 and 100
       parts = parts%100;
   }
   //if whole goes negative means no more of type of money
   if(whole < 0){
       whole = 0;
       parts = 0;
   }
}
bool Dollar::add(Currency* mon){
   if(mon->getWholeName() == wholeName){
       //add each part to eachother
       whole += mon->getWhole();
       parts += mon->getParts();
       //this is why can add like above
       makeGood();
       return true;
   }
   return false;
}
bool Dollar::sub(Currency* mon){
   //if the currrencies are the same
   if(mon->getWholeName() == wholeName){
       //normal subtraction
       whole -= mon->getWhole();
       parts -= mon->getParts();
       //this is why can subtract like above to
       makeGood();
       return true;
   }
   return false;
}
int Dollar::getWhole(){
   return this->whole;
}
int Dollar::getParts(){
   return this->parts;
}
string Dollar::getWholeName(){
   return this->wholeName;
}
void Dollar::toString(){
   cout << whole << " " << wholeName << " and " << parts << " " << partsName << endl;
}
//all other code is the same a Dollar just different object name
Pounds::Pounds(int whol, int par){
   whole = whol;
   parts = par;
   wholeName = "Pound";
   partsName = "Pence";
   makeGood();
}
void Pounds::makeGood(){
   //if parts is negative
   if(parts < 0){
       //int div and the -1 to account for negative
       whole += (parts/100 - 1);
       //gives parts a value between 0 and 100
       parts = 100 + (parts%100);
   }else{
       //int div
       whole += (parts/100);
       //gives parts its value between 0 and 100
       parts = parts%100;
   }
   if(whole < 0){
       whole = 0;
       parts = 0;
   }
}
bool Pounds::add(Currency* mon){
   if(mon->getWholeName() == wholeName){
       whole += mon->getWhole();
       parts += mon->getParts();
       makeGood();
       return true;
   }
   return false;
}
bool Pounds::sub(Currency* mon){
   if(mon->getWholeName() == wholeName){
       whole -= mon->getWhole();
       parts -= mon->getParts();
       makeGood();
       return true;
   }
   return false;
}
int Pounds::getWhole(){
   return this->whole;
}
int Pounds::getParts(){
   return this->parts;
}
string Pounds::getWholeName(){
   return this->wholeName;
}
void Pounds::toString(){
   cout << whole << " " << wholeName << " and " << parts << " " << partsName << endl;
}

Euros::Euros(int whol, int par){
   whole = whol;
   parts = par;
   wholeName = "Euro";
   partsName = "Cent";
   makeGood();
}
void Euros::makeGood(){
   //if parts is negative
   if(parts < 0){
       //int div and the -1 to account for negative
       whole += (parts/100 - 1);
       //gives parts a value between 0 and 100
       parts = 100 + (parts%100);
   }else{
       //int div
       whole += (parts/100);
       //gives parts its value between 0 and 100
       parts = parts%100;
   }
   if(whole < 0){
       whole = 0;
       parts = 0;
   }
}
bool Euros::add(Currency* mon){
   if(mon->getWholeName() == wholeName){
       whole += mon->getWhole();
       parts += mon->getParts();
       makeGood();
       return true;
   }
   return false;
}
bool Euros::sub(Currency* mon){
   if(mon->getWholeName() == wholeName){
       whole -= mon->getWhole();
       parts -= mon->getParts();
       makeGood();
       return true;
   }
   return false;
}
int Euros::getWhole(){
   return this->whole;
}
int Euros::getParts(){
   return this->parts;
}
string Euros::getWholeName(){
   return this->wholeName;
}
void Euros::toString(){
   cout << whole << " " << wholeName << " and " << parts << " " << partsName << endl;
}

Pesos::Pesos(int whol, int par){
   whole = whol;
   parts = par;
   wholeName = "Peso";
   partsName = "Centavo";
   makeGood();
}
void Pesos::makeGood(){
   //if parts is negative
   if(parts < 0){
       //int div and the -1 to account for negative
       whole += (parts/100 - 1);
       //gives parts a value between 0 and 100
       parts = 100 + (parts%100);
   }else{
       //int div
       whole += (parts/100);
       //gives parts its value between 0 and 100
       parts = parts%100;
   }
   if(whole < 0){
       whole = 0;
       parts = 0;
   }
}
bool Pesos::add(Currency* mon){
   if(mon->getWholeName() == wholeName){
       whole += mon->getWhole();
       parts += mon->getParts();
       makeGood();
       return true;
   }
   return false;
}
bool Pesos::sub(Currency* mon){
   if(mon->getWholeName() == wholeName){
       whole -= mon->getWhole();
       parts -= mon->getParts();
       makeGood();
       return true;
   }
   return false;
}
int Pesos::getWhole(){
   return this->whole;
}
int Pesos::getParts(){
   return this->parts;
}
string Pesos::getWholeName(){
   return this->wholeName;
}
void Pesos::toString(){
   cout << whole << " " << wholeName << " and " << parts << " " << partsName << endl;
}

Rubles::Rubles(int whol, int par){
   whole = whol;
   parts = par;
   wholeName = "Ruble";
   partsName = "Kopek";
   makeGood();
}
void Rubles::makeGood(){
   //if parts is negative
   if(parts < 0){
       //int div and the -1 to account for negative
       whole += (parts/100 - 1);
       //gives parts a value between 0 and 100
       parts = 100 + (parts%100);
   }else{
       //int div
       whole += (parts/100);
       //gives parts its value between 0 and 100
       parts = parts%100;
   }
   if(whole < 0){
       whole = 0;
       parts = 0;
   }
}
bool Rubles::add(Currency* mon){
   if(mon->getWholeName() == wholeName){
       whole += mon->getWhole();
       parts += mon->getParts();
       makeGood();
       return true;
   }
   return false;
}
bool Rubles::sub(Currency* mon){
   if(mon->getWholeName() == wholeName){
       whole -= mon->getWhole();
       parts -= mon->getParts();
       makeGood();
       return true;
   }
   return false;
}
int Rubles::getWhole(){
   return this->whole;
}
int Rubles::getParts(){
   return this->parts;
}
string Rubles::getWholeName(){
   return this->wholeName;
}
void Rubles::toString(){
   cout << whole << " " << wholeName << " and " << parts << " " << partsName << endl;
}

Yen::Yen(int whol, int par){
   whole = whol;
   parts = par;
   wholeName = "Yen";
   partsName = "Cen";
   makeGood();
}
void Yen::makeGood(){
   //if parts is negative
   if(parts < 0){
       //int div and the -1 to account for negative
       whole += (parts/100 - 1);
       //gives parts a value between 0 and 100
       parts = 100 + (parts%100);
   }else{
       //int div
       whole += (parts/100);
       //gives parts its value between 0 and 100
       parts = parts%100;
   }
   if(whole < 0){
       whole = 0;
       parts = 0;
   }
}
bool Yen::add(Currency* mon){
   if(mon->getWholeName() == wholeName){
       whole += mon->getWhole();
       parts += mon->getParts();
       makeGood();
       return true;
   }
   return false;
}
bool Yen::sub(Currency* mon){
   if(mon->getWholeName() == wholeName){
       whole -= mon->getWhole();
       parts -= mon->getParts();
       makeGood();
       return true;
   }
   return false;
}
int Yen::getWhole(){
   return this->whole;
}
int Yen::getParts(){
   return this->parts;
}
string Yen::getWholeName(){
   return this->wholeName;
}
void Yen::toString(){
   cout << whole << " " << wholeName << " and " << parts << " " << partsName << endl;
}

Franc::Franc(int whol, int par){
   whole = whol;
   parts = par;
   wholeName = "Franc";
   partsName = "Centime";
   makeGood();
}
void Franc::makeGood(){
   //if parts is negative
   if(parts < 0){
       //int div and the -1 to account for negative
       whole += (parts/100 - 1);
       //gives parts a value between 0 and 100
       parts = 100 + (parts%100);
   }else{
       //int div
       whole += (parts/100);
       //gives parts its value between 0 and 100
       parts = parts%100;
   }
   if(whole < 0){
       whole = 0;
       parts = 0;
   }
}
bool Franc::add(Currency* mon){
   if(mon->getWholeName() == wholeName){
       whole += mon->getWhole();
       parts += mon->getParts();
       makeGood();
       return true;
   }
   return false;
}
bool Franc::sub(Currency* mon){
   if(mon->getWholeName() == wholeName){
       whole -= mon->getWhole();
       parts -= mon->getParts();
       makeGood();       return true;
   }
   return false;
}
int Franc::getWhole(){
   return this->whole;
}
int Franc::getParts(){
   return this->parts;
}
string Franc::getWholeName(){
   return this->wholeName;
}
void Franc::toString(){
   cout << whole << " " << wholeName << " and " << parts << " " << partsName << endl;
}

Colon::Colon(int whol, int par){
   whole = whol;
   parts = par;
   wholeName = "Colon";
   partsName = "Centmo";
   makeGood();
}
void Colon::makeGood(){
   //if parts is negative
   if(parts < 0){
       //int div and the -1 to account for negative
       whole += (parts/100 - 1);
       //gives parts a value between 0 and 100
       parts = 100 + (parts%100);
   }else{
       //int div
       whole += (parts/100);
       //gives parts its value between 0 and 100
       parts = parts%100;
   }
   if(whole < 0){
       whole = 0;
       parts = 0;
   }
}
bool Colon::add(Currency* mon){
   if(mon->getWholeName() == wholeName){
       whole += mon->getWhole();
       parts += mon->getParts();
       makeGood();
       return true;
   }
   return false;
}
bool Colon::sub(Currency* mon){
   if(mon->getWholeName() == wholeName){
       whole -= mon->getWhole();
       parts -= mon->getParts();
       makeGood();
       return true;
   }
   return false;
}
int Colon::getWhole(){
   return this->whole;
}
int Colon::getParts(){
   return this->parts;
}
string Colon::getWholeName(){
   return this->wholeName;
}
void Colon::toString(){
   cout << whole << " " << wholeName << " and " << parts << " " << partsName << endl;
}

Rupee::Rupee(int whol, int par){
   whole = whol;
   parts = par;
   wholeName = "Rupee";
   partsName = "Paise";
   makeGood();
}
void Rupee::makeGood(){
   //if parts is negative
   if(parts < 0){
       //int div and the -1 to account for negative
       whole += (parts/100 - 1);
       //gives parts a value between 0 and 100
       parts = 100 + (parts%100);
   }else{
       //int div
       whole += (parts/100);
       //gives parts its value between 0 and 100
       parts = parts%100;
   }
   if(whole < 0){
       whole = 0;
       parts = 0;
   }
}
bool Rupee::add(Currency* mon){
   if(mon->getWholeName() == wholeName){
       whole += mon->getWhole();
       parts += mon->getParts();
       makeGood();
       return true;
   }
   return false;
}
bool Rupee::sub(Currency* mon){
   if(mon->getWholeName() == wholeName){
       whole -= mon->getWhole();
       parts -= mon->getParts();
       makeGood();
       return true;
   }
   return false;
}
int Rupee::getWhole(){
   return this->whole;
}
int Rupee::getParts(){
   return this->parts;
}
string Rupee::getWholeName(){
   return this->wholeName;
}
void Rupee::toString(){
   cout << whole << " " << wholeName << " and " << parts << " " << partsName << endl;
}

Shekel::Shekel(int whol, int par){
   whole = whol;
   parts = par;
   wholeName = "Shekel";
   partsName = "Agorot";
   makeGood();
}
void Shekel::makeGood(){
   //if parts is negative
   if(parts < 0){
       //int div and the -1 to account for negative
       whole += (parts/100 - 1);
       //gives parts a value between 0 and 100
       parts = 100 + (parts%100);
   }else{
       //int div
       whole += (parts/100);
       //gives parts its value between 0 and 100
       parts = parts%100;
   }
   if(whole < 0){
       whole = 0;
       parts = 0;
   }
}
bool Shekel::add(Currency* mon){
   if(mon->getWholeName() == wholeName){
       whole += mon->getWhole();
       parts += mon->getParts();
       makeGood();
       return true;
   }
   return false;
}
bool Shekel::sub(Currency* mon){
   if(mon->getWholeName() == wholeName){
       whole -= mon->getWhole();
       parts -= mon->getParts();
       makeGood();
       return true;
   }
   return false;
}
int Shekel::getWhole(){
   return this->whole;
}
int Shekel::getParts(){
   return this->parts;
}
string Shekel::getWholeName(){
   return this->wholeName;
}
void Shekel::toString(){
   cout << whole << " " << wholeName << " and " << parts << " " << partsName << endl;
}

Money.h
#ifndef MONEY_H
#define MONEY_H

#include "Currency.h"

class Dollar;
class Pounds;
class Euros;
class Pesos;
class Rubles;
class Yen;
class Franc;
class Colon;
class Rupee;
class Shekel;

class Dollar : public Currency{
   private:
       //dont want a default constructor to be used
       Dollar();
       //dont want default constructor used
       string wholeName, partsName;
       int whole, parts;
       //if parts is not a good number
       void makeGood();
   public:
       Dollar(int, int);
       int getWhole();
       int getParts();
       //to check in add and sub functions if right type
       string getWholeName();
       void toString();
       bool add(Currency*);
       bool sub(Currency*);
};
class Pounds : public Currency{
   private:
       //dont want a default constructor to be used
       Pounds();
       //dont want default constructor used
       string wholeName, partsName;
       int whole, parts;
       //if parts is not a good number
       void makeGood();
   public:
       Pounds(int, int);
       int getWhole();
       int getParts();
       //to check in add and sub functions if right type
       string getWholeName();
       void toString();
       bool add(Currency*);
       bool sub(Currency*);
};
class Euros : public Currency{
   private:
       //dont want a default constructor to be used
       Euros();
       string wholeName, partsName;
       int whole, parts;
       //if parts is not a good number
       void makeGood();
   public:
       Euros(int, int);
       int getWhole();
       int getParts();
       //to check in add and sub functions if right type
       string getWholeName();
       void toString();
       bool add(Currency*);
       bool sub(Currency*);
};
class Pesos : public Currency{
   private:
       //dont want a default constructor to be used
       Pesos();
       string wholeName, partsName;
       int whole, parts;
       //if parts is not a good number
       void makeGood();
   public:
       Pesos(int, int);
       int getWhole();
       int getParts();
       //to check in add and sub functions if right type
       string getWholeName();
       void toString();
       bool add(Currency*);
       bool sub(Currency*);
};
class Rubles : public Currency{
   private:
       //dont want a default constructor to be used
       Rubles();
       string wholeName, partsName;
       int whole, parts;
       //if parts is not a good number
       void makeGood();
   public:
       Rubles(int, int);
       int getWhole();
       int getParts();
       //to check in add and sub functions if right type
       string getWholeName();
       void toString();
       bool add(Currency*);
       bool sub(Currency*);
};
class Yen : public Currency{
   private:
       //dont want a default constructor to be used
       Yen();
       string wholeName, partsName;
       int whole, parts;
       //if parts is not a good number
       void makeGood();
   public:
       Yen(int, int);
       int getWhole();
       int getParts();
       //to check in add and sub functions if right type
       string getWholeName();
       void toString();
       bool add(Currency*);
       bool sub(Currency*);
};
class Franc : public Currency{
   private:
       //dont want a default constructor to be used
       Franc();
       string wholeName, partsName;
       int whole, parts;
       //if parts is not a good number
       void makeGood();
   public:
       Franc(int, int);
       int getWhole();
       int getParts();
       //to check in add and sub functions if right type
       string getWholeName();
       void toString();
       bool add(Currency*);
       bool sub(Currency*);
};
class Colon : public Currency{
   private:
       //dont want a default constructor to be used
       Colon();
       string wholeName, partsName;
       int whole, parts;
       //if parts is not a good number
       void makeGood();
   public:
       Colon(int, int);
       int getWhole();
       int getParts();
       //to check in add and sub functions if right type
       string getWholeName();
       void toString();
       bool add(Currency*);
       bool sub(Currency*);
};
class Rupee : public Currency{
   private:
       //dont want a default constructor to be used
       Rupee();
       string wholeName, partsName;
       int whole, parts;
       //if parts is not a good number
       void makeGood();
   public:
       Rupee(int, int);
       int getWhole();
       int getParts();
       //to check in add and sub functions if right type
       string getWholeName();
       void toString();
       bool add(Currency*);
       bool sub(Currency*);
};
class Shekel : public Currency{
   private:
       //dont want a default constructor to be used
       Shekel();
       string wholeName, partsName;
       int whole, parts;
       //if parts is not a good number
       void makeGood();
   public:
       Shekel(int, int);
       int getWhole();
       int getParts();
       //to check in add and sub functions if right type
       string getWholeName();
       void toString();
       bool add(Currency*);
       bool sub(Currency*);

}
#endif

Welcome to your Wallet! (Wallie)                                                                                                                            
1. Add Random Ammounts of Money                                                                                                                             
2. Sub Random Ammounts of Money                                                                                                                             
3. Fully Remove One Type of Money                                                                                                                           
4. Display Contents of Wallet                                                                                                                               
5. Empty Wallet                                                                                                                                             
6. Quit                                                                                                                                                     
1

Wallet.cpp, Wallet.h, Currency.h

i cant able to upload these three files due to limit character