Code errors

"fraction.h"

#ifndef FRACTION_H
#define FRACTION_H

#include <QString>


class Fraction
{

public:

//Sets the numurator of the fraction and the denominator of the fraction which are stored as private integer variables
void setNumber(int numurator, int denominator);

//Converts the fraction to a decimal.
double toDouble();

//Returns the fraction as a QString
QString toString();

//Adds two fractions together and returns the result.
//Finds a lowest common denominator.
Fraction add(Fraction& other);

//Subtracts two fractions and returns the result
//Finds a lowest common denominator.
// Fraction subtract(Fraction& other);

//Multiplies two fractions together and returns the result
// Fraction multiply(Fraction &other);

//Divides two fractions and returns the result
// Fraction divide(Fraction &other);

private:
int m_Num;
int m_Den;
};


void Fraction::setNumber(int numurator, int denominator)
{
m_Num = numurator;
m_Den = denominator;
}

double Fraction::toDouble()
{
return 1.0 * m_Num / m_Den;
}

QString Fraction::toString()
{
return QString("%1 / %2").arg(m_Num).arg(m_Den);
}

FractionFraction::add(Fraction &other)
{
return Fraction((m_Num * other.m_Den) + (other.m_Num * m_Den)) , (m_Den * other.m_Den));
}

/*Fraction Fraction::subtract(Fraction &other)
{
return Fraction(((m_Num * other.m_Den) - (other.m_Num * m_Den)) , (m_Den * other.m_Den));
}

Fraction Fraction::multiply(Fraction &other)
{
return Fraction(m_Num * other.m_Num, m_Den * other.m_Den);
}

Fraction Fraction::divide(Fraction &other)
{
return Fraction(m_Num * other.m_Den, m_Den * other.m_Num);
}

*/
#endif // FRACTION_H






main.cpp

#include "fraction.h"

int main(int argc, char *argv[])
{
Fraction numbers;

numbers.setNumber(1, 5);

return 0;
}


My program is supposed to take two fractions and then add, subtract, multiply and divide them.

I am stuck and not sure about the errors I get and what they mean. I have tried googling but have not gotten very far.

Oh and I am not sure if I have included all the necessary Qt libraries required.

Please assist :)
Last edited on
And errors will be..?
I hope this helps. :-S

In file included from ../QuestionTwo/main.cpp:1:0:
../QuestionTwo/fraction.h:58:1: error: 'FractionFraction' does not name a type
../QuestionTwo/fraction.h: In member function 'Fraction Fraction::subtract(Fraction&)':
../QuestionTwo/fraction.h:65:92: error: no matching function for call to 'Fraction::Fraction(int, int)'
../QuestionTwo/fraction.h:65:92: note: candidates are:
../QuestionTwo/fraction.h:7:7: note: Fraction::Fraction()
../QuestionTwo/fraction.h:7:7: note: candidate expects 0 arguments, 2 provided
../QuestionTwo/fraction.h:7:7: note: Fraction::Fraction(const Fraction&)
../QuestionTwo/fraction.h:7:7: note: candidate expects 1 argument, 2 provided
../QuestionTwo/fraction.h: In member function 'Fraction Fraction::multiply(Fraction&)':
../QuestionTwo/fraction.h:70:60: error: no matching function for call to 'Fraction::Fraction(int, int)'
../QuestionTwo/fraction.h:70:60: note: candidates are:
../QuestionTwo/fraction.h:7:7: note: Fraction::Fraction()
../QuestionTwo/fraction.h:7:7: note: candidate expects 0 arguments, 2 provided
../QuestionTwo/fraction.h:7:7: note: Fraction::Fraction(const Fraction&)
../QuestionTwo/fraction.h:7:7: note: candidate expects 1 argument, 2 provided
../QuestionTwo/fraction.h: In member function 'Fraction Fraction::divide(Fraction&)':
../QuestionTwo/fraction.h:75:61: error: no matching function for call to 'Fraction::Fraction(int, int)'
../QuestionTwo/fraction.h:75:61: note: candidates are:
../QuestionTwo/fraction.h:7:7: note: Fraction::Fraction()
../QuestionTwo/fraction.h:7:7: note: candidate expects 0 arguments, 2 provided
../QuestionTwo/fraction.h:7:7: note: Fraction::Fraction(const Fraction&)
../QuestionTwo/fraction.h:7:7: note: candidate expects 1 argument, 2 provided
../QuestionTwo/main.cpp: In function 'int main(int, char**)':
../QuestionTwo/main.cpp:13:43: error: cannot call member function 'QString& QString::operator=(const QString&)' without object
../QuestionTwo/main.cpp:14:40: error: cannot call member function 'QString& QString::operator=(const QString&)' without object
../QuestionTwo/fraction.h: In member function 'Fraction Fraction::divide(Fraction&)':
../QuestionTwo/fraction.h:76:1: warning: control reaches end of non-void function [-Wreturn-type]
../QuestionTwo/fraction.h: In member function 'Fraction Fraction::multiply(Fraction&)':
../QuestionTwo/fraction.h:71:1: warning: control reaches end of non-void function [-Wreturn-type]
../QuestionTwo/fraction.h: In member function 'Fraction Fraction::subtract(Fraction&)':
../QuestionTwo/fraction.h:66:1: warning: control reaches end of non-void function [-Wreturn-type]
mingw32-make[1]: *** [debug/main.o] Error 1

I am extremely new to qt.
1. ../QuestionTwo/fraction.h:58:1: error: 'FractionFraction' does not name a type
Your type is Fraction not FractionFraction.
2. ../QuestionTwo/fraction.h:65:92: error: no matching function for call to 'Fraction::Fraction(int, int)'
You haven't defined such a Fraction constructor.
3. ...

Have a second look at the listed errors and try to find out how to solve them by yourself. This will really increase your power level!
Thanks for the initial help, will give it a shot.

Appreciate the pointers :D
Topic archived. No new replies allowed.