This exercise is available at https://study.find-santa.eu/exercises/cpp/oop_intro/.
For the sake of the environment, please avoid printing these instructions in the future. Thank you!

Introduction to OOP

Before submitting your solutions, make sure that cppcheck doesn't show any errors.

  1. Circle
    Create the following files: main.cpp, circle.hpp, circle.cpp and Makefile. The Circle class in the slides is incomplete. Implement the area() and circumference() functions. Think about different implementation strategies (calculation upon calls to the function, calculation upon call to radius or a caching strategy). Explain your decision in comments.
    Create a Makefile for compiling your code.
  2. Bank Account
    Create an Account class for managing bank account information. The class must be defined in account.hpp and the non-trivial methods in account.cpp. Both must be implemented inside of a bank namespace. Use the Account in this mini-project's main.cpp file: Provide a Makefile that compiles the project.
    The bank account must follow the specification in the class diagram below:
    [Bank Account Class Diagram]
    The first three lines in the diagram are data members. The minus in front of them indicates that they are private members. The remaining entries are methods with the plus indicating public access.
    The amounts are stored as integral numbers to avoid problems with floating point precision. The amount stored in the balance represents cents. A balance of 172042 corresponds hence to 1720 Euros and 42 Cents. Note that the withdraw(.) methods returns the amount actually withdrawn which will help us when subclassing the Account in the future.
    Override the << operator to print account data (account number and current balance in Euro and Cent).
  3. Rolling a Die
    Implement a class for rolling a six-sided die. The class should store the last result in a private variable. In addition, it should keep stats of how many times each number was thrown in an appropriate data structure. The API of the class must offer four public methods:
    // reset all stats to 0
    void reset();
    
    // create a random integer 1..6, store it as private property and return it
    int roll();
    
    /* print the stats, one per line (eg.
    1: 45
    2: 53
    ...
     */
    void print_stats();
    
    // return the stored integer result from the last toss
    int value();
    In main(.), instantiate an object of the above class, roll the die 10000 times and print the stats to stdout.
    Name the source file: rolling_a_die.cpp
  4. Roulette
    Implement a class for playing a simplified roulette game. The class must store the most recent number. It must offer an API to start a new game and interpret the resulting number.
    bool is_black();
    bool is_even();  // aka. pair
    bool is_high();  // the number was between 19..36 (passe)
    bool is_low();  // the number was between 1..18 (manque)
    bool is_odd();  // aka. impair
    bool is_red();
    bool is_zero();
    
    // create a random integer 0..36, store it as private property and return it
    int roll();
    
    // return the stored integer
    int value();
    Name the source file: roulette.cpp