C++编程

ynbaiye 2015-03-04 03:33:57
第六章编程练习
1、
#include <iostream>
#include <cctype>

int main()
{
using namespace std;

char ch;
cin.get(ch);

while(ch!='@')
{
if(isdigit(ch))
cin.get(ch);
else
{
if(islower(ch))
ch=toupper(ch);
else
ch=tolower(ch);
cout<<ch;
cin.get(ch);
}
}
system("pause");
return 0;
}


2、
#include <iostream>

int main()
{
using namespace std;

double sum=0;
double average=0;
double num[10];
int i=0,total=0;

double tmp;

while(cin>>tmp&&i<10)
{
num[i]=tmp;
sum+=num[i];
++i;
}

if(i!=0)
average=sum/i;

for(int j=0;j<i;++j)
if(num[j]>average)
++total;

cout<<"这些数字的平均值为"<<average<<endl;
cout<<"并且共有"<<total<<"个数字大于平均值。\n";

system("pause");
return 0;
}


3、
#include <iostream>

int main()
{
using namespace std;

cout<<"Please enter one of the following choices:\n"
<<"c)carnivore p)pianist\n"
<<"t)tree g)game\nf\n";

cout<<"Please enter a c, p, t, or g: ";

char ch;
cin>>ch;

while(ch!='c'&&ch!='p'&&ch!='t'&&ch!='g')
{
cout<<"Please enter a c, p, t, or g: ";
cin>>ch;
}

switch(ch)
{
case 'c':
cout<<"A maple is a tree.\n";
break;
case 'p':
cout<<"A maple is a pianist.\n";
break;
case 't':
cout<<"A maple is a tree.\n";
break;
case 'g':
cout<<"A maple is a game.\n";
}

system("pause");
return 0;
}
...全文
325 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
yan597478677 2015-03-05
  • 打赏
  • 举报
回复
楼主是想问什么啊?

1,317

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder 网络及通讯开发
社区管理员
  • 网络及通讯开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧