Giter VIP home page Giter VIP logo

assignment-7's Introduction

Task 1

Create a class called Rational for performing arithmetic with fractions. Write a program to test your class.
Use integer variables to represent the private data of the class— the numerator and the denominator.
Provide a constructor that enables an object of this class to be initialized when it’s declared.
The constructor should contain default values in case no initializers are provided and should store the fraction in reduced form. For example, the fraction would be stored in the object 2/4 as 1 in the numerator and 2 in the denominator.

Provide public member functions that perform each of the following tasks:

add — adds two Rational numbers. The result should be stored in reduced form.

subtract —s ubtracts two Rational numbers. Store the result in reduced form.

multiply — multiplies two Rational numbers. Store the result in reduced form.

divide — divides two Rational numbers. The result should be stored in reduced form.

toRationalString — Returns a string representation of a Rational number in the form a/b, where a is the numerator and b is the denominator.

toDouble — Returns the Rational number as a double.

Task 2

Modify the supplied Date class to perform error checking on the initializer values for data members month,
day and year. Also, provide a member function nextDay to increment the day by one. Write a program that tests function nextDay in a loop that prints the date during each iteration to illustrate that nextDay works correctly.

Be sure to test the following cases:

Incrementing into the next month

Incrementing into the next year

assignment-7's People

Contributors

tyanakiev avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.