Question

In: Computer Science

C++ PROGRAM 1) Create a "CashOut" currency class with two integer attributes and one string attribute,...

C++ PROGRAM


1) Create a "CashOut" currency class with two integer attributes and one string attribute, all of which are non-public. The int attributes will represent the whole part (or currency note value) and fractional part (or currency coin value) such that 100 fractional parts equal 1 whole part. The string attribute will represent the currency name.
2) Create a "MoreCash" derived/inherited class with one additional non-public double attribute to represent the conversion factor from/to US Dollar.
The value of the conversion factor can be defaulted in the class definition based on 1 CO = 1.36 MC or 1 MC = 0.74 CO.
Also, 1000 of MC fractional parts equals 1 MC whole part.
3) In your two currency classes, add public methods for the following:
Default Construction (i.e. no parameters passed)
Construction based on parameters for all attributes
Copy Constructor and/or Assignment, as applicable to your programming language of choice
Destructor, as applicable to your programming language of choice
Setters and Getters for all attributes
Adding two objects of the same currency
Subtracting one object from another object of the same currency
Comparing two objects of the same currency for equality/inequality
Comparing two objects of the same currency to identify which object is larger or smaller
Print method to print details of a currency object
In your derived class only, methods to convert CO objects to MC and vice versa
4) Create a "Bag" class with one attribute - an array of two "CashOut" references/pointers and the following methods to demonstrate polymorphism of the currencies:
A default constructor which sets
the first element of the array to a zero value CashOut object
the second element of the array to a zero value MoreCash Dollar object
A destructor, as applicable to your programming language of choice
methods to add or subtract
CO objects to/from the first element only and
MC objects to/from the second element only
methods to compare if the value of either element is greater or smaller than an input value
A method to print the values of the two elements in the Bag class
5) In your main:
Create a Bag object
Provide the user a “main menu” to add and subtract as well as compare the CashOut and MoreCash values in the Bag as well as print the contents of the Bag
You can use a second level menu choice to allow the user to select currency type
Based on user choice, create either CashOut or MoreCash objects as needed to perform the desired operations.
The main menu should be run in a loop until the user selects the Exit option

Solutions

Expert Solution

//.h file code:

#include <string>

namespace com::currencyConversion
{

  
   class CashOut
   {

   private:
       int currency_note_value = 0;
       int currency_frac_value = 0;
       std::wstring Currency_name = L"";

   public:
      


       CashOut(); //super();


       CashOut(int currency_note_value, int currency_fracaVal, const std::wstring &currency_name); //super();

       virtual int getcurrency_note_value();

       virtual void setcurrency_note_value(int currency_note_value);

       virtual int getcurrency_fracaVal();

       virtual void setcurrency_fracaVal(int currency_fracaVal);

       virtual std::wstring getCurrency_name();

       virtual void setCurrency_name(const std::wstring &currency_name);

       CashOut(const CashOut &d); //super();

   };

}

//.cpp file code:

#include "snippet.h"

namespace com::currencyConversion
{


   CashOut::CashOut()
   {
       // TODO Auto-generated constructor stub
   }


   CashOut::CashOut(int currency_note_value, int currency_fracaVal, const std::wstring &currency_name)
   {
       this->currency_note_value = currency_note_value;
       this->currency_frac_value= currency_fracaVal;
       this->Currency_name = currency_name;
   }

   int CashOut::getcurrency_note_value()
   {
       return currency_note_value;
   }

   void CashOut::setcurrency_note_value(int currency_note_value)
   {
       this->currency_note_value = currency_note_value;
   }

   int CashOut::getcurrency_fracaVal()
   {
       return currency_fracaVal;
   }

   void CashOut::setcurrency_fracaVal(int currency_fracaVal)
   {
       this->currency_frac_value= currency_fracaVal;
   }

   std::wstring CashOut::getCurrency_name()
   {
       return Currency_name;
   }

   void CashOut::setCurrency_name(const std::wstring &currency_name)
   {
       Currency_name = currency_name;
   }


   CashOut::CashOut(const CashOut &d)
   {
       d.currency_note_value = currency_note_value;
       d.currency_frac_value= currency_fracaVal;
       d.Currency_name = Currency_name;
   }
}


---------------------------------------------------


//.h file code:

#include <string>
#include <iostream>

namespace com::currencyConversion
{

   class MoreCash: public CashOut
   {

   public:
       const double conversionFactor = 1.36;
   private:
       int currency_note_value = 0;
       int currency_frac_value = 0;
       std::wstring Currency_name;

   public:
       CashOut *CashOut1 = new CashOut();
       CashOut *CashOut2 = new CashOut();

       virtual ~MoreCash()
       {
           delete CashOut1;
           delete CashOut2;
       }

       MoreCash(CashOut *d);

       MoreCash(int currency_note_value , int currency_frac_value , const std::wstring &currency_name);

       MoreCash();

       virtual int getcurrency_note_value ();

       virtual void setcurrency_note_value (int currency_note_value );

       virtual int getcurrency_frac_value ();

       virtual void setcurrency_frac_value (int currency_frac_value );

       virtual std::wstring getCurrency_name();

       virtual void setCurrency_name(const std::wstring &currency_name);

       // Methods to Calculate the Total currency amount


       virtual double getConversionFactor();

       virtual void AddCurrency();

       virtual void SubsCurrency();

       virtual void CashOutCurrencyEquality();

       virtual void CheckGreaterAmount();

   };

}

//.cpp file code:

#include "snippet.h"

namespace com::currencyConversion
{

   MoreCash::MoreCash(CashOut *d) : CashOut(d)
   {
       // TODO Auto-generated constructor stub
   }

   MoreCash::MoreCash(int currency_note_value , int currency_frac_value , const std::wstring &currency_name) : CashOut(currency_note_value , currency_frac_value , currency_name)
   {
       // TODO Auto-generated constructor stub
   }

   MoreCash::MoreCash() : CashOut()
   {
       this->currency_note_value = currency_note_value ;
       this->currency_frac_value = currency_frac_value ;
       Currency_name = Currency_name;
   }

   int MoreCash::getcurrency_note_value ()
   {
       return currency_note_value ;
   }

   void MoreCash::setcurrency_note_value (int currency_note_value )
   {
       this->currency_note_value = currency_note_value ;
   }

   int MoreCash::getcurrency_frac_value ()
   {
       return currency_frac_value ;
   }

   void MoreCash::setcurrency_frac_value (int currency_frac_value )
   {
       this->currency_frac_value = currency_frac_value ;
   }

   std::wstring MoreCash::getCurrency_name()
   {
       return Currency_name;
   }

   void MoreCash::setCurrency_name(const std::wstring &currency_name)
   {
       Currency_name = currency_name;
   }

  

   double MoreCash::getConversionFactor()
   {
       return conversionFactor;
   }

   void MoreCash::AddCurrency()
   {
       std::wcout << L"Enter the First ( currency_note_value Amount) of the Currency" << std::endl;
       CashOut1->setcurrency_note_value (sc::nextInt());
       std::wcout << L"Enter the First (currency_frac_value Amount) of the Currency" << std::endl;
       CashOut1->setcurrency_frac_value (sc::nextInt());
       std::wcout << L"Enter the Second (currency_note_value Amount) of the Currency" << std::endl;
       CashOut2->setcurrency_note_value (sc::nextInt());
       std::wcout << L"Enter the Second (currency_frac_value Amount) of the Currency" << std::endl;
       CashOut2->setcurrency_frac_value (sc::nextInt());

       double usdCurrency1;
       usdCurrency1 = CashOut1->getcurrency_note_value () + CashOut1->getcurrency_frac_value () / 100;

       double usdCurrrency2;
       usdCurrrency2 = CashOut2->getcurrency_note_value () + CashOut2->getcurrency_frac_value () / 100;

       double totalUsd = usdCurrency1 + usdCurrrency2;
       std::wcout << totalUsd << std::endl;

   }

   void MoreCash::SubsCurrency()
   {
       std::wcout << L"Enter the First ( currency_note_value Amount) of the Currency" << std::endl;
cin>>
       CashOut1->setcurrency_note_value (put);
       std::wcout << L"Enter the First (currency_frac_value Amount) of the Currency" << std::endl;
       CashOut1->setcurrency_frac_value (sc::nextInt());
       std::wcout << L"Enter the Second (currency_note_value Amount) of the Currency" << std::endl;
       CashOut2->setcurrency_note_value (sc::nextInt());
       std::wcout << L"Enter the Second (currency_frac_value Amount) of the Currency" << std::endl;
       CashOut2->setcurrency_frac_value (sc::nextInt());

       double usdCurrency1;
       usdCurrency1 = CashOut1->getcurrency_note_value () + CashOut1->getcurrency_frac_value () / 100;

       double usdCurrrency2;
       usdCurrrency2 = CashOut2->getcurrency_note_value () + CashOut2->getcurrency_frac_value () / 100;
       double totalUsd = usdCurrency1 - usdCurrrency2;

       if (totalUsd > 0)
       {
           std::wcout << totalUsd << std::endl;
       }
       else
       {
           std::wcout << -totalUsd << std::endl;
       }
   }

   void MoreCash::CashOutCurrencyEquality()
   {
       std::wcout << L"Enter the First ( currency_note_value Amount) of the Currency" << std::endl;
cin>>currency_note_value ;
       CashOut1->setcurrency_note_value (cin>>currency_note_value));
       std::wcout << L"Enter the First (currency_frac_value Amount) of the Currency" << std::endl;
       CashOut1->setcurrency_frac_value (sc::nextInt());
       std::wcout << L"Enter the Second (currency_note_value Amount) of the Currency" << std::endl;
       CashOut2->setcurrency_note_value (sc::nextInt());
       std::wcout << L"Enter the Second (currency_frac_value Amount) of the Currency" << std::endl;
       CashOut2->setcurrency_frac_value (sc::nextInt());

       std::wstring equal = L" Equal", unequal = L"Unequal";
       double usdCurrency1;
       usdCurrency1 = CashOut1->getcurrency_note_value () + CashOut1->getcurrency_frac_value () / 100;

       double usdCurrrency2;
       usdCurrrency2 = CashOut2->getcurrency_note_value () + CashOut2->getcurrency_frac_value () / 100;
       double totalUsd = usdCurrency1 + usdCurrrency2;

       if (usdCurrency1 == usdCurrrency2)
       {
           std::wcout << equal << std::endl;
       }
       else
       {
           std::wcout << unequal << std::endl;
       }

   }

   void MoreCash::CheckGreaterAmount()
   {
       std::wcout << L"Enter the First ( currency_note_value Amount) of the Currency" << std::endl;
       CashOut1->setcurrency_note_value (sc::nextInt());
       std::wcout << L"Enter the First (currency_frac_value Amount) of the Currency" << std::endl;
       CashOut1->setcurrency_frac_value (sc::nextInt());
       std::wcout << L"Enter the Second (currency_note_value Amount) of the Currency" << std::endl;
       CashOut2->setcurrency_note_value (sc::nextInt());
       std::wcout << L"Enter the Second (currency_frac_value Amount) of the Currency" << std::endl;
       CashOut2->setcurrency_frac_value (sc::nextInt());

       double usdCurrency1;
       usdCurrency1 = CashOut1->getcurrency_note_value () + CashOut1->getcurrency_frac_value () / 100;

       double usdCurrrency2;
       usdCurrrency2 = CashOut2->getcurrency_note_value () + CashOut2->getcurrency_frac_value () / 100;
       double totalUsd = usdCurrency1 + usdCurrrency2;

       if (usdCurrency1 > usdCurrrency2)
       {
           std::wcout << L" Greater Currency1: " << usdCurrency1 << std::endl;
       }
       else
       {
           std::wcout << L" Greater Currency1: " << usdCurrrency2 << std::endl;
       }
   }
}


-----------------------------------------

//.h file code:

#include <iostream>

namespace com::currencyConversion
{

   using namespace com::currencyConversion;


   class Bag : public CIS22C_CashOut1
   {

   public:
       CashOut *d1 = new CashOut(15, 16, L"USD");
       CIS22C_CashOut1 *d2 = new CIS22C_CashOut1(17, 18, L"C2D");

       virtual ~Bag()
       {
           delete d1;
           delete d2;
       }

       virtual double USDCurrency();

       virtual double C2DCurrency();

       double getConversionFactor() override;

       void AddCurrency() override;

       void SubsCurrency() override;

       void CashOutCurrencyEquality() override;

       void CheckGreaterAmount() override;

   };

}

//.cpp file code:

#include "snippet.h"

namespace com::currencyConversion
{
   using namespace com::currencyConversion;

   double Bag::USDCurrency()
   {
       double usdCurrency;
       usdCurrency = d1->getcurrency_note_value () + d1->getcurrency_frac_value () / 100;
       return usdCurrency;
   }

   double Bag::C2DCurrency()
   {
       double c2dCurrency;
       c2dCurrency = d2->getcurrency_note_value () + d2->getcurrency_frac_value () / 1000;
       return c2dCurrency;
   }

   double Bag::getConversionFactor()
   {

       return CIS22C_CashOut1::getConversionFactor();
   }

   void Bag::AddCurrency()
   {
       std::wcout << L"Enter the First currency_note_value Amount of the Currency" << std::endl;
       d1->setcurrency_frac_value (sc::nextInt());
       std::wcout << L"Enter the First currency_frac_value Amount of the Currency" << std::endl;
       d1->setcurrency_frac_value (sc::nextInt());
       std::wcout << L"Enter the Second currency_note_value Amount of the Currency" << std::endl;
       CashOut2::setcurrency_frac_value (sc::nextInt());
       std::wcout << L"Enter the Second currency_frac_value Amount of the Currency" << std::endl;
       CashOut2::setcurrency_frac_value (sc::nextInt());

       double usdCurrency1;
       usdCurrency1 = d1->getcurrency_note_value () + d1->getcurrency_frac_value () / 100;

       double c2dCurrrency2;
       c2dCurrrency2 = d2->getcurrency_note_value () + d2->getcurrency_frac_value () / 1000;

       std::wcout << (usdCurrency1 + c2dCurrrency2 * getConversionFactor()) << std::endl;
   }

   void Bag::SubsCurrency()
   {
       std::wcout << L"Enter the First currency_note_value Amount of the Currency" << std::endl;
       d1->setcurrency_frac_value (sc::nextInt());
       std::wcout << L"Enter the First currency_frac_value Amount of the Currency" << std::endl;
       d1->setcurrency_frac_value (sc::nextInt());
       std::wcout << L"Enter the Second currency_note_value Amount of the Currency" << std::endl;
       d2->setcurrency_frac_value (sc::nextInt());
       std::wcout << L"Enter the Second currency_frac_value Amount of the Currency" << std::endl;
       d2->setcurrency_frac_value (sc::nextInt());

       double usdCurrency1;
       usdCurrency1 = d1->getcurrency_note_value () + d1->getcurrency_frac_value () / 100;

       double c2dCurrrency2;
       c2dCurrrency2 = d2->getcurrency_note_value () + d2->getcurrency_frac_value () / 1000;

       std::wcout << (usdCurrency1 - c2dCurrrency2 * getConversionFactor()) << std::endl;

   }

   void Bag::CashOutCurrencyEquality()
   {
       std::wcout << L"Enter the First currency_note_value Amount of the Currency" << std::endl;
       d1->setcurrency_frac_value (sc::nextInt());
       std::wcout << L"Enter the First currency_frac_value Amount of the Currency" << std::endl;
       d1->setcurrency_frac_value (sc::nextInt());
       std::wcout << L"Enter the Second currency_note_value Amount of the Currency" << std::endl;
       d2->setcurrency_frac_value (sc::nextInt());
       std::wcout << L"Enter the Second currency_frac_value Amount of the Currency" << std::endl;
       d2->setcurrency_frac_value (sc::nextInt());

       double usdCurrency1;
       usdCurrency1 = d1->getcurrency_note_value () + d1->getcurrency_frac_value () / 100;

       double c2dCurrrency2;
       c2dCurrrency2 = d2->getcurrency_note_value () + d2->getcurrency_frac_value () / 1000;

       if ((usdCurrency1) == c2dCurrrency2 * getConversionFactor())
       {
           std::wcout << L"Currency Value Are Equal" << std::endl;
       }
       else
       {
           std::wcout << L"The Currency Value is Unequal" << std::endl;
       }

   }

   void Bag::CheckGreaterAmount()
   {
       std::wcout << L"Enter the First currency_note_value Amount of the Currency" << std::endl;
       d1->setcurrency_frac_value (sc::nextInt());
       std::wcout << L"Enter the First currency_frac_value Amount of the Currency" << std::endl;
       d1->setcurrency_frac_value (sc::nextInt());
       std::wcout << L"Enter the Second currency_note_value Amount of the Currency" << std::endl;
       d2->setcurrency_frac_value (sc::nextInt());
       std::wcout << L"Enter the Second currency_frac_value Amount of the Currency" << std::endl;
       d2->setcurrency_frac_value (sc::nextInt());

       double usdCurrency1;
       usdCurrency1 = d1->getcurrency_note_value () + d1->getcurrency_frac_value () / 100;

       double c2dCurrrency2;
       c2dCurrrency2 = d2->getcurrency_note_value () + d2->getcurrency_frac_value () / 1000;

       if (usdCurrency1 > c2dCurrrency2 * getConversionFactor())
       {
           std::wcout << L"The USD Currency is Greater" << std::endl;
       }
       else
       {
           std::wcout << L"The C2D Currency is Greater" << std::endl;
       }

   }
}


//.h file code:

#include <string>
#include <vector>
#include <iostream>
#include <any>

namespace com::currencyConversion
{


   class Main_Test
   {

   public:
       static void main(std::vector<std::wstring> &args);
   };

}

#include <string>
#include <vector>

int main(int argc, char **argv)
{
std::vector<std::wstring> args(argv + 1, argv + argc);
com::currencyConversion::Main_Test::main(args);
}


//.cpp file code:

#include "snippet.h"

namespace com::currencyConversion
{
  

   void Main_Test::main(std::vector<std::wstring> &args)
   {
       Scanner *scan = new Scanner(System::in);
       Wallet *wal = new Wallet();
       CIS22C_CashOut1 *CashOut = new CIS22C_CashOut1();

      
       std::wcout << L" Choose the Number as perform Operation to Perform " << std::endl;
       std::wcout << L" Press -- 1 -- to Add same Type oF Currency " << std::endl;
       std::wcout << L" Press -- 2 -- to substract same Type oF Currency " << std::endl;
       std::wcout << L" Press -- 3 -- to FindGreater same Type oF Currency " << std::endl;
       std::wcout << L" press -- 4 -- to Compare same Type oF Currency " << std::endl;
       std::wcout << L" Press -- 5 -- to Add Different Type oF Currency " << std::endl;
       std::wcout << L" Press -- 6 -- to substract Different Type oF Currency " << std::endl;
       std::wcout << L" Press -- 7 -- to FindGreater Different Type oF Currency" << std::endl;
       std::wcout << L" press -- 8 -- to Compare Different Type oF Currency " << std::endl;
       std::wcout << L" Press -- 9 -- to exit" << std::endl;

       int num1 = 0;

       while (num1 != 9)
       {
           num1 = scan->nextInt();
           switch (num1)
           {
           case 1:
               CashOut->AddCurrency();
               break;
           case 2:
               CashOut->SubsCurrency();

               break;
           case 3:
               CashOut->CheckGreaterAmount();

               break;
           case 4:
               CashOut->CheckCurrencyEquality();

               break;
           case 5:
               wal->AddCurrency();

               break;
           case 6:
               wal->SubsCurrency();

               break;
           case 7:
               wal->CheckGreaterAmount();
               break;
           case 8:
               wal->CheckCurrencyEquality();
               break;
           case 9:
               break;

           }
       }


       delete CashOut;
       delete wal;
       delete scan;
   }
}

Kindly...Excuse for Some typo errors ( converted from java to c++)


Related Solutions

A. Create a Dollar currency class with two integer attributes and one string attribute, all of...
A. Create a Dollar currency class with two integer attributes and one string attribute, all of which are non-public. The int attributes will represent whole part (or currency note value) and fractional part (or currency coin value) such that 100 fractional parts equals 1 whole part. The string attribute will represent the currency name. B. Create a CIS22C Dollar derived/inherited class with one additional non-public double attribute to represent the conversion factor from/to US Dollar. The value of the conversion...
Needs to be done in PYTHON A. Create a Dollar currency class with two integer attributes...
Needs to be done in PYTHON A. Create a Dollar currency class with two integer attributes and one string attribute, all of which are non-public. The int attributes will represent whole part (or currency note value) and fractional part (or currency coin value) such that 100 fractional parts equals 1 whole part. The string attribute will represent the currency name. B. Create a CIS22C Dollar derived/inherited class with one additional non-public double attribute to represent the conversion factor from/to US...
In C++ Demonstrate inheritance. Create an Airplane class with the following attributes: • manufacturer : string...
In C++ Demonstrate inheritance. Create an Airplane class with the following attributes: • manufacturer : string • speed : float Create a FigherPlane class that inherits from the Airplane class and adds the following attributes: • numberOfMissiles : short
write a C++ program to CREATE A CLASS EMPLOYEE WITH YOUR CHOICE OF ATTRIBUTES AND FUNCTIONS...
write a C++ program to CREATE A CLASS EMPLOYEE WITH YOUR CHOICE OF ATTRIBUTES AND FUNCTIONS COVERING THE FOLLOWING POINTS: 1) COUNTING NUMBER OF OBJECTS CREATED ( NO OBJECT ARRAY TO BE USED) USING ROLE OF STATIC MEMBER 2) SHOWING THE VALID INVALID STATEMENTS IN CASE OF STATIC MEMBER WITH NON STATIC MEMBER FUNCTION, NON STATIC MEMBERS OF CLASS WITH STATIC MEMBER FUNCTION, BOTH STATIC. SHOW THE ERRORS WHERE STATEMENTS ARE INVALID. 3) CALL OF STATIC MEMBER FUNCTION, DECLARATION OF...
Using java, create a class called MyString that has one String called word as its attribute...
Using java, create a class called MyString that has one String called word as its attribute and the following methods: Constructor that accepts a String argument and sets the attribute. Method permute that returns a permuted version of word. For this method, exchange random pairs of letters in the String. To get a good permutation, if the length of the String is n, then perform 2n swaps. Use this in an application called Jumble that prompts the user for a...
In c++ Write a program that reads a string consisting of a positive integer or a...
In c++ Write a program that reads a string consisting of a positive integer or a positive decimal number and converts the number to the numeric format. If the string consists of a decimal number, the program must use a stack to convert the decimal number to the numeric format. Use the STL stack
In c++, write a program that reads a string consisting of a positive integer or a...
In c++, write a program that reads a string consisting of a positive integer or a positive decimal number and converts the number to the numeric format. If the string consists of a decimal number, the program must use a stack to convert the decimal number to the numeric format.
*in Java 1.Create a card class with two attributes, suit and rank. 2.In the card class,...
*in Java 1.Create a card class with two attributes, suit and rank. 2.In the card class, create several methods: a. createDeck – input what type of deck (bridge or pinochle) is to be created and output an array of either 52 or 48 cards. b.shuffleDeck – input an unshuffled deck array and return a shuffled one. + Create a swap method to help shuffle the deck c. countBridgePoints – inputs a 13-card bridge ‘hand’-array and returns the number of high-card...
USING C# 1. Write a program that takes outputs a string, an integer and a floating-point...
USING C# 1. Write a program that takes outputs a string, an integer and a floating-point number separated by commas. Sample output: Bob Marley, 20, 5.2 2. 2. Write a program that asks the user for a string of letters of any size (no spaces), and finally a special character (values 33 to 47 in the Ascii table, or ‘!’ to ‘/’). Generate a random number of any size, integer or floating point, and combine those three pieces of information...
Create this C++ program using classes 1. Create a file text file with a string on...
Create this C++ program using classes 1. Create a file text file with a string on it 2. Check the frecuency of every letter, number and symbol (including caps) 3. Use heapsort to sort the frecuencys found 4. Use huffman code on the letters, symbols or numbers that have frecuencys I created the file, and the frecuency part but i'm having trouble with the huffman and heapsort implementation.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT