如何计算总余额和总利息+显示 [英] How do I calculate the total balance and total interest + display

查看:87
本文介绍了如何计算总余额和总利息+显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿伙计们,我一直在为4个银行账户建立这个银行账户计划,我一直在努力计算总余额和总利息并显示两者。



谁能帮助我,我尝试了很多东西,但我只用了2个星期进入C ++,我很想得到一些亲的帮助。



问题是我不知道如何计算一些代码总数会很好输出应该添加所有最终的bal和所有最终兴趣并给出总bal和总interes



什么我试过了:



Hey guys i have been building this bank account programme for 4 bank accounts and i have been struggling in calculating the total balance and total interest and display both.

Could anyone help me i tried many things yet i am just 2 weeks into C++ and i would love to have some pro help.

The problem is that i do not know how to calculate totals a bit of code would be great the output should add all the final bal and all final interest and give total bal and total interes

What I have tried:

#include <iostream>
#include <iomanip>
#include <stdlib.h>
using namespace std;

class bank_account
{
public:
    bank_account();
    bank_account(int account_no, float opening_balance);
    void deposit(float amount);
    void withdraw(float amount);
    float interest(float interest_rate);
    void balance();
    void display_balance();
    void display_interest_earned();
    void display_bank_heading();
    void display_bank_body();
    void display_bank_bottom();
    void display_total_balance();
    void display_total_interest();
private:
    int dm_account_no;
    float dm_balance;
    float dm_interest_rate;
    float dm_interest_earned;
    float dm_total_balance;
    float dm_total_interest;
};
class validation
{
public:
    bool test_userid(int user_id);
    bool test_userpin(int user_pin);

private:
    int dm_userid;
    int dm_userpin;
};

bank_account::bank_account()
{
    dm_account_no = 0;
    dm_balance =0.0;
}


bank_account::bank_account(int account_no, float opening_balance)
{
    dm_account_no = account_no;

    dm_balance = opening_balance*1.1;
}

void bank_account::deposit(float amount)
{
     dm_balance += amount;
}

void bank_account::withdraw(float amount)
{
    dm_balance -= amount;

}
void bank_account::display_total_balance()
{
    balance = ;
}


float bank_account::interest(float interest_rate)
{ dm_interest_rate = interest_rate;
    dm_interest_earned = dm_balance * dm_interest_rate;
    return dm_interest_earned;
}
void bank_account::display_interest_earned()

{   cout<<fixed<<setprecision(2)<<dm_interest_earned<<endl;}

void bank_account::display_balance()

{   cout<<fixed<<setprecision(2)<<dm_balance<<endl;}


void bank_account::display_bank_heading()
{
    cout<<" Bank Account System"<<endl;
    cout<<" ______________________________________"<<endl;
    cout<<"|                                      |"<<endl;
    cout<<"|"<<left << setw(13) <<"" << "Bank Report 1"  << right << setw(13) <<"|"<<endl;
    cout<<"|" <<left << setw(15) <<"" << "Closing"  << left << setw(8) <<""<<"Interest"<<"|" <<endl;
    cout<<"|" << left << setw(15) << "Account No" << "Balance" <<left<<setw(8) <<""<<"Earned"<<left<<setw(2)<<""<<"|" << endl;}

void bank_account::display_bank_body()
{   cout <<"|" << left << setw(15) << dm_account_no<< setw(15) << fixed << setprecision(2)
    << dm_balance <<setw(8)<<dm_interest_earned<<""<<"|"<<endl;}

void bank_account::display_bank_bottom()
{
    cout<<"|                                      |"<<endl;
    cout<<"|"<<"Total" <<right<<setw(10)<<balance<<"|"<<endl;
    cout<<"|______________________________________|"<<endl;
}

///float bank_account::balance()
///{dm_total_balance = 1905 ;
///dm_total_interest = 61.05;}

int reply;
int account_no[4]={80045001,80045002,80045003,80045004};
float opening_balance[4]={100,200,300,400};
int deposit[5]={100,200,300,400,10};
int withdraw[2]={50,155};
float interest_rate[4]={0.01,0.02,0.03,0.04};


bank_account account1,account2,account3,account4;
int main()
{

    class bank_account account1(account_no[0],opening_balance[0]);
    account1.display_bank_heading();
    account1.deposit(deposit[0]);
    account1.withdraw(withdraw[0]);
    account1.interest(interest_rate[0]);
    account1.display_bank_body();


    class bank_account account2(account_no[1],opening_balance[1]);
    account2.deposit(deposit[1]);
    account2.withdraw(withdraw[0]);
    account2.interest(interest_rate[1]);
    account2.display_bank_body();

    class bank_account account3(account_no[2],opening_balance[2]);
    account3.deposit(deposit[2]);
    account3.withdraw(withdraw[0]);
    account3.interest(interest_rate[2]);
    account3.display_bank_body();

    class bank_account account4(account_no[3],opening_balance[3]);
    account4.deposit(deposit[3]);
    account4.withdraw(withdraw[0]);
    account4.interest(interest_rate[0]);
    account4.display_bank_body();
    account4.display_bank_bottom();

    cout<< "Do you want to continue Yes or not"<<endl;
    cout<< "Enter Y to continue or N to exit"<<endl;
    cin>>reply;


    if (reply == 'N'){
        cout<<"Goodbye!"<<endl;
        exit(EXIT_FAILURE);}


    account1.display_bank_heading();
    account1.deposit(deposit[4]);
    account1.withdraw(withdraw[1]);
    account1.interest(interest_rate[0]);
    account1.display_bank_body();

    account2.deposit(deposit[1]);
    account2.withdraw(withdraw[0]);
    account2.interest(interest_rate[1]);
    account2.display_bank_body();

    account3.deposit(deposit[2]);
    account3.withdraw(withdraw[0]);
    account3.interest(interest_rate[2]);
    account3.display_bank_body();

    account4.deposit(deposit[3]);
    account4.withdraw(withdraw[1]);
    account4.interest(interest_rate[0]);
    account4.display_bank_body();
    account4.display_bank_bottom();



    cout<< "Enter 1 to continue or 2 to exit"<<endl;
    cin>>reply;
    if (reply == 2){
        cout<<"Goodbye!"<<endl;
        exit(EXIT_FAILURE);
    }
    cout<<"Continue processing"<<endl;
    return 0;
}

推荐答案

您必须在银行帐户类中实现一些返回所需值的功能。



You must implement some functions in the bank account class which are returning the needed values.

class bank_account
{
public:
  float getBalance();
float getInterest();



因此,您可以在主例程中访问这些值并进行计算它的总和。



一些额外的提示:使用一系列帐户来简化代码编写。


So you access these values in your main routine and can compute the total sums of it.

Some additional tip: use an array of accounts to ease writing code.

bank_account account[4]; //create 4 accounts
int sum = 0;
for(int i = 0: i < 4; i++ ) {
  account[i].deposit(1000);//access a function and deposit 1000 to all accounts
  sum = sum + account[i] + getBalance();
}



你完成了, - )


And you are done ,-)


这篇关于如何计算总余额和总利息+显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆