diff --git a/day4/d10.cpp b/day4/d10.cpp new file mode 100644 index 0000000..17d3a22 --- /dev/null +++ b/day4/d10.cpp @@ -0,0 +1,15 @@ +#include + +using namespace std; + +int main() +{ + char c = 'a'; // 1B + int m = 2; // 4B + // 小字节转大字节, 会自动转换 + m += c; // 先将c转换为int,再相加 + cout << "m = " << m << endl; + // 大字节转小字节,会丢失精度,需要强制类型转换 + cout << "m to char is " << (char)m << endl; + return 0; +} \ No newline at end of file diff --git a/day4/d8.cpp b/day4/d8.cpp new file mode 100644 index 0000000..8fc5fd9 --- /dev/null +++ b/day4/d8.cpp @@ -0,0 +1,13 @@ +#include + +using namespace std; + +int main() +{ + int x1, y1, x2, y2; + cout << "请输入两个点坐标, 格式如 x1 y1 x2 y2" << endl; + cin >> x1 >> y1 >> x2 >> y2; + cout << "P1(" << x1 << "," << y1 << ")" + << " P2(" << x2 << "," << y2 << ")" << endl; + return 0; +} \ No newline at end of file