C++编程设计两个重载函数,分别求两个整数相除的余数和两个实数相除的余数.两个实数求余定义为实数四舍五
来源:学生作业帮 编辑:大师作文网作业帮 分类:综合作业 时间:2024/11/12 11:03:54
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;
}
C++编程设计两个重载函数,分别求两个整数相除的余数和两个实数相除的余数.两个实数求余定义为实数四舍五
4、设计两个重载函数,分别求两个整数相除的余数和两个实数相除的余数.两个实数求余定义为实数四舍五入取整后相除的余数.
编写三个名为add的重载函数,分别实现两个整数、两个实数和两个复数相加
l两个数相除商47余8,这两个数加商和余数的和是972求这两个数.
两个数相除,商3余10,被除数,除数,商与余数的和是143,求被除数是多少
两个自然数相除,商15,余3,被除数.除数.商.余数的和是853,求被除数.
C语言:输入两个整数,求它们相除的余数,用带参的宏来实现编程序.
编写函数,得到两个整数相除的商和余数.要求通过指针在函数间传递商和余数这两个
两个整数相除,商是5,余数是11,被除数、除数、商及余数的和是99,求被除数和除数.
两个整数相除,商是12,余数是26,被除数、除数、商与余数的和是454,求除数和被除数各是______、______.
两个整数相除,商17,余数是8,已知被除数、除数、商、余数的和是501,求被除数和除数
两个整数相除,商17,余数是8,已知被除数、除数、商、余数的和是501,求被除数和除数(用方程解)