Determine the different ways the system will be used. This includes main functions the system needs to perform and who will use it.
Core objects User
class User{
public:
string name;
string DOB;
string creditScore;
string accountNumber;
string phoneNumber;
string address;
double accountbalance;
int getCreditScore(){}
double getbalance(){}
int getCreditCardStatus(){}
void applyForLoan(){}
void getAccountInfo(){}
};
Another class can be Transaction
class Transaction{
public:
double Amount;
Transaction(){}
double Credit(double amount){}
double Deposit(double amount){}
};
Another class Loan
enum Status {
SUCCESS = 0,
FAILURE = 1,
PENDING = 2,
IN_PROGRESS = 3,
APPROVED = 4,
REJECTED = 5
};
class Loan{
public:
string loadId;
double principal;
double interestRate;
int termYear;
Status status;
Loan(double amount, double rate, int term) : principal(amount), interestRate(rate), termMonths(term), status(PENDING) {}
void approveLoan(){}
void RejectLoan(){}
};
Another can be account
class Account : Transaction{
public:
User user;
void authenticate_address(){}
void authenticate_phoneNmber(){}
void creditAccount(double amount) {}
void depositAccount(double amount){}
};
Determine how these objects will interact with each other to fulfill the use cases...
Design inheritance trees where applicable to promote code reuse and polymorphism. This step involves identifying common attributes and behaviors that can be abstracted into parent classes...
Consider using design patterns (e.g., Factory, Singleton, Observer, Strategy) that fit the problem...
Attributes: For each class, define the attributes (data) it will hold...
Methods: Define the methods (functions) that operate on the attributes. Ensure they align with the object's responsibilities and adhere to the principle of encapsulation.
#include <iostream>
#include <vector>
using namespace std;
enum Status {
SUCCESS = 0,
FAILURE = 1,
PENDING = 2,
IN_PROGRESS = 3,
APPROVED = 4,
REJECTED = 5
};
class User{
public:
string name;
string DOB;
string creditScore;
string accountNumber;
string phoneNumber;
string address;
Status status;
double accountbalance;
User(string name , string DOB, string creditScore, string accountNumber , string phoneNumber , string address , double accountbalance ){
this->name = name;
this->DOB = DOB;
this->creditScore = creditScore;
this->accountNumber = accountNumber;
this->phoneNumber = phoneNumber;
this->address = address;
this->accountbalance = accountbalance;
}
int getCreditScore(){
return creditScore;
}
double getbalance(){
return accountbalance;
}
void getCreditCardStatus(){
if (creditScore > 700)
{
status = SUCCESS;
}
else{
status = PENDING;
}
}
void applyForLoan(){
}
void getAccountInfo(){
cout << accountNumber << endl;
}
};
class Loan{
public:
string loadId;
double principal;
double interestRate;
int termMonths;
Status status;
Loan(double amount, double rate, int term) : principal(amount), interestRate(rate), termMonths(term), status(PENDING) {}
void approveLoan(){
status = APPROVED;
cout << "Loan approved!" << endl;
}
void RejectLoan(){
status = REJECTED;
cout << "Loan rejected!" << endl;
}
void getLoanInfo() {
cout << "Loan ID: " << loadId << endl;
cout << "Principal: $" << principal << endl;
cout << "Interest Rate: " << interestRate << "%" << endl;
cout << "Term (months): " << termMonths << endl;
cout << "Loan Status: " << (status == APPROVED ? "Approved" : status == PENDING ? "Pending" : "Rejected") << endl;
}
};
class Transaction {
public:
double amount;
Transaction() : amount(0.0) {}
double credit(double amount) {
this->amount += amount;
return this->amount;
}
double deposit(double amount) {
this->amount -= amount;
return this->amount;
}
};
// Account Class (Inherits from Transaction)
class Account : public Transaction {
public:
User user;
Account(User u) : user(u) {}
void authenticateAddress() {
cout << "Authenticating address: " << user.address << endl;
// Logic to authenticate address
}
void authenticatePhoneNumber() {
cout << "Authenticating phone number: " << user.phoneNumber << endl;
// Logic to authenticate phone number
}
// Function to credit account balance
void creditAccount(double amount) {
user.accountbalance = credit(amount);
cout << "Credited " << amount << " to the account. New balance: " << user.getbalance() << endl;
}
// Function to deposit from account balance
void depositAccount(double amount) {
user.accountbalance = deposit(amount);
cout << "Debited " << amount << " from the account. New balance: " << user.getbalance() << endl;
}
};
int main() {
User user("John Doe", "01-01-1980", "750", "123456", "9876543210", "123 Main St", 1000.0);
Account account(user);
account.getAccountInfo();
account.authenticateAddress();
account.authenticatePhoneNumber();
account.creditAccount(500); // Crediting account
account.depositAccount(300); // Depositing (withdrawing) from account
return 0;
}
Check and explain whether your design adheres to solid principles (Ask interviewer what SOLID principle is if you can not recall it.)...
Explain how your design can handle changes in scale and whether it would be easily to extend with new functionalities...
Try creating a class, flow, state and/or sequence diagram using the diagramming tool. Mermaid flow diagrams can be used to represent system use cases. You can ask the interviewer bot to create a starter diagram if unfamiliar with the tool. Briefly explain your diagrams if necessary...
Critically examine your design for any flaws or areas for future improvement...