Hi I'm doing an assignment on Rational Number calculations.

I'm getting some compiling errors which I don't know how to fix.

Here is the error message and the code is beneath the error message.
I would really appreciate if someone could read over this and see if you know whats wrong.

Thanks
Gudmundur.


1>------ Build started: Project: Dæmatími 7, Configuration: Debug Win32 ------
1> Assignment 7.cpp
1>c:\program files\microsoft visual studio 10.0\vc\include\istream(860): error C2248: 'std::basic_ios<_Elem,_Traits>::basic_ios' : cannot access private member declared in class 'std::basic_ios<_Elem,_Traits>'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\ios(176) : see declaration of 'std::basic_ios<_Elem,_Traits>::basic_ios'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> This diagnostic occurred in the compiler generated function 'std::basic_istream<_Elem,_Traits>::basic_istream(const std::basic_istream<_Elem,_Traits> &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

#include <iostream>
#include <string>
#include <istream>
#include <fstream>
using namespace std;


class RationalNumber
{
private:

    int numberator;
    int denominator;

public:

    RationalNumber();
    RationalNumber(int a);
    RationalNumber(int a, int b);

    RationalNumber add(RationalNumber rnum);
    RationalNumber sub(RationalNumber rnum);
    RationalNumber mul(RationalNumber rnum);
    RationalNumber div(RationalNumber rnum);
    RationalNumber neg();
    int less(RationalNumber rnum);

    int getNumberator();
    int getDenominator();
    void set(int numer, int denomi);
    void input(istream in);

};
void writeOutput(string s, RationalNumber rnum, ostream &ostr);
void openFiles(ifstream& fin, ofstream& fout);
void closeFiles(ifstream& fin, ofstream& fout);

int main()
{
    RationalNumber rnum1(2,3), rnum2(1,2), rnum3(2);
    RationalNumber rnum4, rnum5, rnum6, result;
    ifstream fin;
    ofstream fout;
    openFiles(fin, fout);
    writeOutput("First rational number: ", rnum1, cout);
    writeOutput("Second rational number: ", rnum2, cout);
    result = rnum1.add(rnum2);
    writeOutput("First + second: ", result, cout);


    result = rnum1.sub(rnum2);
    writeOutput("First - second: ", result, cout);
    result = rnum1.mul(rnum2);
    writeOutput("First * second: ", result, cout);
    result = rnum1.div(rnum2);
    writeOutput("First / second: ", result, cout);
    writeOutput("Third rational number: ", rnum3, cout);
    writeOutput("Fourth rational number: ", rnum4, cout);
    cout << "Input the integer numbers respresenting a rational number: ";
    rnum3.input(cin);
    writeOutput("Third rational number is now: ", rnum3, cout);
    writeOutput("Third rational number is now: ", rnum3, fout);
    cout << "Now reading two rational numbers from the input file ..." << endl;
    rnum4.input(fin);
    rnum5.input(fin);
    writeOutput("Fourth rational number: ", rnum4, cout);
    writeOutput("Fifth rational number: ", rnum5, cout);
    if (rnum4.less(rnum5))
        cout << "The fourth is less than the fifth" << endl;
    else
        cout << "The fourth is greater or equal to the fifth" << endl;
    result = rnum5.neg();
    writeOutput("Fifth rational number negated: ", result, cout);
    writeOutput("Fifth rational number negated: ", result, fout);
    cout << "Now setting the sixth rational number ..." << endl;
    rnum6.set(4,8);
    writeOutput("Sixth rational number is: ", rnum6, cout);
    cout << "The numerator of the sixth rational number is: " << rnum6.getNumberator() <<
         endl;
    closeFiles(fin,fout);
}

RationalNumber::RationalNumber()
{
    this->numberator = 0;
    this->denominator = 0;
}
RationalNumber::RationalNumber(int a)
{
    this->numberator = a;
    this->denominator = 1;
}
RationalNumber::RationalNumber(int a, int b)
{
    this->numberator = a;
    this->denominator = b;

}
int RationalNumber::getNumberator()
{
    return this->numberator;
}

int RationalNumber::getDenominator()
{
    return this->denominator;
}

void RationalNumber::set(int numer, int denomi)
{
    this->numberator = numer;
    this->denominator = denomi;
}

RationalNumber RationalNumber::add(RationalNumber rnum)
{
    RationalNumber temp;

    temp.set(this->numberator * rnum.getDenominator() + this->denominator * rnum.getNumberator(),
             this->denominator * rnum.getDenominator());

    return temp;
}
RationalNumber RationalNumber::sub(RationalNumber rnum)
{
    RationalNumber temp;

    temp.set(this->numberator * rnum.getDenominator() - this->denominator * rnum.getNumberator(),
             this->denominator * rnum.getDenominator());

    return temp;

}
RationalNumber RationalNumber::mul(RationalNumber rnum)
{
    RationalNumber temp;

    temp.set(this->numberator * rnum.getDenominator(),
             this->denominator * rnum.getDenominator());

    return temp;
}
RationalNumber RationalNumber::div(RationalNumber rnum)
{
    RationalNumber temp;

    temp.set(this->numberator * rnum.getDenominator(),
             rnum.getNumberator() * this->denominator);

    return temp;
}
RationalNumber RationalNumber::neg()
{
    RationalNumber temp;

    temp.set(this->numberator - this->numberator - this->numberator,
             this->denominator - this->denominator - this->denominator);
    return temp;

}
int RationalNumber::less(RationalNumber a)
{
    RationalNumber temp;
}
void RationalNumber::input(istream in)
{
    int a, b;
    in >> a;
    in >> b;
    this->numberator = a;
    this->denominator = b;
}
void openFiles(ifstream& fin, ofstream& fout)
{
    fin.open("input.dat");
    fout.open("output.dat");
}
void closeFiles(ifstream& fin, ofstream& fout)
{
    fin.close();
    fout.close();
}
void writeOutput(string s, RationalNumber rnum, ostream &ostr)
{
    ostr << s << " " << rnum.getNumberator() << "/" << rnum.getDenominator() << endl;
}

Its fixed :).

-.- you can not copy IO object in line 31

Thanks :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.