Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

image text in transcribed

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 #include "Rational.h" //main.cpp is testRational.cpp (the file in the question) using namespace std; int main() { Rational r1,r2; r1.setNumerator(1); r1.setDenominator(2); r2.setNumerator(2); r2.setDenominator(3); r1.Add(r2); r1.Subtract(r2); r1.Multiply(r2); r1.printNum(); return 0; }?

//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

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_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

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

Get Started

Students also viewed these Databases questions

Question

Determine whether the number is rational or irrational. 5/8

Answered: 1 week ago

Question

Does it use a maximum of two typefaces or fonts?

Answered: 1 week ago