Skip to content

Commit 6368f6d

Browse files
committed
Wk-2 assessment
1 parent 2d1df82 commit 6368f6d

5 files changed

Lines changed: 29 additions & 7 deletions

File tree

a.out

2.67 MB
Binary file not shown.

b.out

2.67 MB
Binary file not shown.

bank_account.hpp

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,43 @@ class BankAccount {
99

1010
public:
1111
// Constructor
12-
BankAccount(){
13-
// TODO: Implement the constructor
12+
BankAccount() : accountNumber(""), accountHolderName(""), balance(0.0) {
13+
// Default initialization for an empty account
1414
}
1515

16-
BankAccount(const std::string& accNumber, const std::string& accHolder, double initialBalance){
17-
// TODO: Implement the constructor
16+
BankAccount(const std::string& accNumber, const std::string& accHolder, double initialBalance)
17+
: accountNumber(accNumber), accountHolderName(accHolder), balance(initialBalance) {
18+
// Constructor initializes the account with the provided values
1819
}
1920

2021
// Deposit method
2122
void Deposit(double amount) {
2223
// TODO: Implement the Deposit method
24+
if(amount > 0){
25+
balance += amount;
26+
std::cout << "Deposited " << amount << " to the account.\n";
27+
} else {
28+
std::cout << "Deposit amount must be positive.\n";
29+
}
2330
}
2431

2532
// Withdraw method
2633
void Withdraw(double amount) {
2734
// TODO: Implement the Deposit method
35+
if(amount <= balance){
36+
balance -= amount;
37+
std::cout << "Withdrew " << amount << " from the account.\n";
38+
} else {
39+
std::cout << "Insufficient balance for withdrawal.\n";
40+
}
2841
}
2942

3043
// Display account information
3144
void DisplayAccountInfo() {
3245
// TODO: Implement the DisplayAccountInfo method
46+
std::cout << "Account Number: " << accountNumber << std::endl;
47+
std::cout << "Account Holder: " << accountHolderName << std::endl;
48+
std::cout << "Balance: " << balance << std::endl;
3349
}
3450

3551
double GetBalance() const {

factorial.hpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
1+
#include <stdexcept> // Include this to use std::invalid_argument
2+
13
#define CATCH_CONFIG_MAIN
24

35
// Function to calculate factorial using multiple threads
46
long calculateFactorial(int n) {
5-
long result = 0;
6-
//TODO: Implement the function to calculate factorial of n
7-
7+
long result = 1; // Initialize result as 1, not 0
8+
if (n < 0) {
9+
throw std::invalid_argument("Factorial is not defined for negative numbers.");
10+
}
11+
for (int i = 1; i <= n; i++) {
12+
result *= i; // Multiply by i, not 1
13+
}
814
return result;
915
}

factorial.hpp.gch

18.7 MB
Binary file not shown.

0 commit comments

Comments
 (0)