Operator Overloading Assignment for CS1120 Spring 2009, Assignments of Computer Science

An assignment for a c# programming course (cs1120) in spring 2009. Students are required to write a c# windows application that uses operator overloading to define a fraction class with private members numerator and denominator. The application should allow users to input fractions in the format (a/b), parse the input, and perform addition, subtraction, multiplication, division, and comparison operations using overloaded operators. The assignment includes examples and instructions for handling different denominator scenarios.

Typology: Assignments

Pre 2010

Uploaded on 07/28/2009

koofers-user-31g
koofers-user-31g 🇺🇸

10 documents

1 / 9

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CS1120-Assignment#5 Operator Overloading Spring 2009
Operator Overloading
Lab Time Due Date
Monday 8:30 – 10:10 am
Wednesday 12:30 – 2:10 pm
Thursday 3:30 – 5:10 pm
3/16 @ 11:55 pm
3/11 @ 11:55 pm
3/19 @ 11:55 pm
Objectives
Learn how to enable C# operators to work with class objects using operator overloading.
Problem Description
You are to write a C# windows application that uses the concept of operator overloading.
Your program should define class Fraction with the private members: numerator and denominator.
You should create a fraction calculator that will have the following functions:
1 Add/subtract two Fraction numbers:
If the fractions have the same denominator, their sum/subtraction is the sum/subtraction of the
numerators over the denominator.
For example: 3/11 + 4/11 = 7/11
If the fractions have different denominators:
1) First, find the maximum common denominator.
2) Then write equivalent fractions using this denominator.
3) Add or subtract the fractions. Reduce if necessary.
For example:
3/7 + 1/2 =13/14
2 To Multiply two Fractions:
When two fractions are multiplied, the result is a fraction with a numerator that is the product of the
fractions' numerators and a denominator that is the product of the fractions' denominators.
For Example: 3/4 * 1/7 = 3/28
3 Your program should be able to compare two fractions
For example:
1 /3> 1/4 is True and 1/5 < 1/6 is False.
pf3
pf4
pf5
pf8
pf9

Partial preview of the text

Download Operator Overloading Assignment for CS1120 Spring 2009 and more Assignments Computer Science in PDF only on Docsity!

Operator Overloading

Lab Time Due Date Monday 8 :30 – 10 : 10 am Wednesday 1 2:30 – 2 : 1 0 pm Thursday 3 :30 – 5 : 1 0 pm 3 / 16 @ 11:55 pm 3 / 11 @ 11:55 pm 3 / 19 @ 11:55 pm

Objectives

 Learn how to enable C# operators to work with class objects using operator overloading.

Problem Description

You are to write a C# windows application that uses the concept of operator overloading. Your program should define class Fraction with the private members: numerator and denominator. You should create a fraction calculator that will have the following functions: 1 Add/subtract two Fraction numbers: If the fractions have the same denominator, their sum/subtraction is the sum/subtraction of the numerators over the denominator. For example: 3/11 + 4/11 = 7/ If the fractions have different denominators:

  1. First, find the maximum common denominator.
  2. Then write equivalent fractions using this denominator.
  3. Add or subtract the fractions. Reduce if necessary. For example: 3/7 + 1/2 =13/ 2 To Multiply two Fractions: When two fractions are multiplied, the result is a fraction with a numerator that is the product of the fractions' numerators and a denominator that is the product of the fractions' denominators.  For Example: 3/4 * 1/7 = 3/ 3 Your program should be able to compare two fractions For example: 1 /3> 1/4 is True and 1/5 < 1/6 is False.

Problem Specification

Your program should define the class Fraction with the private members: numerator and denominator.

In the Fraction class, overload the plus (+), minus (-), multiplication (*), division (/), and comparison (>), (<),(>=),(<=),(==) operators to enable programs to add, subtract, multiply, divide and compute other functions as defined above. Design the Form as follow:

Compare your result to the following examples:

The (++) button means plus one. For example: