课程代码仓库初始化:Part1 (144) + Part3 (29) 全量生成与验证
把川大 wiki「02.Qt方向」课程代码整理为 CMake 管理的可编译运行项目。
Part1 C/C++ 强化 (p01/, 144 目标, host gcc/g++ 构建, 全绿):
- 修复全部编译失败:补 <cstring>/<fstream>/<iomanip>/<vector> 等缺失头
(common_fix + infer_stl_includes 自动检测注入)、修正 pause() 壳注入
(改检测已转换后的 pause 调用)、namespace 提升出函数体、const 成员函数
正确性、dedupe 不再破坏函数重载集、K&R 隐式 int / 动态异常规范等
C++17 移除特性的可编译等价改写。
- 目录采用深缩写 p01/ch04/s03/ (原 part1_cpp/ch04_class_object/03_ctor_dtor)。
Part3 Qt 桌面 (p03/, 29 目标, 隔离 Qt 5.14.2 构建, 全绿):
- gen_part3.py: Qt 外壳模板 (main+QApplication+show, QTimer 自动退出便于
offscreen 验证)、AUTOMOC + .moc include、rewrite_* 处理散文混入/重载/
资源依赖、生成占位 png/gif + .qrc + rundata 样例数据。
- 修正 QLable 笔误、全角分号、.→->、Windows 路径、QApplication 阻塞事件
循环改为 QCoreApplication 等。
任务1 概念/版本验证:
- tools/std_probe.py: 跨 -std= 编译探针 (--pedantic-errors 让已废除特性硬失败)。
- tools/demo_versions/: K&R 隐式 int、三目左值、void* 转换、enum 赋整、
const 经指针、动态异常规范 共 6 个跨版本演示。
- docs/VERSION_NOTES.md: 每条「原文说法→C17/C++17 是否成立→何版本成立→已验证」。
文档: 顶层 README、docs/SOURCE_PAGES.md (页面→目录映射)、
docs/ERRATA.md (Part1 修正)、docs/ERRATA_part3.md (Part3 修正)。
另修复 tools/run.sh / run_qt.sh 的 ${1:?...} 引号语法 bug。
隔离 Qt 验证: ldd 0 系统 Qt 引用; 173/173 目标全绿; p03 offscreen 运行通过。
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
# Auto-generated by tools/gen_part1.py — do not edit by hand.
|
||||
# 章节:p01/ch04/s02
|
||||
add_executable(p1c04_02_01 cube_class_design.cpp)
|
||||
set_target_properties(p1c04_02_01 PROPERTIES C_STANDARD 17 C_STANDARD_REQUIRED ON C_EXTENSIONS OFF)
|
||||
set_target_properties(p1c04_02_01 PROPERTIES CXX_STANDARD 17 CXX_STANDARD_REQUIRED ON CXX_EXTENSIONS OFF)
|
||||
target_compile_options(p1c04_02_01 PRIVATE -Wall -Wextra)
|
||||
add_executable(p1c04_02_02 point_and_circle.cpp)
|
||||
set_target_properties(p1c04_02_02 PROPERTIES C_STANDARD 17 C_STANDARD_REQUIRED ON C_EXTENSIONS OFF)
|
||||
set_target_properties(p1c04_02_02 PROPERTIES CXX_STANDARD 17 CXX_STANDARD_REQUIRED ON CXX_EXTENSIONS OFF)
|
||||
target_compile_options(p1c04_02_02 PRIVATE -Wall -Wextra)
|
||||
add_custom_target(all_p01_ch04_s02 DEPENDS p1c04_02_01 p1c04_02_02)
|
||||
@@ -0,0 +1,80 @@
|
||||
// ============================================================================
|
||||
// p1c04_02_01 — 4.2.1 设计立方体类
|
||||
// 来源:川大 C++/LinuxC wiki「02.Qt方向」
|
||||
// 说明:本文件由 gen_part1.py 合并页面中的教学片段而成。每个片段用
|
||||
// // --- 原文片段 [pageId:blockIdx] --- 标注出处。
|
||||
// 已做最小修正(笔误/平台移植),详见 docs/ERRATA.md。
|
||||
// ============================================================================
|
||||
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
// --- 原文片段 [58954449:0] 4.2.1 设计立方体类 ---
|
||||
//立方体类
|
||||
class Cub{
|
||||
public:
|
||||
void setL(int l){ mL = l; }
|
||||
void setW(int w){ mW = w; }
|
||||
void setH(int h){ mH = h; }
|
||||
int getL(){ return mL; }
|
||||
int getW(){ return mW; }
|
||||
int getH(){ return mH; }
|
||||
//立方体面积
|
||||
int caculateS(){ return (mL*mW + mL*mH + mW*mH) * 2; }
|
||||
//立方体体积
|
||||
int caculateV(){ return mL * mW * mH; }
|
||||
//成员方法
|
||||
bool CubCompare(Cub& c){
|
||||
if (getL() == c.getL() && getW() == c.getW() && getH() == c.getH()){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
private:
|
||||
int mL; //长
|
||||
int mW; //宽
|
||||
int mH; //高
|
||||
};
|
||||
|
||||
//比较两个立方体是否相等
|
||||
bool CubCompare(Cub& c1, Cub& c2){
|
||||
if (c1.getL() == c2.getL() && c1.getW() == c2.getW() && c1.getH() == c2.getH()){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void test(){
|
||||
Cub c1, c2;
|
||||
c1.setL(10);
|
||||
c1.setW(20);
|
||||
c1.setH(30);
|
||||
|
||||
c2.setL(20);
|
||||
c2.setW(20);
|
||||
c2.setH(30);
|
||||
|
||||
cout << "c1面积:" << c1.caculateS() << " 体积:" << c1.caculateV() << endl;
|
||||
cout << "c2面积:" << c2.caculateS() << " 体积:" << c2.caculateV() << endl;
|
||||
|
||||
//比较两个立方体是否相等
|
||||
if (CubCompare(c1, c2)){
|
||||
cout << "c1和c2相等!" << endl;
|
||||
}
|
||||
else{
|
||||
cout << "c1和c2不相等!" << endl;
|
||||
}
|
||||
|
||||
if (c1.CubCompare(c2)){
|
||||
cout << "c1和c2相等!" << endl;
|
||||
}
|
||||
else{
|
||||
cout << "c1和c2不相等!" << endl;
|
||||
}
|
||||
}
|
||||
|
||||
// --- main ---
|
||||
int main() {
|
||||
test();
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
// ============================================================================
|
||||
// p1c04_02_02 — 4.2.2 点和圆的关系
|
||||
// 来源:川大 C++/LinuxC wiki「02.Qt方向」
|
||||
// 说明:本文件由 gen_part1.py 合并页面中的教学片段而成。每个片段用
|
||||
// // --- 原文片段 [pageId:blockIdx] --- 标注出处。
|
||||
// 已做最小修正(笔误/平台移植),详见 docs/ERRATA.md。
|
||||
// ============================================================================
|
||||
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
// --- 原文片段 [58954449:1] 4.2.2 点和圆的关系 ---
|
||||
//点类
|
||||
class Point{
|
||||
public:
|
||||
void setX(int x){ mX = x; }
|
||||
void setY(int y){ mY = y; }
|
||||
int getX(){ return mX; }
|
||||
int getY(){ return mY; }
|
||||
private:
|
||||
int mX;
|
||||
int mY;
|
||||
};
|
||||
|
||||
//圆类
|
||||
class Circle{
|
||||
public:
|
||||
void setP(int x,int y){
|
||||
mP.setX(x);
|
||||
mP.setY(y);
|
||||
}
|
||||
void setR(int r){ mR = r; }
|
||||
Point& getP(){ return mP; }
|
||||
int getR(){ return mR; }
|
||||
//判断点和圆的关系
|
||||
void IsPointInCircle(Point& point){
|
||||
int distance = (point.getX() - mP.getX()) * (point.getX() - mP.getX()) + (point.getY() - mP.getY()) * (point.getY() - mP.getY());
|
||||
int radius = mR * mR;
|
||||
if (distance < radius){
|
||||
cout << "Point(" << point.getX() << "," << point.getY() << ")在圆内!" << endl;
|
||||
}
|
||||
else if (distance > radius){
|
||||
cout << "Point(" << point.getX() << "," << point.getY() << ")在圆外!" << endl;
|
||||
}
|
||||
else{
|
||||
cout << "Point(" << point.getX() << "," << point.getY() << ")在圆上!" << endl;
|
||||
}
|
||||
}
|
||||
private:
|
||||
Point mP; //圆心
|
||||
int mR; //半径
|
||||
};
|
||||
|
||||
void test(){
|
||||
//实例化圆对象
|
||||
Circle circle;
|
||||
circle.setP(20, 20);
|
||||
circle.setR(5);
|
||||
//实例化点对象
|
||||
Point point;
|
||||
point.setX(25);
|
||||
point.setY(20);
|
||||
|
||||
circle.IsPointInCircle(point);
|
||||
}
|
||||
|
||||
// --- main ---
|
||||
int main() {
|
||||
test();
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user