Skip to content

Latest commit

 

History

History

ex00

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 

Exercise 00: My First Class in Orthodox Canonical Form

Objective

The objective of this exercise is to create a class in the Orthodox Canonical Form that represents a fixed-point number. You will implement a class with specific private and public members, including constructors, a destructor, and member functions, following the orthodox canonical form.

Description

In this exercise, you will create a Fixed class with the following specifications:

Private Members

  • _fixedPointValue: An integer to store the fixed-point number value.
  • _fractionalBits: A static constant integer to store the number of fractional bits. Its value will always be 8.

Public Members

  • Default Constructor: Initializes the fixed-point number value to 0.
  • Copy Constructor: Initializes the fixed-point number value by copying another Fixed object.
  • Copy Assignment Operator Overload: Assigns the value of one Fixed object to another.
  • Destructor: Cleans up resources when a Fixed object is destroyed.
  • Member Function getRawBits: Returns the raw integer value of the fixed-point number.
  • Member Function setRawBits: Sets the raw integer value of the fixed-point number.

Example

Fixed a;
Fixed b(a);
Fixed c;

c = b;

std::cout << a.getRawBits() << std::endl; // Output: 0
std::cout << b.getRawBits() << std::endl; // Output: 0
std::cout << c.getRawBits() << std::endl; // Output: 0

a.setRawBits(42);

std::cout << a.getRawBits() << std::endl; // Output: 42

Resources