1613-3-傅溥衍 总结《2016年12月9日》【连续第七十天总结】

标题:模板和异常处理
关键词:异常处理
内容: 
A今日完成情况

1. 异常处理50%


B具体内容

#include<iostream>
#define MAX 200
#define MiN 100
using namespace std;
int data;
double div;
class except{
	char *message;
public:
	except(char * ptr){message = ptr;
	}
	const char *what(){return message;
	}
	virtual void handling(){
		cout<<"再次输入被除数";
		cin>>div;
			}
	void action(){
		cout<<"异常为"<<what()<<'\n';
		handling();
	}
};
class except_derive:public except{
	public:
		except_derive(char * ptr):except(ptr){
		}
		virtual void handling(){
			if(data>MAX)
			cout<<"启动数据转换,将数据减少至"<<(data/=2)<<endl;
			else
			cout<<"启动数据转换,将数据增加至"<<(data*=2)<<endl;
		}
};
double quotient(double m,double n){
	if(n==0)
	throw except("除数为0的错误抛出");
	return m/n;
}
int main()
{
	double n,result;
	int flag=1;
	char * mes_low={"数据太小 超出范围"};
	char * mes_high={"数据太大 超出范围"};
	cout<<"请输入转换数据";
	cin>>data;
	cout<<"请输入除数和被除数";
	cin>>n>>div;
	while(glag){
		try{
			if((data>MAX)||(data<MIN))
			throw except_derive((data>MAX)?(mes_high):(mes_low));
			result=quotient(n,div);
			cout<<"二数相除的结果为"<<result<<endl;
			flag=0;
		}
		catch(except_derive ex){ex.action();
		}
		catch(except ex){ex.action();
		}
	}
}




C明日计划

A 异常处理


C明日计划

A 异常处理

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值