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.


   


C# Primer Plus
C Primer Plus (5th Edition)
ISBN: 0672326965
EAN: 2147483647
Year: 2000
Pages: 286
Authors: Stephen Prata

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net