Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

This project consists of implementing a C++ class following the canonical form of Coplien, which includes a default constructor, copy constructor, assignment operator, and destructor. The goal is to create a Fixed class representing fixed-point numbers, with a fixed precision of 8 bits for the fractional part.

NotificationsYou must be signed in to change notification settings

cypri1-dev/42_CPP02

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Description

This project consists of implementing a C++ class following the canonical form of Coplien, which includes a default constructor, copy constructor, assignment operator, and destructor. The goal is to create a Fixed class representing fixed-point numbers, with a fixed precision of 8 bits for the fractional part.

Exercise 00 - My First Canon

Objectives 🚀:

  • This exercise introduces you to the canonical form of Coplien in C++.
  • You will create a class that represents a fixed-point number with 8 bits of fractional precision.

Requirement:

  • Create a class namedFixed that adheres to the canonical form of Coplien (default constructor, copy constructor, assignment operator, and destructor).
  • Add the following private member: an integer to store the fixed-point number's value - a static constant integer representing the number of bits (always 8) used for the fractional part.
  • Public member functions: agetRawBits() function that returns the raw value of the fixed-point number - asetRawBits(int const raw) function to set the raw value.
  • In themain function, create instances ofFixed, copy them, assign values, and print the results usinggetRawBits().

Exercise 01 - First Steps Toward a Useful Class

Objectives 🚀:

  • This exercise builds on the previous one by adding constructors for converting integers and floating-point numbers to fixed-point representation.

Requirements:

  • Extend theFixed class by adding: a constructor that takes an integer and converts it to fixed-point - a constructor that takes a floating-point number and converts it to fixed-point - atoFloat() member function to convert the fixed-point number to a floating-point number - atoInt() member function to convert the fixed-point number to an integer.
  • Overload the output stream operator (<<) to print the fixed-point number in floating-point format.
  • Test these features in themain function by creatingFixed instances from integers and floating-point numbers, then print their values and conversions.

Exercise 02 - Now We Can Talk

Objectives 🚀:

  • This exercise explores operator overloading to perform arithmetic and comparison operations with fixed-point numbers.

Requirements:

  • Overload the following operators for theFixed class: Comparison operators:>,<,>=,<=,==,!= - Arithmetic operators:+,-,*,/ - Increment/decrement operators:++,-- (both prefix and postfix).
  • Add static member functionsmin() andmax() to return the smaller or larger of twoFixed objects.
  • Test each functionality in themain function to ensure proper behavior.

Exercise 03 - BSP

Objectives 🚀:

  • This exercise demonstrates how to use theFixed class for practical purposes, such as determining whether a point is inside a triangle using Binary Space Partitioning (BSP).

Requirements:

  • Create a Point class that represents a 2D point using Fixed coordinates.
  • Add the following: Private members forx andy coordinates (asFixed) - A constructor, copy constructor, assignment operator, and destructor.
  • Implement the functionbool bsp(Point const a, Point const b, Point const c, Point const point) which determines ifpoint is inside the triangle formed bya,b, andc.

About

This project consists of implementing a C++ class following the canonical form of Coplien, which includes a default constructor, copy constructor, assignment operator, and destructor. The goal is to create a Fixed class representing fixed-point numbers, with a fixed precision of 8 bits for the fractional part.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp