#include<math.h>
#include<iostream>
using namespace std;
class SQRT{
private:
int num;
public:
double r;
SQRT(int i){
num=i;
r=(int)sqrt(i);
}
int getNum(){return num;}
void Show();
void In();
};
void SQRT::In(){
try{
cout<<"输入一个数:";
cin>>num;
if(num<0) throw num;
}
catch(int num){cout<<"* * * * *输 入 值 非 法 * * * * *"<<endl;}
}
void SQRT::Show(){
r=(int)sqrt(num);
cout<<num<<"的 平 方 根 为:";
cout<<r<<endl;
}
void main(){
SQRT s(16);
s.Show();
s.In();
s.Show();
}
编写一个程序,求输入数的平方根。设置异常处理,对输入负数的情况给出提示
最新推荐文章于 2023-03-21 10:05:15 发布