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 and should store the fraction in reduced form. For example, the
fraction 2/4 should be stored in the object as 1 in the numerator and 2 in
the denominator. Provide public member functions that perform each of the
following tasks:
Adding two Rational numbers. The result should be stored in reduced
form.
b) Subtracting two Rational numbers. The result should be stored in
reduced form.
c) Multiplying two Rational numbers. The result should be stored in
reduced form.
d) Dividing two Rational numbers. The result should be stored in reduced
form.
e) Printing Rational numbers in the form a/b, where a is numerator and b
is denominator.
f) Printing Rational numbers in floating-point format.
ok i dont seem to understand why i keep getting the same error, someone please help me, its due monday :( it keeps saying error C2470: 'Fraction' : looks like a function definition, but there is no parameter list; skipping apparent body
//this is the header file
#include <iostream>
#include <fstream>
using namespace std;
class Fraction
{
public:
Fraction(void);
Fraction(int n, int d);
void plus(Fraction second);
void minus(Fraction second);
void times(Fraction second);
void divide(Fraction second);
void reduce();
double todecimal();
void scan(istream& in);
void print(ostream& out);
~Fraction();
private:
int num,den;
};
// The cpp file
#include "Fraction.h"
Fraction::Fraction()
{
num=0;
den=1;
}
Fraction::Fraction(int n, int d){
num=n;
den=d;
}
void Fraction:plus(Fraction second){
int tempden= den*second.den;
num=num*second.den + den*second.num;
den=tempden;
}
void Fraction::minus(Fraction second){
int tempden= den*second.den;
num=num*second.den - den*second.num;
den = tempden;}
void Fraction::times(Fraction second){
num = num*second.num;
den=second.den*den;
}
void Fraction::divide(Fraction second){
num = num*second.den;
den= den*second.num;
}
void Fraction::scan(istream & in){
char slash;
in >> num >> slash >> den;
}
void Fraction:print(ostream & out){
out << num <<" / " << den;}
double Fraction::todecimal()
{double dec;
dec=(num*1.00)/(den*1.00);
return dec;
}
void Fraction::reduce()
{
}
Fraction::~Fraction()
{
}
//program file
#include "Fraction.h"
using namespace std;
int main(){
Fraction first;
Fraction d(1,2);
cout << " Fraction class menu" << endl;
cout << " " << endl;
cout << " Please enter fraction in form of 1/2"<<endl;
first.scan(cin);
cout << " What would you like to do ? (fraction will automatically be reduced and given in decimals)"<< endl;
cout << "1. plus" << endl;
cout << "2. minus" << endl;
cout << "3. times"<<endl;
cout << "4. divide"<<endl;
cout << " Make your choice now" << endl;
int choice;
cin >> choice;
switch (choice)
{
case 1: {
cout << "Enter a second fraction to be added to";
d.scan(cin);
first.plus(d);
first.reduce();
cout << endl;
first.print(cout);
cout << endl << "Decimal is " << first.todecimal();
break;}
case 2: {
cout << " Enter a second fraction to be subtracted from";
d.scan(cin);
first.minus(d);
first.reduce();
cout << endl;
first.print(cout);
cout << endl << "Decimal is " << first.todecimal();
break;}
case 3: {
cout << "Enter a second fraction to be timed by" << endl;
d.scan(cin);
first.times(d);
first.reduce();
cout << endl;
first.print(cout);
cout << endl << "Decimal is " << first.todecimal();
break;}
case 4:{ cout << "Enter a second fraction to be divided by" <<endl;
d.scan(cin);
first.divide(d);
first.reduce();
cout << endl;
first.print(cout);
cout << endl << "Decimal is " << first.todecimal();
break;}
default: cout << "ERROR : Menu Choice";
break;
}
}