Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Programming the following questions 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
1
2
,
2
0
1
9
1
2
:
3
2
:
5
9
Sold
0
.
5
bitcoin on September
1
2
,
2
0
1
9
1
2
:
3
3
:
5
9
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 ledger
s
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
2
5
and
3
5
k
.
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
2
5
and
3
5
k
.
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 don
t want it to be
.
It can be just a double called USD.
Grading
4
0
points
(
Struct and Functions
)
I will be checking your code to make sure you made the wallet structure, ledger structure, date function, and getlive function are implemented as described. Additionally the buy and sell commands should be implemented as functions
/
procedures with the relevant information they need passed in as arguments..
3
0
points
(
Main loop
)
I would like to make sure your menu and main loop works.
1
5
points
(
buy and sell functions with instance handles passed in
)
The buy and sell command should also be implemented as separate functions which are called from main. You should pass in the handles to the wallet, ledger, date and getlive as parameters so you can access them as needed within the function.
1
5
points
(
demo the programs functionality
)
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

Database In Depth Relational Theory For Practitioners

Authors: C.J. Date

1st Edition

0596100124, 978-0596100124

More Books

Students also viewed these Databases questions

Question

1. Describe the power of nonverbal communication

Answered: 1 week ago

Question

2. Outline the functions of nonverbal communication

Answered: 1 week ago