A problem that occurs with most high-level programming languages is that standar
ID: 3828870 • Letter: A
Question
Explanation / Answer
#include <iostream>
using namespace std;
class LargeInt
{
private:
long long number;
public:
LargeInt() //default constructor
{
number = 0;
}
LargeInt(long long number) //parameterized constructor
{
this->number = number;
}
~LargeInt() //destructor
{
cout<<"destructor"<<endl;
}
LargeInt(const LargeInt& obj) //copy constructor
{
number = obj.number;
}
const LargeInt& operator=(const LargeInt& obj)// overloaded assignment operator
{
number = obj.number;
return *this;
}
LargeInt operator+(LargeInt obj) //overloaded + operator
{
LargeInt temp;
temp.number = number +obj.number;
return temp;
}
void operator--(int) //decrement operator
{
number = number -1;
}
friend istream& operator>>(istream& is,LargeInt& obj)
{
is>>obj.number;
}
friend ostream& operator<<(ostream& os,LargeInt& obj)
{
os<<obj.number;
}
};
int main()
{
LargeInt l1(78568686);
cout<<"l1 ="<<l1;
LargeInt l2(45447485);
cout<<" l2 ="<<l2;
LargeInt l3(l2); //copy constructor
cout<<" l3="<<l3;
LargeInt l4 ;
l4 = l1 +l2;
cout<<"l1+l2 = "<<l4;
l4--;
cout<<" l4-- = "<<l4;
return 0;
}
output:
l1 =78568686 l2 =45447485 l3=45447485destructor
destructor
l1+l2 = 124016171 l4-- = 124016170destructor
destructor
destructor
destructor
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.