Define class to represent the credit limit - C++ Class

C++ examples for Class:Class Creation

Description

Define class to represent the credit limit

Demo Code

                         
#include <iostream>
                         /*from w w  w  . jav  a 2  s  .c  o  m*/
class Account {
 private:
    int accountNumber = 0;
    double beginningBalance = 0.0f;
    double newBalance = 0.0f;
    double totalMonthCharges = 0.0f;
    double totalMonthCredit = 0.0f;
    double creditLimit = 0.0f;
                         
 public:
    Account();
    ~Account();
                         
    // SETTERS
    void setAccountNumber(int);
    void setBeginningBalance(double);
    void setNewBalance();
    void setTotalMonthCharges(double);
    void setTotalMonthCredit(double);
    void setCreditLimit(double);
                         
    // GETTERS
    int getAccountNumber();
    double getBeginningBalance();
    double getNewBalance();
    double getTotalMonthCharges();
    double getTotalMonthCredit();
    double getCreditLimit();
                         
    bool isCreditLimitExceeded();
                         
    void run();
    void printInfo();
};
Account::Account() {}
Account::~Account() {}
                         
// SETTERS
void Account::setAccountNumber(int accNo) { accountNumber = accNo; }
void Account::setBeginningBalance(double startBalance) {
    beginningBalance = startBalance;
}
void Account::setNewBalance() {
    newBalance = (getBeginningBalance() + getTotalMonthCharges()) -
                 getTotalMonthCredit();
}
void Account::setTotalMonthCharges(double totalCharges) {
    totalMonthCharges = totalCharges;
}
void Account::setTotalMonthCredit(double totalCredit) {
    totalMonthCredit = totalCredit;
}
void Account::setCreditLimit(double limit) { creditLimit = limit; }
                         
// GETTERS
int Account::getAccountNumber() { return accountNumber; }
double Account::getBeginningBalance() { return beginningBalance; }
double Account::getNewBalance() { return newBalance; }
double Account::getTotalMonthCharges() { return totalMonthCharges; }
double Account::getTotalMonthCredit() { return totalMonthCredit; }
double Account::getCreditLimit() { return creditLimit; }
// determine if credit limit is exceeded
bool Account::isCreditLimitExceeded() {
    return (getCreditLimit() - getNewBalance() < 0) ? true : false;
}
                         
void Account::printInfo() {
    std::cout << "Account: " << getAccountNumber() << std::endl;
    std::cout << "Credit limit: " << getCreditLimit() << std::endl;
    std::cout << "Balance: " << getNewBalance() << std::endl;
                         
    if (isCreditLimitExceeded()) {
        std::cout << "Credit Limit Exceeded." << std::endl;
    }
}
                         
void Account::run() {
    int itmp;
    std::cout << "Enter account number (or -1 to quit): ";
    std::cin >> itmp;
    setAccountNumber(itmp);
                         
    if (getAccountNumber() != -1) {
        double dtmp;
                         
        std::cout << "Enter beginning balance: ";
        std::cin >> dtmp;
        setBeginningBalance(dtmp);
                         
        std::cout << "Enter total charges: ";
        std::cin >> dtmp;
        setTotalMonthCharges(dtmp);
                         
        std::cout << "Enter total credits: ";
        std::cin >> dtmp;
        setTotalMonthCredit(dtmp);
                         
        std::cout << "Enter credit limit: ";
        std::cin >> dtmp;
        setCreditLimit(dtmp);
                         
        setNewBalance();
                         
        printInfo();
    }
}
int main(int argc, const char *argv[]) {
    Account cl;
                         
    while (cl.getAccountNumber() != -1) {
        cl.run();
    }
    return 0;
}

Result


Related Tutorials