zoukankan      html  css  js  c++  java
  • 第十六周 项目一-平方根中的异常

    /*
     * Copyright (c) 2014, 烟台大学计算机学院
     * All rights reserved.
     * 文件名:test.cpp
     * 作    者:冷基栋  
     * 版 本 号:v1.0
     * 完毕日期:2015年 6 月 27日
     * 问题描写叙述:
     * 输入描写叙述:编写一个程序,求输入数的平方根。设置异常处理。当输入负数时採用异常处理机制给出提示。
     * 程序输出:
     */
    #include<iostream>
    #include<cmath>
    using namespace std;
    double squart(int &x);
    int main()
    {
        int n;
        try
        {
                cout<<"请输入一个数:"<<endl;
                cin>>n;
                cout<<n<<"的平方根为"<<squart(n)<<endl<<endl;
        }
        catch(int)
        {
            cout<<"无法开方!

    "<<endl<<endl; } return 0; } double squart(int &x) { double n; if(x>=0) n=sqrt(x); else throw x; return n; }


    执行结果:

    学习心得:

    自上而下

  • 相关阅读:
    FirstThunk
    FirstThunk
    输入地址表(IAT)
    PE文件讲解
    PE格式详细讲解
    pe结构讲解
    PE格式详细讲解
    输入地址表(IAT)
    pe结构讲解
    zindex可以使用负值
  • 原文地址:https://www.cnblogs.com/lytwajue/p/6786241.html
Copyright © 2011-2022 走看看