How can I complete this code succesfully?I just need to add RationalSet.cpp files code . Could someone help me ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How can I complete this code succesfully?I just need to add RationalSet.cpp files code . Could someone help me ?

//This is my main.cpp file #include<iostream> #include "RationalSet.h" using namespace std; int main() { RationalSet rs; int x, y; cin>>x>>y; Rational x1(x, y); cin>>x>>y; Rational x2(x, y); cin>>x>>y;; Rational x3(x, y); cin>>x>>y; Rational x4(x, y); cin>>x>>y; Rational x5(x, y); cin>>x>>y; Rational x6(x, y); cin>>x>>y; Rational x7(x, y); cin>>x>>y; Rational x8(x, y); cout<<"Initial RationalSet"<<endl; rs.print(); cout<<"RationalSet after insertion"<<endl; rs.insert(x1); rs.insert(x2); rs.insert(x3); rs.insert(x4); rs.insert(x5); rs.print(); cout<<"RationalSet after first element deleted"<<endl; rs.delete_rational(x6); rs.print(); cout<<"RationalSet after second element deleted"<<endl; rs.delete_rational(x7); rs.print(); cout<<"RationalSet after insertion"<<endl; rs.insert(x8); rs.print(); return 0; }

10th Apr 2019, 6:56 PM
Nurullah Aydın
Nurullah Aydın - avatar
3 Answers
0
//This is my Rational.h file #include<iostream> using namespace std; class Rational{ public: Rational(int a=0,int b=0){ x=a; y=b; } void setX(int a){ x=a; } void setY(int b){ y=b; } int getX(){ return x; } int getY(){ return y; } void print() { cout<<x<<"/"<<y<<endl; } private: int x,y; };
10th Apr 2019, 6:56 PM
Nurullah Aydın
Nurullah Aydın - avatar
0
//This is my RationalSet.h file #include<iostream> #include"Rational.h" using namespace std; class RationalSet{ public: RationalSet(); void insert(Rational r1); void delete_rational(Rational r1); int search(Rational r1); Rational reduce(Rational r1); int size(); void print(){ int s=size(); if(s==0) cout<<"empty set"<<endl; for(int i=0; i<s; i++){ r[i].print(); } } private: Rational r[10]; };
10th Apr 2019, 6:57 PM
Nurullah Aydın
Nurullah Aydın - avatar
0
//This explonation tell the what I want to do... Define a RationalSet class. This class stores an array of objects, that belong to Rational class, as private data member. The size of the array is 10. The constructor for the Rational class should take the x and y values as input. Rational class should have set/get functions for both of x and y private data members and a print function that prints the values of the rational number on the screen. The RationalSet class should contain a constructor and 6 member functions. The definitions of the functions are as follow:  insert function should take a Rational object as input and store it into the first appropriate position of the array. Before placing the element, it should check whether the equivalent Rational object is present in the array. If reduced forms of Rational objects are same, these Rational objects are called as equivalent. - delete_rational function should take a Rational object and delete it from the array. - search function should take a Rational object as input and return the index of the Rational object (if there is no such Rational object in the array, it should return -1). If equivalent Rational object is present in the array, search function should return the index of the equivalent object. - size function should return the number of elements in the array. - reduce function should reduce a rational number by dividing the numerator and denominator by their greatest common divisor. - print function should call the Rational objects' print function to print the values of the rational number in the array to the screen.
10th Apr 2019, 7:01 PM
Nurullah Aydın
Nurullah Aydın - avatar