Answered step by step
Verified Expert Solution
Link Copied!

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 -1 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 2 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.push_back(Transaction());
std::cout << "Please enter the date of the transaction in the format: MM DD YY ";
std::cin >> checking.transactions.back().date.month >> checking.transactions.back().date.day >> checking.transactions.back().date.year;
if (checking.transactions.back().date.month <1|| checking.transactions.back().date.month >12) checking.transactions.back().date.month =12;
if (checking.transactions.back().date.day <1|| checking.transactions.back().date.day >31) checking.transactions.back().date.day =31;
if (checking.transactions.back().date.year >0 && checking.transactions.back().date.year <21)
checking.transactions.back().date.year +=2000;
else if (checking.transactions.back().date.year >70 && checking.transactions.back().date.year <99)
checking.transactions.back().date.year +=1900;
else
checking.transactions.back().date.year =2021;
std::cout << "Where did the transaction take place: ";
std::cin >> checking.transactions.back().description;
std::cout << "How much was the transaction: ";
std::cin >> checking.transactions.back().amount;
checking.transactions.push_back(Transaction());
std::cout << "Please enter the date of the transaction in the format: MM DD YY ";
std::cin >> checking.transactions.back().date.month >> checking.transactions.back().date.day >> checking.transactions.back().date.year;
if (checking.transactions.back().date.month <1|| checking.transactions.back().date.month >12) checking.transactions.back().date.month =12;
if (checking.transactions.back().date.day <1|| checking.transactions.back().date.day >31) checking.transactions.back().date.day =31;
if (checking.transactions.back().date.year >0 && checking.transactions.back().date.year <19)
checking.transactions.back().date.year +=2000;
else if (checking.transactions.back().date.year >70 && checking.transactions.back().date.year <99)
checking.transactions.back().date.year +=1900;
else
checking.transactions.back().date.year =2019;
std::cout <<

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions