Programming in C++

Exercise Sheet 2
  1. Create a new directory for this session’s exercises. Create a file account.cc containing a bank account class. Your class should contain private fields for the customer’s name and a balance, one or more constructors, extractor methods to access the name and balance, and methods to deposit and withdraw an amount. Write a simple main function that creates a few of these objects and tests them.

  2. How can you ensure that no bank account object is created without supplying a customer name?

  3. Move some of the methods out of the class, and get the result to compile. Also try this with a constructor.

  4. Define a bank class, containing a vector of bank accounts, with methods to add a new account and to print all the accounts.

  5. Add a method to deposit a specified amount into the account of a named customer, and another to similarly withdraw. Use your print method to test them.

  6. Add a method to add a specified amount of interest (e.g. 3.5 meaning 3.5%) to each account in the bank. Again, test it with your print method.