C++编程设计两个重载函数,分别求两个整数相除的余数和两个实数相除的余数。两个实数求余定义为实数四舍五
展开全部
#include <iostream.h>
class digital
{
private:
int m_num;
public:
digital(int num=0)
{
this->m_num=num;
}
~digital(){};
int GetNum()
{
return m_num;
}
digital operator + (digital x)
{
digital y;
y.m_num=this->m_num+x.m_num;
return y;
}
digital operator * (digital x)
{
digital y;
y.m_num=this->m_num*x.m_num;
return y;
}
digital operator / (digital x)
{
digital y;
y.m_num=this->m_num / x.m_num;
return y;
}
digital operator - (digital x)
{
digital y;
y.m_num = this->m_num - x.m_num;
return y;
}
};
void main()
{
digital a(3);
digital b(3);
cout<<(a+b).GetNum()<<endl;
cout<<(a*b).GetNum()<<endl;
cout<<(a/b).GetNum()<<endl;
cout<<(a-b).GetNum()<<endl;
}
class digital
{
private:
int m_num;
public:
digital(int num=0)
{
this->m_num=num;
}
~digital(){};
int GetNum()
{
return m_num;
}
digital operator + (digital x)
{
digital y;
y.m_num=this->m_num+x.m_num;
return y;
}
digital operator * (digital x)
{
digital y;
y.m_num=this->m_num*x.m_num;
return y;
}
digital operator / (digital x)
{
digital y;
y.m_num=this->m_num / x.m_num;
return y;
}
digital operator - (digital x)
{
digital y;
y.m_num = this->m_num - x.m_num;
return y;
}
};
void main()
{
digital a(3);
digital b(3);
cout<<(a+b).GetNum()<<endl;
cout<<(a*b).GetNum()<<endl;
cout<<(a/b).GetNum()<<endl;
cout<<(a-b).GetNum()<<endl;
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询