在线等:C++编程问题求教,谢谢
#include<iostream>
using namespace std;
/**********Program**********/
?????????
????????
/********** End **********/
int main(){
int i,j;
cout<<"请输入两个整数:"<<endl;
cin>>i>>j;
MaxMin A(i,j);
cout<<"最大公约数:"<<A.MaxCommonDevisor()
<<'\t'<<"最小公倍数:"<<A.MinCommonMultiple( )<<endl;
return 0;
}
问号区域填什么?? 展开
#include<iostream>
using namespace std;
/**********Program**********/
class MaxMin
{
private :
int a,b;
public:
int MaxCommonDevisor();
int MinCommonMultiple();
MaxMin(int a1,int b1);
};
MaxMin::MaxMin (int a1,int b1)
{
a=a1;
b=b1;
}
int MaxMin::MaxCommonDevisor()
{
int t;
if(a>b) {t=a;a=b;b=t;}
for(int i=a;i>=1;i--)
if((a%i==0)&&(b%i==0))
return i;
}
int MaxMin::MinCommonMultiple()
{
return a*b/MaxCommonDevisor();
}
/********** End **********/
int main()
{
int i,j;
cout<<"请输入两个整数:"<<endl;
cin>>i>>j;
MaxMin A(i,j);
cout<<"最大公约数:"<<A.MaxCommonDevisor()
<<'\t'<<"最小公倍数:"<<A.MinCommonMultiple()<<endl;
return 0;
}
还有不懂可以追问
{
private:
int firstNum,secondNum;
publc:
MaxMin(int x ,int y)
{
firstNum=x;
secondNum=y;
}
int MaxCommonDevisor()
{
int m = 1;
for(int i=firstNum/2;i>0;i--)
{
if(firstNum%m==0&&secondNum%m==0)
return i;
}
}
int MinCommonMultiple()
{
int m = 1;
for(int i=firstNum>secondNum?firstNum:secondNum;i<=firstNum*secondNum;i++)
{
if(i%secondNum==0&&i%firstNum==0)
return i;
}
}
};
class Middle个问题了,这是刚才那个问题的代码,这个问题的我再给你写
{
private:
int x,y,z;
public:
Middle(int x,int y,int z)
{
this->x = x;
this->y = y;
this->z = z;
}
int median()
{
if (x>y)
{
if (z>y)
{
return x>z ? z : x;
}
else
{
return y;
}
}
else
{
if (z>y)
{
return y;
}
else
{
return x>z ? x : z;
}
}
}
};
#include<iostream>
using namespace std;
/**********Program**********/
// ?????????
// ????????
//
class MaxMin
{
public:
MaxMin(int arg1, int arg2)
{
int arg1_abs = arg1 < 0 ? -1 * arg1 : arg1;
int arg2_abs = arg2 < 0 ? -1 * arg2 : arg2;
if( arg1_abs > arg2_abs ){
m_max = arg1;
m_min = arg2;
m_max_abs = arg1_abs;
m_min_abs = arg2_abs;
}else{
m_max = arg2;
m_min = arg1;
m_max_abs = arg2_abs;
m_min_abs = arg1_abs;
}
}
int MaxCommonDevisor( void )
{
int val = 0;
for( val = m_min_abs ; val > 0 ; val -- ){
if( (m_max%val)==0 && (m_max%val)==0 ){
break;
}
}
return val;
}
int MinCommonMultiple( void )
{
int val = 0;
for( val = m_min_abs; val <= m_max_abs*m_min_abs; val ++ ){
if( (val%m_max)==0 && (val%m_min)==0 ){
break;
}
}
return val;
}
private:
int m_max;
int m_min;
int m_max_abs;
int m_min_abs;
};
/********** End **********/
int main(){
int i,j;
cout<<"请输入两个整数:"<<endl;
cin>>i>>j;
MaxMin A(i,j);
cout<<"最大公约数:"<<A.MaxCommonDevisor()
<<'\t'<<"最小公倍数:"<<A.MinCommonMultiple( )<<endl;
return 0;
}
// 问号区域填什么??