| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
为什么计算结果为 0 不能运行?哪位同仁帮帮忙看一下啊!#include<iostream>
using namespace std;
class A
{
public:
A(){}
void set() //读取数据
{
cin>>a>>ch1>>b>>ch2>>c>>ch3>>d;
}
void f() //加减计算
{
x=a*d+b*c;
y=b*d;
if(ch2=='-')
{
x=a*d-b*c;
y=b*d;
}
}
void display() //输出计算结果
{
m=x;
n=y;
if(m<n)
{
r=m;
m=n;
n=r;
}
while(m%n!=0) //求最大公约数
{
r=m%n;
m=n;
n=r;
}
//if(x==0)
//cout<<x<<endl;
if(x!=0)
{
if(x%y==0)
cout<<x/y<<endl;
else
cout<<x/n<<"/"<<y/n<<endl;
}
}
private:
int a,b,c,d;
int x,y;
int r,m,n;
char ch1,ch2,ch3;
};
int main()
{
A a1,a2,a3;
a1.set();
a1.f();
a1.display();
a2.set();
a2.f();
a2.display();
a3.set();
a3.f();
a3.display();
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator