《c++程序设计》谭浩强 答案 - 第05章(2)

2019-04-22 19:40

}

else if (number

top=mid+1; }

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

cout<>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++; }

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

string ch=\ cout<<\ j=0;

while (j<=ch.size())

{ 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]; j++; }

cout<<\ cout< #include using namespace std; int main()


《c++程序设计》谭浩强 答案 - 第05章(2).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:技术管理办法27

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

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