Programming Exercises

1:Implement a struct called Fraction that contains two private data members of type int called numerator and denominator. Equip Fraction with the following elements:
  • A constructor that takes two arguments to initialize numerator and denominator

  • Properties to get and set numerator and denominator

  • A property called Value that simply returns the value of the fraction, which is calculated as (numerator / denominator)

  • Override the ToString method (implicitly inherited from System.Object) to return the following string: “Fraction value: xxx” where xxx represents the fraction value as a string.

Write suitable code to test the Fraction struct.

Get C# Primer Plus now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.