Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Please help me with code in c + + . Please help me to understand the code. Continuing from our Level 3 Quest we are
Please help me with code in c Please help me to understand the code. Continuing from our Level Quest we are going to add two pieces of functionality:
The bank occasionally has a prize drawing for a random account holder. You need to write a function that randomly selects an account and displays the winning message.
The ability to save and load the accounts.
Source.cpp
You will add the following functions to yourmy level Quest solution:
findAccount: Does the same as Level Quest.
chooseAccount: asks the user for an account ID calls findAccount with that ID and continues to ask until a valid ID is entered. The Account is returned NOT THE ID
prizeDrawing: create a seed, engine, and uniform distribution between and accounts.size pick a random winner, and display that account holder's first and last name.
loadAccounts: creates a vector of the Account class, and loads it from the passed in file. The file structure is as follows
lastID
number of Accounts
Joe Smith account information ID first, last, beginning balance
number of transactions for this account
Walmart date month day year description, and amount for the transaction.
Amazon another transaction.
NOTE::The file can continue to repeat for additional accounts and additional transactions.
saveAccounts: takes a filename and vector of the Account class and saves it to the save file that was loaded from. Be sure to format the save in such a way that loadAccounts can load it
Account Class
This class takes the place of the account struct and has the following public membersmethods:
static int lastID; keeps track of the last ID
Account; Should increment lastID, ask the user for the account holder's full name and beginning balance. Use this for new accounts.
Accountint ID std::string firstName, std::string lastName, float beginningBalance; Simply assigns the values passed in Use this for loading from a file.
void addTransaction; copy code from addTransaction function from Level Quest. Adjust for being in a class. used for new transactions. asks for all information. #include
#include
#include
#include
#include
#include "Transaction.h
#include "Account.h
int findAccountint ID const std::vector & accounts;
Account& chooseAccountstd::vector& accounts;
void prizeDrawingconst std::vector& accounts;
std::vector loadAccountsconst std::string & accountFile;
void saveAccountsconst std::string & accountFile, const std::vector& accounts;
using namespace std;
int main
enum class Choices addAccount addTransaction, getBalance, print, drawPrize, exit ;
string accountFile "accounts.txt;
vector accounts loadAccountsaccountFile;
int choice;
while Choiceschoice Choices::exit
cout "Would you like to:
Add a new Account
Add a new Transaction to an existing Account
Get the current balance of an account
Print Account & Transactions
Draw Prize
Exit
;
cin choice;
switch Choiceschoice
case Choices::addAccount:
accounts.pushbackAccount;
break;
case Choices::addTransaction:
chooseAccountaccountsaddTransaction;
break;
case Choices::getBalance:
cout "Your current account balance is: $ chooseAccountaccountsgetCurrentBalance endl;
break;
case Choices::print:
chooseAccountaccountsprint;
break;
case Choices::drawPrize:
prizeDrawingaccounts;
break;
default:
break;
systemPAUSE;
systemCLS;
saveAccountsaccountFile accounts;
int findAccountint ID const std::vector& accounts
for int i; i accounts.size; i
if accountsigetID ID
return i;
return ;
Account& chooseAccountstd::vector& accounts
while true
systemCLS;
std::cout "Which account do you wish to access Account::lastID : ;
int accountID;
std::cin accountID;
if int accountIndex findAccountaccountID accounts; accountIndex
return accountsaccountIndex;
else
std::cout "not a valid ID
;
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