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

 1 #include <iostream>
 2 using namespace std;
 3
 4 void to_lower(char* s)
 5 {
 6     while(*s!=‘\0‘)
 7     {
 8         if(*s>=‘A‘&&*s<=‘Z‘)
 9             *s+=32;
10         s++;
11     }
12 }
13
14 char* strdup1(const char*s)
15 {
16     char *p=new char[];
17     cout<<sizeof(s)<<endl;               //////////注意
18     int i;
19     for(i=0;s[i]!=‘\0‘;i++)
20     {
21         p[i]=s[i];
22     }
23     p[i]=‘\0‘;
24     return p;
25 }
26
27 char* findx(const char*s,const char*x)
28 {
29     int i=0;
30     while(*s!=‘\0‘)
31     {
32         while(*(s+i)==*(x+i)&&*(x+i)!=‘\0‘)
33         {
34             i++;
35         }
36         if(*(x+i)==‘\0‘)
37             return (char*)s;
38         else
39             i=0;
40         s++;
41     }
42     return NULL;
43 }
44
45 int main()
46 {
47     //char c[]="D";
48     //cout<<sizeof(&c)<<endl;          //////////注意
49     //char *p=strdup1(c);
50 //    cout<<p<<endl;
51     char c1[]="fgasdfghj";
52     char c2[]="fgh";
53     cout<<findx(c1,c2);
54     while(1);
55     return 0;
56
57 }

习题3 4 5

习题10

习题11

习题14

习题12     应用与其他函数参数若是const Link&的话需用后者,因为后者已声明它不改变原有的值  P200  P377

时间: 2024-12-18 19:10:42

C++程序设计原理与实践 第十七章部分答案的相关文章

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

1 #include<stdio.h> 2 #include<stdlib.h> 3 #include<assert.h> 4 5 6 struct List 7 { 8 struct Link*first; 9 struct Link*last; 10 }; 11 12 struct Link 13 { 14 struct Link*pre; 15 struct Link*suc; 16 }; 17 18 void init(struct List*lst) 19 {

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

1 #include <iostream> 2 #include <vector> 3 #include <string> 4 #include <list> 5 #include<fstream> 6 #include <set> 7 #include<algorithm> 8 #include<stdexcept> 9 #include <map> 10 #include<boost/re

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

1 #include "../../st.h" 2 3 int main() 4 { 5 vector<double> nums; 6 double t; 7 int n; 8 cout<<"input how many nums: "; 9 cin>>n; 10 cin>>t; 11 nums.push_back(t); 12 int i=0; 13 while(cin>>t) 14 { 15 if(i&

c++程序设计原理与实践 第四章部分答案

1 #include <iostream> 2 using namespace std; 3 4 int main() 5 { 6 int a=1,b=100; 7 int f=1; 8 char c=0; 9 10 while(f<=7 && (b-a)>=1) 11 { 12 cout<<"你的数小等于"<<(a+b)/2<<"吗?(y/n)"; 13 cin>>c; 14

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

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

1 #include <iostream> 2 #include <vector> 3 #include <string> 4 #include <list> 5 #include<fstream> 6 #include<algorithm> 7 #include<stdexcept> 8 using namespace std; 9 10 struct Item 11 { 12 string name; 13 int i

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

1 int strcmp1(const char* s1,const char*s2) 2 { 3 int i=0; 4 cout<<strlen(s1)<<endl; 5 while(*(s1+i)==*(s2+i)) 6 { 7 if(*(s1+i)=='\0') 8 return 0; 9 else 10 i++; 11 } 12 return *(s1+i)-*(s2+i); 13 //return((*(unsignedchar*)(s1+i)<*(unsigned

编码原则实例------c++程序设计原理与实践(进阶篇)

编码原则: 一般原则 预处理原则 命名和布局原则 类原则 函数和表达式原则 硬实时原则 关键系统原则 (硬实时原则.关键系统原则仅用于硬实时和关键系统程序设计) (严格原则都用一个大写字母R及其编号标识,而推荐原则都用小写字母r及其编号标识,对于前者程序员必须严格遵守,而后者则偶尔可以不遵守) 1.一般原则 R100:任何函数和类的代码规模都不应超过200行(不包括注释). 原因:长的函数和类会更复杂,因而难以理解和测试. r101:任何函数和类都应该能完全显示在一屏上,并完成单一的逻辑功能.

bitest(位集合)------c++程序设计原理与实践(进阶篇)

标准库模板类bitset是在<bitset>中定义的,它用于描述和处理二进制位集合.每个bitset的大小是固定的,在创建时指定: bitset<4> flags; bitset<128> dword_bits; bitset<12345> lots; 默认情况下,bitset被初始化为全0,但通常我们都会给它一个初始值,可以是一个无符号的整数或者"0"和"1"组成的字符串.例如: bitset<4> fl