Question
You are required to submit via one cpp file for each of the parts in this lab. Name your files: Rational.h Rational.cpp testRational.cpp I have
You are required to submit via one cpp file for each of the parts in this lab. Name your files: Rational.h Rational.cpp testRational.cpp
I have Submit my code please just need to get fix it, i have problems with code
#include
//Rational.cpp
#include#include "Rational.h" using namespace std; Rational::Rational() //initialising the values of constructor { num = 0; den = 0; } void Rational::setNumerator(int n1) { n1 = num; } void Rational::setDenominator(int d1) { d1 = den; } Rational Rational::Add(Rational r1) { Rational sum; sum.num = num*(r1.den) + den*(r1.num); sum.den = den * r1.den; return sum; } Rational Rational::Subtract(Rational r1) { Rational diff; diff.num = num*(r1.den) - den*(r1.num); diff.den = den * r1.den; return diff; } Rational Rational ::Multiply(Rational r1) { Rational prod; prod.num = num*(r1.num); prod.den = den * r1.den; return prod; } void Rational::printNum() { cout"/"
Third file
//Rational.h
#ifndef SUDCPPLAB10_RATIONAL_H #define SUDCPPLAB10_RATIONAL_H class Rational { private: int num; int den; public: Rational(); void setNumerator(int); void setDenominator(int); Rational Add(Rational r1); Rational Subtract(Rational r1); Rational Multiply(Rational r1); void printNum(); }; #endif //SUDCPPLAB10_RATIONAL_H
Create a class called Rational for performing arithmetic with fractions. 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 is declared. The constructor should contain default values in case no initializers are provided Provide public member functions that perform each of the following tasks: Adding two rational numbers. Subtracting two rational numbers. Print Rational numbers in the form a/b, where a is the numerator and b is the denominator The implementation of the class rational is divided in two steps: Part 1: Class Definition Implement the class definition for class Rational in a file called Rational.h. The class definition should contain only the prototypes of the member functions Rational, setNumerator, setDenominator, add, subtract, multiply and print. You also need to include the integer data members numerator and denominator. Determine if the functions and the data members should be private or public. You can find an example of the class definition for the class Time in the file Time.h - also available in Chapter 9.2 (page 379 of the Deitel book, ninth edition)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started