O'Reilly logo

C# Primer Plus by Klaus Michelsen

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required