C++程序设计原理与实践 第十一章部分答案

 1 #include "../../st.h"
 2 
 3 int main()
 4 try{
 5     string s1="a.txt";
 6     string s2="z.txt";
 7     ifstream ifs(s1.c_str());
 8     if(!ifs)
 9         error("can not open input file",s1);
10     ofstream ofs(s2.c_str());
11     if(!ofs)
12         error("can not open output file1",s2);
13     char ch;
14     while(ifs.get(ch))
15     {
16         if(isalpha(ch))
17             ch=tolower(ch);
18         ofs<<ch;
19     }
20     keep_window_open();
21 }
22 catch(exception&e){
23     cerr<<e.what()<<endl;
24     while(1);
25     return 1;
26 }
27 
28 catch(...){
29     cerr<<"exception\n";
30     while(1);
31     return 2;
32 }
33     
习题1
习题2
 1 int fn()
 2 {
 3     char c;
 4     cin>>c;
 5     if(c=='0')
 6     {
 7         char c1;
 8         cin>>c1;
 9         if(c1=='x')
10         {
11             cin.putback(c1);
12             cin.putback(c);
13             return 16;
14         }
15         else
16         {
17             cin.putback(c1);
18             cin.putback(c);
19             return 8;
20         }
21     }
22     else
23     {
24         cin.putback(c);
25         return 10;
26 
27     }
28 
29 }
30 
31 int main()
32 {
33     int i;
34     cin.unsetf(ios::hex);
35     cin.unsetf(ios::dec);
36     cin.unsetf(ios::oct);
37     cout<<showbase;
38     int p=fn();
39     cin>>i;
40     switch (p)
41     {
42     case 16:
43         cout<<hex<<i<<"  hexadecimal  converts to "<<dec<<i<<" decimal"<<endl;
44         break;
45     case 8:
46         cout<<oct<<i<<"  octmal  converts to "<<dec<<i<<" decimal"<<endl;
47         break;
48     case 10:
49         cout<<dec<<i<<" decimal  converts to "<<dec<<i<<" decimal"<<endl;
50         break;
51     default:
52         break;
53     }
54     while(1);
55     return 0;
56 
57 }
习题3
习题5 6
习题9 10
习题11

 习题14

<<scientific<<setprecision(8)<<setw(20)

用for控制域数  每四个一行

 

习题15

排序比较难  先存后排序  再计数

转载于:https://www.cnblogs.com/yueba/p/4088422.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值