Skip to content

UoL-SoCS/w2-factorials-constructors-and-methods-KendoCee25

 
 

Repository files navigation

Open in Codespaces

CMP9133 - Workshop 2

University of Lincoln
School of Computer Science
CMP9133 – Advanced Programming

Task1

Modify the factorial.hpp file for computing the factorial of a given number. This task will introduce you to basic control structures (loops) and basic mathematical operations in C++.

Hint: the factorial for negative numbers is not defined, so you will need to raise an ìnvalid_argument`exception in that case. Go look online how to do that 😉

Test Case:

Input: 5
Output: 120

Mathematically, the factorial of a number n is n!, which is given by either

    1. n! = 1 x 2 x 3 x … x (n-2) x (n-1) x n
    2. n! = n x (n-1)!

Task2

Modify the file bank_account.hpp that defines a simple bank account class. The class should have the following properties and methods:

  1. Properties:
    • Account Number
    • Account Holder Name
    • Balance
  2. Methods:
    • Constructor: Initialize the account with an account number, account holder name, and initial balance.
    • Deposit: Accept an amount and add it to the balance.
    • Withdraw: Accept an amount and deduct it from the balance. Make sure the withdrawal doesn't exceed the available balance.
    • Display Account Information: Display the account number, account holder name, and balance.

The program will prompt the user to enter the bank account number, account name, and initial balance, and then create an instance of the BankAccount class using the provided input. It will then demonstrate the usage of the class by performing deposits and withdrawals and displaying account information.

Test Case:
Input: > bank_account.exe 
Output:

image

About

uol-cmp9133-w2-cmp9133-w2 created by GitHub Classroom

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C++ 100.0%