⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sl310.cpp

📁 Visual C++ 的学习资料一
💻 CPP
字号:
// sl310.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "iostream.h"
namespace name
{
	class overflow {};
	class underflow {};
} 

const double PI=3.1415926;
using namespace name;

int main()
{
	int countarea(int n);
	int r;
	try
	{
		cout<<"输入一个1~7的整数:"<<"\n";
		cin >>r;
		double area;
		area = PI*r*r;
		cout<<"求半径为"<<countarea(r)<<"的圆面积:"<<"\n";
		cout<<"面积:area = "<<area<<"\n";
	}
	catch (overflow)
	{
		cout<<"发生上溢!"<<"\n";
	}
	catch (underflow)
	{
		cout<<"发生下溢!"<<"\n";
	}
	catch(...)
	{
		cout<<"发生意料之外的异常!"<<"\n";
	}
}

int countarea(int n)
{
	if(n<1)
	{
		throw underflow();
	}
	if(n>7)
	{
		throw overflow();
	}
	return n;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -