Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create a library containing the Fraction class After compiling a console application project, the output will be an executable. A library project on the other

Create a library containing the Fraction class After compiling a console application project, the output will be an executable. A library project on the other hand will produce a dll file(s). This is because a library template compiles to a dynamic linked library. Hence you will not be able to run this project. This class consist of 6 members.

Fraction Class Properties + C# property Top : int + C# property Bottom : int

Methods + constructor Fraction(int top = 0, int bottom = 1) +$ C# operator +(Fraction left, Fraction right) : Fraction +$ C# operator -(Fraction left, Fraction right) : Fraction + ToString() : string

Description of class members Fields: There are no fields Properties:All the properties have public getters and the settersare absent.

Top this property represents the numerator of this object.

Bottom this property represents the denominator of this object Some common decorators for class members + public # protected - private $ class member (static)

Constructor: Fraction(int top = 0, int bottom = 1) This constructor takes two optional parameters and assigns them to the appropriate properties.

Operators: There are two overloaded operators: the addition and the subtraction operators

public static Fraction operator +(Fraction left, Fraction right) This will implement the addition operation. public static Fraction operator -(Fraction left, Fraction right) This will implement the subtraction operation. This will throw an exception if the right argument is larger than the left side argument. i.e. if the resulting difference will be negative.

Methods: public override string ToString() This is a public method overrides the corresponding method in the object class to return a stringify form of the object. You get to decide how the properties will be display to the user. Try to keep the output on a single line.

Unit Testing Remember in testing you will compare the expected value to the actual value. You need to write the testing methods for the following: Page 2 of 4 Look at the Complex Number Lab to for hints on operator overloading If you are having problems accessing your Fraction class from your testing project, or running your tests check the following: Verify that the Fraction class is public Ensure a reference to the library is added to your testing project Add the necessary using statement Confirm that you are NOT running from an unsecured drive such as the network H drive

Programming II Fraction: Library, Unit Testing //1, 2 & 3 Constructor. You must test the three cases: creating a fraction with two ints, with one int and with no argument //arrange //declare and suitably initialise two int: expectedTop and expectedBottom //act //create a fraction using the above two arguments //assert //compare the expectedTop with the Top property of the above object //compare the expectedBottom with the Bottom property of the above fraction [TestMethod] public void Constructor_WithZeroArgument() { //arrange int expectedTop = 0, expectedBottom = 1; //act Fraction f = new Fraction() //assert Assert.AreEqual(expectedTop, f.Top); Assert.AreEqual(expectedBottom, f.Bottom); } //4 ToString. //arrange //declare and initialise two ints //declare the variable expectedString that will depend on your ToString() method. Page 3 of 4 Note: To test this constructor exhaustively, you need to check three conditions: constructor with zero, one and two arguments

Programming II Fraction: Library, Unit Testing //act //declare and create an object using the above two ints //assert //compare the expectedString variable to the actual output of the ToString() method . //5 Addition. //6 Subtraction without exception. //7 - Subtraction with exception. Page 4 of 4 You may use the following sample for your addition 11 10 =3 5 + 1 2 You may use the following sample for your subtraction 1 10 =3 5 + 1 2 You may use the following sample for your subtraction 1 10 =1 2 + 3

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Technology And Management Computers And Information Processing Systems For Business

Authors: Robert C. Goldstein

1st Edition

0471887374, 978-0471887379

More Books

Students also viewed these Databases questions