更新第8周课评资料与教学文件:CSP03第7-8课string知识点、课评规范、教学演示文件

This commit is contained in:
chengzi
2026-04-22 20:15:18 +08:00
parent e4853c6123
commit 11fecf2b64
5 changed files with 2143 additions and 0 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,116 @@
# CSP03班 第8课 课前默写10分钟
**班级**CSP03班周六早/下午、周日早上) **范围**第7课《string字符串使用**满分**100分**建议用时**10分钟
---
## 一、填空题(每空 4 分,共 32 分)
1. 声明一个 `string` 变量 `s` 并初始化为 `"hello"` 的语句是:
`string s = _______________ ;`
2. 获取字符串 `s` 长度的函数是 `s._______()`
3. 读取一整行字符串(**包含空格**)应该使用函数:
`_______________(cin, s);`
4. `cin >> s` 读取字符串时,遇到 **_______** 就会停止读取。
5. 在字符串 `s` 中查找子串 `"abc"`,应该调用:
`s._______________("abc")`
6. 如果 `find()` 函数没有找到目标子串,返回值是 **_______**
7. 字符串 `"abcdef"` 中,字符 `'c'` 的下标是 **_______**
8. 从字符串 `s` 的下标 `2` 开始截取 `3` 个字符,应写成:
`s._______________(2, 3)`
---
## 二、判断题(每题 4 分,共 16 分)
正确的打 `√`,错误的打 `×`
1. `string s = "abc"; s += "def";` 执行后,`s` 的值是 `"abcdef"`
2. `string::npos` 的值等于 `-1`
3. )两个 `string` 可以直接用 `==` 比较是否相等。
4. `getline(cin, s)` 可以读取包含空格的整行字符串,直到遇到回车。
---
## 三、代码填空(每空 4 分,共 24 分)
下面程序的功能是:输入一行字符串,统计其中**大写字母**的数量。请补全代码。
```cpp
#include <iostream>
#include <string>
using namespace std;
int main() {
string s;
_______________(cin, s); // ① 读入一整行
int cnt = 0;
for (int i = 0; i < s.___________(); i++) { // ② 遍历字符串
if (_______(s[i])) { // ③ 判断是否为大写字母
cnt++;
}
}
cout << cnt << endl;
return 0;
}
```
---
## 四、代码阅读(共 10 分)
阅读以下程序,写出输出结果:
```cpp
#include <iostream>
#include <string>
using namespace std;
int main() {
string s = "hello world";
cout << s.find("world") << endl; // 输出①________
if (s.find("xyz") == string::npos) {
cout << "YES" << endl; // 输出②________
} else {
cout << "NO" << endl;
}
return 0;
}
```
---
## 五、简答题(共 18 分)
1. **简述 `cin >> s` 和 `getline(cin, s)` 在读取字符串时的主要区别。**10分
答:
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
2. **写出一段代码,遍历字符串 `s`,将其中的所有大写字母转换为小写字母。**8分
答:
```cpp
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
```
---
*穹狼科创 · CSP03班 · 2026春季*