程设期末复习

发布于 2026-01-04  525 次阅读


标识符 identifier
An identifier must start with a letter or an underscore. It cannot start with a digit.
assignment statement赋值语句


Numerical Data Types and Operations

A constant must be declared and initialized in the same statement.

overflow underflow

%remainder *subtraction *multiplication
5 / 2 yields an integer 2.
5.0 / 2 yields a double value 2.5

cout << "Interest is:" <<fixed<<setprecision(2)<<interest<<endl;
Interest is: 16.40

Operator Name
! not logical negation
&& and logical conjunciton
|| or logical disjunction

输入输出:

string sentence;getline(cin, sentence);
cout << "Interest is:" <<fixed<<setprecision(2)<<interest<<endl;

字符串

string s1 = "Hello";
string s2 = "Hi";
int result = s1.compare(s2);

string s = "programming";cout << s.substr(0, 3) << endl;   // "pro"
cout << s.substr(3, 4) << endl;   // "gram"
cout << s.substr(7) << endl;      // "ming"
string s = "Welcome to C++ programming";
cout << s.find("come") << endl; // 3
cout << s.find('o') << endl; // 4
cout << s.find("Java") << endl; // string::npos (not found)
cout << s.find("o", 5)<< endl; // search from index 5 onward
操作示例代码说明
拼接s3 = s1 + s2;合并两个字符串
追加s1 += "!";在末尾追加内容
长度s1.length() / s1.size()返回字符数
清空s1.clear()变为空字符串
判断空s1.empty()返回true或false
When a function contains a mixture of parameters with and without default values, those with default values must be declared last.


一沙一世界,一花一天堂。君掌盛无边,刹那成永恒。