Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Could you please show me how to write this code? Please make it simple as I am beginner and need to understand. For this quest,
Could you please show me how to write this code? Please make it simple as I am beginner and need to understand. For this quest, you are going to start with the Account and Transaction structs from the previous quest and write four functions:
addTransaction will ask for information for a transaction, check for valid date input, and create the newly created Transaction. Try to use uniform initialization for the return instead of creating a temporary variable.
newAccount takes in the last ID used for an account, increments it and asks for all the information for a new Account, except for the ID The past in and incremented ID is used for that. Again, try to use uniform initialization for the return value.
getCurrentBalance calculates and returns the current balance of a passed in instance of the Account struct. This will need to be calculated based on the beginning balance and transactions on the account.
findAccount uses linear search to find the account by its ID and return the index in the vector for that account. return if not found
For the main function of this quest you will need to create a vector of Account structs and then should present a menu of options for the user.
"Add account" which calls the newAccount function and adds the new account to the vector of accounts
"Add Transaction"
asks for an account ID
calls findAccount to get the index of the account
calls addTransaction to create a new transaction and pushes it onto the correct Account's transactions vector.
"Get Balance"
asks for an account ID
calls findAccount to get the index of the account
calls getCurrentBlance, passing in the correct account
displays the account's balance on the terminal.
List Transactions
asks for an account ID
calls findAccount to get the index of the account
displays all transactions neatly on the screen.
HINT:: You may want to create a printTransaction function to help with this!
"Exit Program" This entire menu should be in a while loop that ends when this option is chosen.
Try to minimize the creation of temporary variables and take advantage of functions being first class citizens when you write this code. The following is the solution to quest that we should be using in reference to this: #include
#include
#include
struct Date
int month;
int day;
int year;
;
struct Transaction
Date date;
std::string description;
float amount;
;
struct Account
int ID;
std::string firstName;
std::string lastName;
float beginningBalance;
std::vector transactions;
;
int main
Account checking;
std::cout "What is the account ID: ;
std::cin checking.ID;
std::cout "What is the account holder's first and last name: ;
std::cin checking.firstName checking.lastName;
std::cout "What is the beginning balance for the account: ;
std::cin checking.beginningBalance;
checking.transactions.pushbackTransaction;
std::cout "Please enter the date of the transaction in the format: MM DD YY ;
std::cin checking.transactions.backdate.month checking.transactions.backdate.day checking.transactions.backdate.year;
if checkingtransactions.backdate.month checking.transactions.backdate.month checking.transactions.backdate.month ;
if checkingtransactions.backdate.day checking.transactions.backdate.day checking.transactions.backdate.day ;
if checkingtransactions.backdate.year && checking.transactions.backdate.year
checking.transactions.backdate.year ;
else if checkingtransactions.backdate.year && checking.transactions.backdate.year
checking.transactions.backdate.year ;
else
checking.transactions.backdate.year ;
std::cout "Where did the transaction take place: ;
std::cin checking.transactions.backdescription;
std::cout "How much was the transaction: ;
std::cin checking.transactions.backamount;
checking.transactions.pushbackTransaction;
std::cout "Please enter the date of the transaction in the format: MM DD YY ;
std::cin checking.transactions.backdate.month checking.transactions.backdate.day checking.transactions.backdate.year;
if checkingtransactions.backdate.month checking.transactions.backdate.month checking.transactions.backdate.month ;
if checkingtransactions.backdate.day checking.transactions.backdate.day checking.transactions.backdate.day ;
if checkingtransactions.backdate.year && checking.transactions.backdate.year
checking.transactions.backdate.year ;
else if checkingtransactions.backdate.year && checking.transactions.backdate.year
checking.transactions.backdate.year ;
else
checking.transactions.backdate.year ;
std::cout
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started