Create two structures and name the types Account and Money. . The Money struct h
ID: 3877486 • Letter: C
Question
Create two structures and name the types Account and Money. . The Money struct has two variables. - One represents how many dollars you have. - The other represents how many cents you have. The Account struct has three variables. - A Money struct that will represent how much money is in the account - One variable to represent the interest rate as a decimal value. - The final variable will contain the name of the account. (Checking. Savings, CD, etc.) Negative amounts of Money are stored by making both variables of the Money object negative Use the following function prototypes - Account createAccount ) The function shall prompt the user for an account name, interest rate, and starting balance in that order The prompts shall appear as follows: Let's set up your account. First, what's the name of the account? What is the interest rate of your [NAME] account? Finally, what is the starting balance of your [NAME] account? INAME] shall be replaced with the name of the account You may NOT assume that the name of the account contains only a single word You may assume the user will always type an interest rate as a decimal value (e.g., 0.05) You may also assume that a positive and valid (whole number or no more than two decimal places) amount of money will be entered - Account deposit (Account account, Money deposit) The function shall not accept negative amounts of money If a negative amount of money is attempted to be deposited, an error message will be displayed and the original account will be returnedExplanation / Answer
here is your program : ------------------>>>>>>>>>>>>>>>
#include<iostream>
using namespace std;
struct Money{
int dollor;
int cents;
};
typedef struct Money money;
struct Account{
money balance;
float rate;
string name;
};
typedef struct Account account;
account createAccount(){
account temp;
system("cls");
cout<<" Let's set up Your Account , ";
cout<<" First, what is the name of the Account : ";
cin>>temp.name;
cout<<" What is the interest rate of your "<<temp.name<<" Account : ";
cin>>temp.rate;
cout<<" Finally,what is the starting balance of your "<<temp.name<<" Account : ";
float bal;
cin>>bal;
temp.balance.dollor = (int)bal;
temp.balance.cents =(int)((bal - temp.balance.dollor)*100);
return temp;
}
account deposit(account acc,money deposit){
if(deposit.dollor < 0 || deposit.cents < 0){
cout<<" cannot deposit negative balance ";
}else{
acc.balance.cents = acc.balance.cents + deposit.cents;
acc.balance.dollor = acc.balance.dollor + deposit.dollor;
if(acc.balance.cents > 100){
acc.balance.cents = acc.balance.cents - 100;
acc.balance.dollor = acc.balance.dollor + 1;
}
cout<<" $"<<deposit.dollor<<"."<<deposit.cents<<" is deposited to your "<<acc.name<<" account";
}
return acc;
}
account withdraw(account acc,money withdraw){
if(withdraw.dollor < 0 || withdraw.cents < 0){
cout<<" cannot deposit negative balance ";
}else if((acc.balance.dollor + 90) < withdraw.dollor){
cout<<"Your Account "<<acc.name<<" cant have that much money to withdraw ";
}
else{
if(acc.balance.cents < withdraw.cents){
acc.balance.cents = acc.balance.cents + 100;
acc.balance.cents = acc.balance.cents - withdraw.cents;
acc.balance.dollor = acc.balance.dollor - 1;
}
acc.balance.dollor = acc.balance.dollor - withdraw.dollor;
cout<<" $"<<withdraw.dollor<<"."<<withdraw.cents<<" is withdraw from your "<<acc.name<<" account";
}
return acc;
}
void update(account &acc){
acc.balance.dollor = acc.balance.dollor + (int)((acc.balance.dollor)*acc.rate);
cout<<" At "<<acc.rate<<" % Your Account "<<acc.name<<" earned $"<<((int)((acc.balance.dollor)*acc.rate))<<"";
}
void print(account acc){
if(acc.balance.dollor < 0){
cout<<"($"<<acc.balance.dollor<<"."<<acc.balance.cents<<" )";
}else{
cout<<" $"<<acc.balance.dollor<<"."<<acc.balance.cents;
}
}
void print(money mon){
if(mon.dollor < 0){
cout<<"($"<<mon.dollor<<"."<<mon.cents<<" )";
}else{
cout<<" $"<<mon.dollor<<"."<<mon.cents;
}
}
int main(){
account acc = createAccount();
cout<<" In your "<<acc.name<<" You have ";
print(acc);
money with;
float bal;
cout<<" Money to withdraw From your account : ";
cin>>bal;
with.dollor = (int)bal;
with.cents =(int)((bal - temp.balance.dollor)*100);
withdraw(acc,with);
update(acc);
print(acc);
cout<<" Money to deposit From your account : ";
cin>>bal;
with.dollor = (int)bal;
with.cents =(int)((bal - temp.balance.dollor)*100);
deposit(acc,with);
print(acc);
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.