第一范文网 - 专业文章范例文档资料分享平台

《c++程序设计》谭浩强课后习题答案及解析 

来源:用户分享 时间:2025/5/29 4:19:06 本文由loading 分享 下载这篇文档手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:xxxxxxx或QQ:xxxxxx 处理(尽可能给您提供完整文档),感谢您的支持与谅解。

.

#include using namespace std; int main()

{ const int n=7;

int i,number,top,bott,mid,loca,a[n]; bool flag=true,sign; char c;

cout<<\ cin>>a[0]; i=1;

while(i>a[i];

if (a[i]>=a[i-1]) i++; else

cout<<\ }

cout<

{cout<<\ cin>>number; sign=false;

top=0; //top是查找区间的起始位置 bott=n-1; //bott是查找区间的最末位置

if ((numbera[n-1])) //要查的数不在查找区间 loca=-1; // 表示找不到 while ((!sign) && (top<=bott)) {mid=(bott+top)/2; if (number==a[mid]) {loca=mid;

cout<<\ sign=true; }

else if (number

top=mid+1; }

if(!sign||loca==-1)

cout<

.

.

cin>>c;

if (c=='N'||c=='n') flag=false; }

return 0; } 5.9题

#include using namespace std; int main()

{int sum_day(int,int); int leap(int year);

int year,month,day,days=0;

cout<<\ cin>>year>>month>>day;

cout<

days=sum_day(month,day); */

if(leap(year) && month>=3) */

days=days+1;

cout<<\ return 0; }

int sum_day(int month,int day) //计算日期 {int i;

int day_tab[12]={31,28,31,30,31,30,31,31,30,31,30,31}; for (i=0;i

}

int leap(int year) //判断是否为闰年 {int leap;

leap=year%4==0&&year0!=0||year@0==0; return(leap); }

5.10题

#include using namespace std; int main()

.

/* 调用函数一/* 调用函数二 .

{int i,j,upper,lower,digit,space,other; char text[3][80];

upper=lower=digit=space=other=0; for (i=0;i<3;i++)

{cout<<\ gets(text[i]);

for (j=0;j<80 && text[i][j]!='\\0';j++) {if (text[i][j]>='A'&& text[i][j]<='Z') upper++;

else if (text[i][j]>='a' && text[i][j]<='z') lower++;

else if (text[i][j]>='0' && text[i][j]<='9') digit++;

else if (text[i][j]==' ') space++; else

other++; } }

cout<<\ cout<<\ cout<<\ :\ cout<<\ :\ cout<<\ :\ return 0; }

5.11题

#include using namespace std; int main()

{ char a[5]={'*','*','*','*','*'}; int i,j,k;

char space=' ';

for (i=0;i<5;i++) // 输出5行

{ cout<

cout<

cout<

cout<

.

.

5.11题另一解

#include #include using namespace std; int main()

{ string stars=\ int i,j;

for (i=0;i<5;i++) // 输出5行

{ cout<<\ \ // 每行前面留4个空格 for (j=1;j<=i;j++)

cout<<\ // 每行再插入i个空格 cout<

5.12题

#include using namespace std; int main() {int j,n;

char ch[80],tran[80];

cout<<\ gets(ch);

cout<<\ j=0;

while (ch[j]!='\\0')

{ if ((ch[j]>='A') && (ch[j]<='Z')) tran[j]=155-ch[j];

else if ((ch[j]>='a') && (ch[j]<='z')) tran[j]=219-ch[j]; else

tran[j]=ch[j]; j++; } n=j;

cout<<\ for (j=0;j

.

.

using namespace std; int main() {int j,n;

char ch[80];

cout<<\ gets(ch);

cout<<\ j=0;

while (ch[j]!='\\0')

{ if ((ch[j]>='A') && (ch[j]<='Z')) ch[j]=155-ch[j];

else if ((ch[j]>='a') && (ch[j]<='z')) ch[j]=219-ch[j]; else

ch[j]=ch[j]; j++; } n=j;

cout<<\ for (j=0;j #include using namespace std; int main() {int j;

string ch=\ tran=ch;

cout<<\ j=0;

while (j<=ch.size())

{ if ((ch[j]>='A') && (ch[j]<='Z')) tran[j]=155-ch[j];

else if ((ch[j]>='a') && (ch[j]<='z')) tran[j]=219-ch[j]; else tran[j]=ch[j]; j++;

.

《c++程序设计》谭浩强课后习题答案及解析 .doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.diyifanwen.net/c4tr8n37guk79ew80o94h77xpo584e200qvv_7.html(转载请注明文章来源)
热门推荐
Copyright © 2012-2023 第一范文网 版权所有 免责声明 | 联系我们
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:xxxxxx 邮箱:xxxxxx@qq.com
渝ICP备2023013149号
Top