Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Required Items Wallet ( STORE IN A STRUCT ) For our Wallet struct, we need to store a few things 1 ) We need to

Required Items
Wallet (STORE IN A STRUCT)
For our Wallet struct, we need to store a few things
1) We need to store the ticker symbol for the coin ie BTC
2) We need to store how many coins we currently have
3) We also need to be able to print the information in the structure out. It will print out the ticker symbol (BTC) for the coin and the number of coins currently in the wallet.
4) You should pass the wallet struct to the methods that need it, you can think of the buy and sell methods as the setter function to add coins to the wallet and update the cash, and you can think of the getlive function as a getter function to get a simulated live value for bitcoin..
Ledger (STORE IN A STRUCT)
Inside the structure you can store the history either as an array of strings along with a number n which is the current number of strings in the array that are valid, or as a linked list of strings. I have linked list code in the class notes.
We need a procedure that is going to turn our transactions into a string and store them for our history.
1) It will store the transaction strings just so we have a record of the buy & sell commands. We are going to use ArrayList(Java) Vectors(C++) and then List (Python) for this. Ie: it will be a list of transaction strings. For C you can store transaction strings in an array or in a linked list either is fine.
2) It will be able to print out the transaction history if requested For example it might print out the following transaction strings::
Bought 1 bitcoin on September 12,201912:32:59
Sold 0.5 bitcoin on September 12,201912:33:59
3) You may want to have a method to add a transaction string. It takes as a parameter a string and adds it to the transaction list. (Once you know how many they bought or sold, there are functions available to get the current date and time. So from those pieces of data you make a string using string concatenation and then you send the string to the ledgers add method and it adds it to the ledger)
Date (IMPLEMENT AS A FUNCTION)
This function will call the library routines to get the current date. It will have a function in it that returns that date as a string. We need this for our transaction history
GetLive (IMPLEMENT AS A FUNCTION)
This is going to fetch the current live value of bitcoin. (Most of you will fake it by generating a random number between 25 and 35k. Getting the live value in Python is easy, for other languages you can find libraries to use however it is ok to just approximate the value by generating a random number for example between 25 and 35k.
Putting it all together
Your program will create an instance of the above. Additionally, it will create a variable to track your USD (you can use a double or float). You can keep your USD variable out in the main, or you can tuck it in with the wallet struction.
Then the program will go into a loop. It will print their menu options and ask what command they want to do. They can buy, sell, ask for the balance, the price, and print the history, and exit when they want to.
When you buy coins your US dollars go down and the number of bitcoins in your wallet goes up accordingly. When you sell coins your US balance goes up and the number of coins you have goes down. The variable that stores your actual cash/US dollars (USD) does not really need to be in the wallet structure if you dont want it to be. It can be just a double called USD.
Demo the program as follows:
price
price
buy 1.5 bitcoins
balance
price
sell 0.5 bitcoins
balance
history
buy 1 bitcoin
balance
history
exit

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

DB2 11 The Ultimate Database For Cloud Analytics And Mobile

Authors: John Campbell, Chris Crone, Gareth Jones, Surekha Parekh, Jay Yothers

1st Edition

1583474013, 978-1583474013

More Books

Students also viewed these Databases questions