--- config: look: handDrawn themeVariables: fontSize: 28px --- flowchart LR ra[需求分析] ad[算法设计] ci[程序编码] td[测试调试] ra --> ad ad --> ci ci --> td td --> ci
《计算机程序设计》
计算机学院计算机研究所编译系统研究室
Your are the GOD to computer while programming!
教员箴言
学习编程,既有用,又好玩 !
Picture created by Google Imagen 3
温馨提示
点击课件上的链接可以直达目标!
温馨提示
课件右下角校徽其实是课程主页传送门 :-D
课次 | 教学模块 | 课次 | 教学模块 | 课次 | 教学模块 |
---|---|---|---|---|---|
1 | 绪论 | 9 | 指针 | 17 | 链表 |
2 | 语言基础 | 10 | 程序调试 | 18 | 综合应用2 |
3 | 控制结构 | 11 | 数组进阶 | 19 | 文件IO |
4 | 控制结构 | 12 | 字符串 | 20 | 函数进阶 |
5 | 输入输出 | 13 | 函数参数 | 21 | 标准库 |
6 | 工具链 | 14 | 综合应用1 | 22 | 大模型 |
7 | 函数初步 | 15 | 结构 | 23 | 总结复习 |
8 | 数组初步 | 16 | 联合与枚举 | 24 | 答疑 |
上机安排
上课当天第9-10节,地点同上课教室
推荐主题(包括但不限于)
教员箴言
不打无准备之仗,不讲无准备之课!排练!排练!排练!
成绩模块 | 比例 | 备注 |
---|---|---|
课堂练习 | 10% | 简短编程练习、翻转课堂表现 |
实训作业 | 20% | 有严格限时,期末补交有罚分 |
单元测试 | 20% | 无期中考试,计划5次单元测试 |
期末考试 | 50% | 闭卷机试,10道编程题 |
温馨提示
硬件是身体,软件是灵魂!
计算机系统组成
软件的三个组成部分:程序、数据、文档
名人名言
程序 = 数据结构 + 算法
— Niklaus Wirth
Niklaus Wirth,瑞士计算机科学家,ETH教授,瑞士计算机科学主要奠基人之一,1984年图灵奖(首位德语获奖者)、1988年IEEE计算机先驱奖获得者,Pascal/Modula-2/Oberon发明者,首次提出“软件危机”概念。
--- config: look: handDrawn themeVariables: fontSize: 28px --- flowchart LR ra[需求分析] ad[算法设计] ci[程序编码] td[测试调试] ra --> ad ad --> ci ci --> td td --> ci
问题:求两个整数的商,若除数为0则向用户报错
文字描述
流程图描述
--- config: look: handDrawn themeVariables: fontSize: 24px --- flowchart LR start(["开始"]) input[/"读入除数、被除数"/] if0{"除数为0"} compute["计算整商"] output[/"输出整商"/] error[/"输出错误"/] End(["结束"]) start --> input input --> if0 if0 -- 否 --> compute compute --> output if0 -- 是 --> error output --> End error --> End classDef condition height:10,width:20 class if0 condition
--- config: look: handDrawn themeVariables: fontSize: 28px --- flowchart LR ra[需求分析] ad[算法设计] ci[程序编码] td[测试调试] ra --> ad ad --> ci ci --> td td --> ci
--- config: look: handDrawn themeVariables: fontSize: 24px --- flowchart LR start(["开始"]) input[/"读入除数、被除数"/] if0{"除数为0"} compute["计算整商"] output[/"输出整商"/] error[/"输出错误"/] End(["结束"]) start --> input input --> if0 if0 -- 否 --> compute compute --> output if0 -- 是 --> error output --> End error --> End
#include <iostream>
using namespace std;
int main() {
int dividend, divisor, quotient; //变量声明
cout << "Please enter the dividend:" << endl; //提示输入被除数
cin >> dividend;
cout << "Please enter the divisor:" << endl; //提示输入除数
cin >> divisor;
if (divisor == 0) {
cout << "Error: divisor cannot be zero!"<< endl; //输出错误信息
} else {
quotient = dividend / divisor; //执行除法
cout << "Quotient is " << quotient << endl; //输出商
}
return 0;
}
考考你
回顾《大学计算机基础》课程内容,程序设计语言按照抽象层次分为哪些类别?
据不完全统计,人类已经发明近9000种程序设计语言!
高级程序设计语言简史(1956–2004)
Chen, Yaofei, et al. “An empirical study of programming language trends.” IEEE software 22.3 (2005): 72-79.
1973年,Ken Thompson与Dennis Ritchie在实现UNIX操作系统过程中设计了C语言
1983年,贝尔实验室Bjarne Stroustrup对C进行改进和扩充,命名为C++
helloworld.cpp
庖丁解牛
#include <iostream>
:包含外部库,类似于Python的import
using namespace std;
:使用标准命名空间,类似于Python的from ... import *
int main()
:主函数,C/C++程序的执行入口
main
函数参数列表为空main
函数返回值类型为整型int
{}
:代码块,不同于python使用缩进界定代码块边界,C/C++使用花括号标记代码块的开始和结束return 0;
:返回0,表示程序正常结束,若非0则表示发生错误(别问为什么,问就是惯例)cout << "Hello world!\n";
:输出字符串,类似于Python的print('hello world')
//
:行注释,编译器将忽略注释内容;
:语句结束符,所有C/C++语句必须以分号结束,多个语句可以写在同一行,一个语句可以分成多个行--- config: look: handDrawn themeVariables: fontSize: 28px --- flowchart LR 编辑 --> 编译 --> 链接 --> 调试 调试 -.-> 编辑
进入helloworld.cpp
所在的目录,编译、链接此程序并运行
$ g++ -c -o helloworld.o helloworld.cpp # 生成目标文件helloworld.o
$ g++ -o helloworld helloworld.o # 链接生成可执行程序helloworld
$ ./helloworld # 运行可执行程序
对于单一文件构成的程序,编译、链接可以合并为一步
考考你
目标代码和可执行程序均为二进制程序,它们之间有何区别?
温馨提示
参照官方文档安装WSL
WSL启用后安装Ubuntu
启动WSL Ubuntu系统,执行下列命令安装C++开发工具
安装C++开发工具
参照官方文档安装VSCode
安装插件
计算机程序设计