#include #include typedef long long integer; typedef struct { integer numerator; integer denominator; } Fraction; void Fraction_i_i(Fraction* this, integer numerator, integer denominator) { this->numerator = numerator; this->denominator = denominator ? denominator : 1; } void Fraction_i(Fraction* this, integer numerator) { this->numerator = numerator; this->denominator = 1; } void Fraction_(Fraction* this) { this->numerator = 0; this->denominator = 1; } integer Fraction_getNumerator(const Fraction* this) { return this->numerator; } void Fraction_setNumerator(Fraction* this, integer numerator) { this->numerator = numerator; } integer Fraction_getDenominator(const Fraction* this) { return this->denominator; } void Fraction_setDenominator(Fraction* this, integer denominator) { if ( denominator ) this->denominator = denominator; } void Fraction_print(const Fraction* this) { printf("%lld/%lld", Fraction_getNumerator(this), this->denominator); } // Funcion libre int main() { Fraction fr1; Fraction_( &fr1 ); Fraction_setDenominator(&fr1, 3); Fraction_setDenominator(&fr1, 0); printf("fr1 = "); Fraction_print(&fr1); putchar('\n'); Fraction fr2; Fraction_i_i(&fr2, 2, 9); printf("fr2 = "); Fraction_print(&fr2); putchar('\n'); Fraction fr3; Fraction_i(&fr3, 5); printf("fr3 = "); Fraction_print(&fr3); putchar('\n'); Fraction* fr0 = (Fraction*) malloc( sizeof(Fraction) ); Fraction_(fr0); free(fr0); return 0; }