Question
please fix the code c++: (Don't change QT classes) #include #include QTextStream cout(stdout); QTextStream cin(stdin); class Fraction { private : int m_Numberator; int m_Denominator; public
please fix the code c++: (Don't change QT classes)
#include
#include
QTextStream cout(stdout);
QTextStream cin(stdin);
class Fraction {
private:
int m_Numberator;
int m_Denominator;
public:
Fraction() {
set(m_Numberator,m_Denominator);
}
void set(int numerator, int denominator) {
m_Numberator = numerator;
m_Denominator = denominator;
}
Fraction add(Fraction& other) {
Fraction temp;
temp.m_Denominator=m_Denominator+other.m_Denominator;
temp.m_Numberator=m_Numberator+other.m_Denominator;
return temp;
}
Fraction substact(Fraction& other){
Fraction temp;
temp.m_Denominator=m_Denominator-other.m_Denominator;
temp.m_Numberator=m_Numberator-other.m_Denominator;
return temp;
}
Fraction multiply(Fraction& other){
Fraction temp;
temp.m_Denominator=m_Denominator*other.m_Denominator;
temp.m_Numberator=m_Numberator*other.m_Denominator;
return temp;
}
Fraction divide(Fraction& other){
Fraction temp;
temp.m_Denominator= m_Denominator/other.m_Denominator;
temp.m_Numberator=m_Numberator/other.m_Denominator;
return temp;
}
double toDouble() {
return double (m_Denominator);
}
QString toString() {
return QString("This is the numberator This is the Denominator This is divition This is multiply This is substraction This is addition ").arg(m_Numberator).arg(m_Denominator).arg(m_Numberator/m_Denominator).arg(m_Numberator*m_Denominator).arg(m_Numberator-m_Denominator).arg(m_Numberator+m_Denominator);
}
};
int main()
{
Fraction f;
Fraction f2;
Fraction c;
f.set(3, 2);
f2.set(6, 9);
c = f.add(f2);
cout<< f.toString() << endl;
cout<< c.toString() << endl;
}
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