C++Primer中文版(第四版)题解整理(21)

时间:2025-04-20

C++Primer题解

参见2.9.1节。

习题2.33

确定你的编译器提供了哪些提高警告级别的选项。使用这些选项重新编译以前选择的程序,查看是否会报告新的问题。

【解答】

在笔者所用的编译器(MicrosoftVisualC++.NET2003)中,在Project菜单中选择Properties菜单项,在Configuration

Properties→C/C++→General→WarningLevel中可以选择警告级别。习题3.1

用适当的using声明,而不用std::前缀,访问标准库中的名字,重新编写2.3节的程序,计算一给定数的给定次幂的结果。

#include<iostream>

#include"windows.h"

usingnamespacestd;

intmain()

{

intbase,exponent;

longresult=1;

system("CLS");

cout<<"Enterbaseandexponent:"<<endl;

cin>>base>>exponent;

if(exponent<0)

{

cout<<"Exponentcan'tbesmallerthan0"<<endl;

return-1;

}

if(exponent>0)

{

for(intcnt=1;cnt<=exponent;cnt++)

result*=base;

}

cout<<base<<"raisedtothepowerof"<<exponent<<":

"<<result<<endl;

return0;

}

C++Primer中文版(第四版)题解整理(21).doc 将本文的Word文档下载到电脑

精彩图片

热门精选

大家正在看

× 游客快捷下载通道(下载后可以自由复制和排版)

限时特价:7 元/份 原价:20元

支付方式:

开通VIP包月会员 特价:29元/月

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:fanwen365 QQ:370150219