Untitled
Anonymous
Plain Text
09/07/2025 4:29 PM
2.9 KB
17
Indexable
Never
#include <iostream>
#include <string>
using namespace std;
// ---------------- Base Class ----------------
class Customer {
protected:
string name;
int customerID;
public:
void inputCustomer() {
cout << "\n--- Enter Customer Details ---\n";
cout << "Enter Customer Name: ";
cin.ignore(); // clear buffer before getline
getline(cin, name); // allows spaces in name
cout << "Enter Customer ID: ";
cin >> customerID;
}
void displayCustomer() {
cout << "Customer Name : " << name << endl;
cout << "Customer ID : " << customerID << endl;
}
};
// ---------------- Derived Class SavingsAccount ----------------
class SavingsAccount : virtual public Customer {
protected:
double balance;
double interestRate;
public:
void inputSavings() {
cout << "\n--- Enter Savings Account Details ---\n";
cout << "Enter Balance: ";
cin >> balance;
cout << "Enter Interest Rate (%): ";
cin >> interestRate;
}
void deposit(double amount) {
balance += amount;
cout << "Deposited: " << amount << " | New Balance: " << balance << endl;
}
double calculateInterest() {
double interest = (balance * interestRate) / 100;
cout << "Interest Calculated: " << interest << endl;
return interest;
}
};
// ---------------- Derived Class LoanAccount ----------------
class LoanAccount : virtual public Customer {
protected:
double loanAmount;
double EMI;
public:
void inputLoan() {
cout << "\n--- Enter Loan Account Details ---\n";
cout << "Enter Loan Amount: ";
cin >> loanAmount;
cout << "Enter EMI: ";
cin >> EMI;
}
void calculateEMI() {
cout << "Monthly EMI: " << EMI << endl;
}
};
// ---------------- Final Class AccountHolder ----------------
class AccountHolder : public SavingsAccount, public LoanAccount {
public:
void displayAllDetails() {
cout << "\n========= Account Holder Full Details =========\n";
displayCustomer();
cout << "Balance : " << balance << endl;
cout << "Interest Rate : " << interestRate << "%" << endl;
cout << "Loan Amount : " << loanAmount << endl;
cout << "EMI : " << EMI << endl;
cout << "================================================\n";
}
};
// ---------------- Main Function ----------------
int main() {
AccountHolder ah;
// Step 1: Input details
ah.inputCustomer();
ah.inputSavings();
ah.inputLoan();
// Step 2: Deposit
double depositAmount;
cout << "\nEnter amount to deposit: ";
cin >> depositAmount;
ah.deposit(depositAmount);
// Step 3: Interest & EMI Calculation
ah.calculateInterest();
ah.calculateEMI();
// Step 4: Display all details
ah.displayAllDetails();
return 0;
}
Editor is loading...
Leave a Comment