problem 5.8(Example)
#include<bits/stdc++.h>
using namespace std;
class item
{
int a,b;
public :
void get(int x,int y)
{
a=x;
b=y;
}
double friend mean(item it);
};
double mean(item it)
{
try
{
int r;
r=it.a-it.b;
if(r==0)throw 0;
}
catch(int x)
{
cout<<"cant not divide by zero\n";
return 0.0;
}
return (it.a+it.b)/2.0;
}
int main()
{
item i;
ifstream in;
in.open("input.txt");
int p,q;
in>>p>>q;
i.get(p,q);
in.close();
cout<<mean(i)<<endl;
return 0;
}
0 Comments