第4章过程化语句及程序设计
- 格式:ppt
- 大小:514.51 KB
- 文档页数:102


粤教版信息技术必修一《数据与计算》第一章数据与信息第二章知识与数字化学习知识与数字化学习知识与智慧知识对信息进行提炼、研究和分析的结果智慧运用知识解决问题的创新思维能力数字化学习与创新数字化工具能够采集、获取、检索、表示、传输、存储与加工多媒体数字化资源的装备设置数字化资源数字化工具加工处理,可共享的多媒体材料数字化工具与资源的优势获取的便捷性形式的多样性资源的共享性平台的互动性内容的扩展性数字化学习的特点问题化合作性个性化创造性与再生性开放性思维导图软件xmindMindmanagerFreeMind2.1知识与智慧1.知识是人们运用大脑对获取或积累的信息进行系统化地提炼、研究和分析的结果。
2.智慧是应用知识解决问题的实践创新能力。
3.数据、信息、知识和智慧的相互关系4.数据、信息、知识和智慧是逐渐递进的概念,前者是后者的基础和前提,后者是前者的抽象与升华。
2.2数字化学习与创新1.数字化资源与学习工具,可以有效地管理学习过程和学习资源。
2.数字化资源与工具(1)数据采集工具。
如:声卡、视频卡、数码照相机、数码录像机、手写板、扫描仪等。
(2)信息获取工具。
如:台式电脑、笔记本电脑、平板电脑和手机等。
(3)信息检索工具。
如:搜索引擎和电子词典等。
(4)数字化可视化表达工具。
如:思维导图和演示文稿等。
思维导图:XMind、Mindmanager ,Free-Mind等(5)信息通信交流与传输工具。
如:电子邮件、博客、社交软件和视频会议系统等。
(6)信息存储工具。
如:光盘、U盘、硬盘和服务器等。
(7)信息加工工具。
如:编程软件、多媒体制作软件、网站制作工具和信息系统制作工具等。
(8)三维设计工具。
如3D制作软件、3D打印机、虚拟现实和增强现实制作系统等。
3.数字化工具与资源的优势①获取的便捷性②形式的多样性③资源的共享性④平台的互动性⑤内容的扩展性4.数字化学习的特点问题化、合作性、个性化、创造性和再生性、开放性第三章算法基础算法基础体验计算机解决问题的过程人工解决问题的过程计算机解决问题的过程算法及描述算法在有限步骤内解决问题的方法算法的特征有穷性确定性数据输入:可有可无数据输出:必须有可行性算法的描述自然语言流程图伪代码三种控制结构顺序结构选择结构循环结构计算机程序与程序设计语言计算机程序计算机可以识别执行的指令集合程序设计语言机器语言汇编语言高级语言一、体验计算机解决问题的过程(一)人工解决问题的过程明确问题和给出条件—>根据经验和知识确定解决问题的方法—>解决问题(二)计算机解决问题的过程分析问题—>设计算法—>编写程序—>调试运行程序二、算法及其描述(一)算法1.概念:在有限步骤内求解某一问题所使用的一组定义明确的规则。
《C语言程序设计》基本知识点第一章C语言基本知识1.C源程序的框架尽管各个C源程序的功能千变万化,但框架是不变的,主要有:编译预处理、主函数()、函数n()等,主函数的位置不一定在最前面,可以在程序的中部或后面,主函数的名字固定为main。
2.C语言源程序的书写规则:(1)C源程序是由一个主函数和若干个其它函数组成的。
(2)函数名后必须有小括号,函数体放在大括号内。
(3)C程序必须用小写字母书写。
(4)每句的末尾加分号。
(5)可以一行多句。
(6)可以一句多行。
(7)可以在程序的任何位置加注释。
3.语句种类语句是程序的基本成分,程序的执行就是通过一条条语句的执行而得以实现的,根据表现形式及功能的不同,C语言的基本语句可以分为五大类。
(1)流程控制语句流程控制语句的功能是控制程序的走向,程序的流程有三种基本结构:顺序结构、分支结构和循环结构,任何复杂的程序都可以由这三种基本结构复合而成。
其中后两种结构要用特定的流程控制语句实现。
(2)表达式语句表达式语句的形式是:表达式;,即表达式后跟一分号“;”,分号是语句结束符,是一个语句必不可少的成分。
表达式和表达式语句的区别在于表达式代表的是一个数值,而表达式语句则代表一种动作。
最常见的表达式语句是赋值语句。
(3)函数调用语句函数调用语句实际上也是一种表达式语句,形式为:在一次函数调用的小括号后面加上一个分号。
(4)空语句空语句的形式就是一个分号,它不代表任何动作,常常作为一个意义转折点使用。
(5)复合语句复合语句从形式上看是多个语句的组合,但在语法意义上它只相当于一个语句,在任何单一语句存在的地方都可以是复合语句。
注意复合语句中最后一个语句末尾的分号不能少。
复合语句右大括号后面没有分号。
4.运算符用来表示数据各种操作的符号称为运算符。
运算符实际上代表了一种类型数据的运算规则。
不同的运算符具有不同的运算规则,其操作的数据类型必须符合该运算符的要求,运算结果的数据类型也是固定的。
过程化和非过程化declarev_deptno scott.emp.deptno%type;beginselect deptno into v_deptno from scott.emp where empno=7844;if v_deptno=10 thenupdate scott.emp set sal=sal+100 where empno=7844;else update scott.emp set sal=sal+200 where empno=7844;end if;end;定义一个包含子块的PL/SQL块set serveroutput ondeclare v_sal number(6,2);v_deptno number(2);beginbegin select deptno into v_deptno from scott.emp where empno=7844; end;select avg(sal) into v_sal from scott.emp where deptno=V_deptno; dbms_output.put_line(v_sal);end;命名块:create or replace procedure showavgsal(p_deptno number)asv_sal number(6,2);beginselect avg(sal) into v_sal from scott.emp where deptno=p_deptno; dbms_output.put_line(v_sal);end showavgsal;execute showavgsal(10);记录变量:利用记录类型以及记录类型变量来保存员工信息declaretype t_emp is record(empno number(4),ename char(10),sal number(6,2));v_emp t_emp;beginselect empno,ename,sal into v_emp from scott.emp where empno=7844; dbms_output.put_line(v_emp.ename||' '||v_emp.sal);集合类型:索引表类型declaretype emp_table is table of char(10) index by binary_integer;v_enames emp_table;beginselect ename into v_enames(0) from scott.emp where empno=7844; select ename into v_enames(1) from scott.emp where empno=7900; dbms_output.put_line(v_enames(0)||' '||v_enames(1));end;常量与变量的定义:declarev1 number(4);v2 number(4) not null:=10;v3 constant number(4) default 100;beginif v1 is null thendbms_output.put_line('v1 is null!');end if;dbms_output.put_line(v2||' '||v3);end;变量的作用域:<<OUTER>>declarev_ename char(15);v_outer number(5);beginv_outer:=10;declarev_ename char(20);v_inner date;beginv_inner:=sysdate;v_ename:='inner v_ename';OUTER.v_ename:='outer v_ename';end;dbms_output.put_line(v_ename);end;DML:declarev_empno scott.emp.empno%type:=7500;begininsert into scott.emp(empno,ename,sal,deptno)values(v_empno,'JOAN',2300,20);update scott.emp set sal=sal+100 where empno=v_empno;delete from scott.emp where empno=v_empno;end;returning:declarev_sal scott.emp.sal%type;beginupdate scott.emp set sal=sal+100 where empno=7844 returning sal into v_sal; dbms_output.put_line(v_sal);end;控制语句:IF:declarev_deptno scott.emp.deptno%type;v_increment number(4);v_empno scott.emp.empno%type;beginv_empno:=&x;select deptno into v_deptno from scott.emp where empno=v_empno;if v_deptno=10 then v_increment:=100;elsif v_deptno=20 then v_increment:=150;elsif v_deptno=30 then v_increment:=200;else v_increment:=300;end if;update scott.emp set sal=sal+v_increment where empno=v_empno;end;case::declarev_deptno scott.emp.deptno%type;v_increment number(4);v_empno scott.emp.empno%type;beginv_empno:=&x;select deptno into v_deptno from scott.emp where empno=v_empno;when 20 then v_increment:=150;when 30 then v_increment:=200;else v_increment:=300;end case;update scott.emp set sal=sal+v_increment where empno=v_empno;end;游标:declarev_deptno scott.emp.deptno%type;cursor c_emp is select * from scott.emp where deptno=v_deptno;v_emp c_emp%rowtype;beginv_deptno:=&x;open c_emp;loopfetch c_emp into v_emp;exit when c_emp%notfound;dbms_output.put_line(v_emp.empno||' '||v_emp.ename||' '||v_emp.sal||' '||v_deptno); end loop;close c_emp;end;隐式游标:beginupdate scott.emp set sal=sal+100 where empno=1000;if sql%notfound theninsert into scott.emp(empno,sal) values(1000,1500);end if;end;存储过程:create or replace procedure show_emp(p_deptno scott.emp.deptno%type)asv_sal scott.emp.sal%type;beginselect avg(sal) into v_sal from scott.emp where deptno=p_deptno;dbms_output.put_line(p_deptno||' '||'average salary is:'||v_sal);for v_emp in (select * from scott.emp where deptno=p_deptno and sal>v_sal) loop dbms_output.put_line(v_emp.empno||' '||v_emp.ename);end loop;exceptionwhen no_data_found thendbms_output.put_line('the department doesn''t exists!');end show_emp;execute show_emp(10);create or replace procedure return_deptinfo(p_deptno scott.emp.deptno%type,p_avgsal out scott.emp.sal%type,p_count out scott.emp.sal%type)asbeginselect avg(sal),count(*) into p_avgsal,p_count from scott.empwhere deptno=p_deptno;exceptionwhen no_data_found thendbms_output.put_line('the department don''t exists!');end return_deptinfo;存储过程可以作为一个独立的表达式被调用declarev_avgsal scott.emp.sal%type;v_count number;beginshow_emp(20);return_deptinfo(10,v_avgsal,v_count);dbms_output.put_line(v_avgsal||' '||v_count);end;函数:create or replace function return_maxsal(p_deptno scott.emp.deptno%type) return scott.emp.sal%typeasv_maxsal scott.emp.sal%type;beginselect max(sal) into v_maxsal from scott.emp where deptno=p_deptno; return v_maxsal;exceptionwhen no_data_found thendbms_output.put_line('the deptno is invalid!');end return_maxsal;declarev_sal scott.emp.sal%type;beginfor v_dept in(select distinct deptno from scott.emp) loopv_sal:=return_maxsal(v_dept.deptno);dbms_output.put_line(v_dept.deptno||' '||v_sal);end loop;end;触发器:DML:语句级:禁止操作create or replace trigger trg_emp_weekendbefore insert or update or delete on scott.empbeginif to_char(sysdate,'DY','nls_date_langudage=american') in('sat','sun')thenraise_application_error(-20000,'can''t operate in weekend');end if;end trg_emp_weekend;insert into scott.emp(empno)values(1423);drop trigger trg_emp_weekend条件谓词:create or replace trigger trg_emp_dmlafter insert or update or delete on scott.empdeclarev_count number;if inserting thenselect count(*) into v_count from scott.emp;dbms_output.put_line(v_count);elsif updating thenselect avg(sal) into v_sal from scott.emp;dbms_output.put_line(v_sal);elsefor v_dept in(select deptno,count(*) num from scott.emp group by deptno) loop dbms_output.put_line(v_dept.deptno||' '||v_dept.num);end loop;end if;end trg_emp_dml;insert into scott.emp(empno)values(1423);行级触发器create or replace trigger trg_emp_dml_rowbefore insert or update or delete on scott.empfor each rowbeginif inserting thendbms_output.put_line(:new.empno||' '||:new.ename);elsif updating thendbms_output.put_line(:old.sal||' '||:new.sal);elsedbms_output.put_line(:old.empno||' '||:old.ename);end if;end trg_emp_dml_row;利用when进行控制:create or replace trigger trg_emp_update_rowbefore update of sal on scott.empfor each rowwhen(new.sal<=old.sal)beginraise_application_error(-20001,'the salary is lower!');end trg_emp_update_row;Instead OF触发器create or replace view scott.empdeptasselect empno,ename,sal,dname from scott.emp,scott.dept where scott.emp.deptno=scott.dept.deptno with check option;insert into scott.empdept values(2345,'tom',3000,'sales');create or replace trigger trig_viewinstead of insert on scott.empdeptfor each rowdeclare v_deptno scott.dept.deptno%type;beginselect deptno into v_deptno from scott.dept where dname=:new.dname;insert into scott.emp(empno,ename,sal,deptno)values(:new.empno,:new.ename,v_deptno,:new.sal);end trig_view;系统触发器:create or replace trigger log_user_connectionafter logon on databasebegininsert into scott.temp_table values(user,sysdate);end log_user_connection;。