I am doing a small assignement that has one class with two private members.....numerator and denominator. The question asks to make three overloaded constructors, some have arguements while one does not example .....fraction()
now the deconstructor is basically has to print out the two private members now this works great but when it prints out the values for the contructors with no aruguements it gives the wierd print out of
numerator: -8388484
denominator: -3883489 and so on. If you make three overloaded constructors, do you make three deconstructors tailored to each of the constructors??????
the constructor that has no arguements does not do anything as per the code below, you just call it up but don't assign anything on it.
Help???????
#include <iostream.h>
class fraction
{
private:
int numerator;
int denominator;
public:
fraction(void) { cout<<"constructor\n";}
fraction(int x);
fraction(int x, int y);
~fraction();
fraction operator * (fraction);
};
fraction::fraction(int x)
{
numerator = x;
denominator = 1;
cout << "single constructor\n";
}
fraction::fraction(int x, int y)
{
numerator = x;
denominator =y;
cout << "double constructor\n";
}
fraction::~fraction()
{
cout << "the numerator is " << numerator;
cout << "\nthe denominator is " << denominator;
cout << "\ndeconstructor\n";
}
fraction fraction::operator * (fraction a)
{
fraction temp(0,0);
temp.numerator= numerator * a.numerator;
temp.denominator = denominator * a.denominator;
return temp;
}
//Question 2 main
//void main(void)
//{
// fraction one(3,5), two(5,2), three;
// three = one * two;
//}
//Question 1 main
void main(void)
{
fraction one(3,5), two(5,2), three, four(4);
}