C++ Primer Plus 第六版课后编程答案 2.1-2.5

第一章没有习题


2.1

//p35  1

#include <iostream.h>
int main()
{
  cout<<"我的名字啊,这是个什么啊"<<endl;
  cout<<"我家住在黄土高坡\n";
  cin.get();
  return 0;    
    
    
}

2.2

// 2.2

#include <iostream.h>
int main()
{
 cout<<"输入一个以码为单位的距离\n";
 int n;
 cin>>n;
 //cout<<n;
 cout<<"转换之后啊,看看是多少啊:\n"<<n*220<<"码"<<endl; 
 cin.get();
 cin.get();
 return 0;    
    
    
}

2.3

//2.3

#include <iostream.h>

void myFuction1();
void myFuction2() ;

int main()
{
    using namespace std;
    myFuction1(); 
    myFuction1(); 
    myFuction2(); 
    myFuction2();
    cin.get();
    return 0; 
    
    
}

void myFuction1()
{
 cout<<"Three blind mice"<<endl;
 cout<<"Three blind mice"<<endl;      
}
void myFuction2()
{
cout<<"see how they run"<<endl; 
cout<<"see how they run"<<endl;      
     
}

2.4


//2.4 

#include <iostream.h>
int main()
{
     cout<<"请输入你的年龄"<<endl;
     int age;
     cin>>age;
     cout<<"你的年龄是:"<<age<<endl;
     cout<<"包含"<<age*12<<"个月"<<endl;
     cin.get();
     cin.get();
     return 0; 
    
    
}

2.5

//2.5
#include <iostream.h>

double change(double n);
int main()
{
     cout<<"please enter a Celsius valus:";
     double n;
     cin>>n;
     cout<<"\nyour valus is :"<<n<<endl;
     double now=change(n);
     cout<<"now is "<<now<<endl<<change(5.2);
     cin.get();
     cin.get();
     return 0;
    
    
}
double change(double n)
{
      
 return n*10;//这里的公式是错的,应该是return 1.8*n+32.0 才对  --2015/01/28       
       
       
}

不懂可以留言,这么简单应该都懂吧





  • 0
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 16
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 16
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值