Using OOP in C++ to make a Currency Converter

            In my time of learning C++ and comparing it to Java, there have been many clear differences I agree and disagree in using when it comes to coding a simple and general program. As such, I decided to make a currency converter. A program that provides options of what currency one would want converted from the Canadian dollar. After inputting that option, a new input that accepts numbers which represents the Canadian dollar is then accepted into the system and outputs the converted amount in the currency that the user chose.

            The program starts with the main driver printing out all the options the program has to offer. The options include the US dollar, Euro, Japanese Yen, and Australian Dollar. The “cout” syntax, mentioned in the last blog post, is used to display streams of characters followed the insertion operator (<<). The options are displayed on the terminal which then follows up with a new syntax called “cin”. This syntax is used to read inputs into the stream and put them into a declared variable, which in this code is the is the currencyInput variable.

 



            After that, a new class was made called CurrencyOption. This class will contain the needed variables that will contain the input from the options, the cases for each option to choose from and the calculations to convert the Canadian dollar to the chosen currency. The private section of the class contains the variables currencyIn, amount, and convertedAmount. The first variable will contain the input value option from the main driver class. The second is the variable that will receive the inputted amount of Canadian dollar that is to be converted. The last variable will contain the converted amount.

 


            In the public section, the first method is the constructor of the class. This is where the input will be passed through from the main driver. The variable currencyIn will have the value that gets passed through which will be used at a different part of the code.

 

 

            The other void method is called currencySelection, which is the method that contains the switch cases for the different options of currency conversion. Each case will have a cout syntax that contains the message to enter the amount, a cin syntax to receive the amount input, the calculation to convert the Canadian dollar to the currency, and the converted amount being printed onto the terminal.

 


            Back in the main driver, a new object pointer is declared and is set to pass the value of the input variable. On the next line, the currencySelection method is called through the co variable object in order to convert the inputted Canadian dollar amount to the currency the user chose to convert to.

 


            With all the code coming together, the program of currency conversion is created and ready to be used. After running the code, the user is then displayed with an option to choose the US Dollar, Euro, Japanese Yen, or Australian Dollar. After choosing, another message pops up asking the user to enter an amount they want to be converted. After entering, the output is the converted amount in the currency chosen.

 

 

            After making this program, I have come to adore C++ programming. The ease of reading and making blocks of code. The method of having the access modifiers be sections is easy to the eye and convenient to use. The program is simple and easy to use. Programming it in Java would be very much similar but comparing it with how C++ does it, I believe I prefer this method of programming.

 

            Thank you for reading this far, this extremely rushed, and I hope you can give me a passing evaluation for pushing for attempting the least number of words required to pass but failing. May you have a great day or night and have a happy easter. Thank you very much again. Word padding.

Comments