面积对象编程(PPT讲稿)Object-Oriented Programming and Classes

Object-Oriented Programming and Classes
Object-Oriented Programming and Classes

OoP/ Slide 2 Motivation Basic, built-in, pre-defined types: char, int, double, Variables operations on them nt a b c=atb a mod b More complicated, user-defined types: classes Variables objects Types >classes
OOP / Slide 2 Basic, built-in, pre-defined types: char, int, double, … Variables + operations on them int a, b,c; c=a+b; c=a mod b; … More complicated, user-defined types: classes Motivation Variables → objects Types → classes

OoP/ Slide 3 procedural programming a sequence of procedures int a, b, c; CC: a=1(x) b=2(); f20 C=f3(z); } Class A int f20 Class B int f30 Int f20 Class c Object oriented programming: a sequence of 'objects'!
OOP / Slide 3 int main() { int x,y,z; int a,b,c; a=f1(x); b=f2(y); c=f3(z); … } int f1() { } int f2() { } int f3() { } int main() { A a; B b; C c; a.f1(); b.f2(); c.f3(); … } Class A { Int x; Int f1(); } Class B { Int y; Int f2() } Class C { Int z; Int f3(); } procedural programming: a sequence of ‘procedures’ Object oriented programming: a sequence of ‘objects’!

OoP/ Slide 4 Variables objects MotivationTypes → classes Procedural programming LOW-level. closer to hardware More intuitive less abstract More 'action’ oriented Focus on 'action, procedure, 'method Procedure-oriented Object-oriented programming High-level More abstract Focus on what to do' not on how to do In the implementation of OOP, we still need sound procedure programming' skills
OOP / Slide 4 Motivation Variables → objects Types → classes Procedural programming: Low-level, closer to hardware More intuitive, less abstract More ‘action’ oriented Focus on ‘action’, ‘procedure’, ‘method’ Procedure-oriented Object-oriented programming: High-level More abstract Focus on ‘what to do’ not on ‘how to do’ In the implementation of OOP, we still need sound ‘procedure programming’ skills!

OoP/ Slide 5 Motivation We want to build user-defined(and"smart) objects that can answer many questions(and perform various actions) What is your temperature? What is your temperature in Fahrenheit? What is your humidity?” Print your temperature in Celsius What is your wish?
OOP / Slide 5 Motivation We want to build user-defined (and “smart”) objects that can answer many questions (and perform various actions). “What is your temperature?” “What is your temperature in Fahrenheit?” “What is your humidity?” “Print your temperature in Celsius.” What is your wish?

OoP/ Slide 6 Temperature example Write a program that, given a temperature in Fahrenheit or Celsius, will display the equivalent temperature in each of the scales double degree=0.0; / needs 2 items char scale F To apply a function f() to a temperature, we must specify both degree and scale f(degree, scale)i Also to display a temperature 197 8202(Putonghua) cout < degree < scale 1878066( English)
OOP / Slide 6 Temperature example Write a program that, given a temperature in Fahrenheit or Celsius, will display the equivalent temperature in each of the scales. double degree = 0.0; // needs 2 items! char scale = 'F'; To apply a function f() to a temperature, we must specify both degree and scale: f(degree, scale); Also to display a temperature: cout << degree << scale;

OoP/ Slide 7 Put related variables together (remember that an array is a collection of variables of same type) The simpliest Class (or a C-structure) can be thought of being a collection of variables of different types
OOP / Slide 7 (remember that an Array is a collection of variables of same type) The simpliest Class (or a C-structure) can be thought of being a collection of variables of different types Put related variables together …

OoP/ Slide 8 a first simple class or object-oriented' solution class Temperature i public double degree Two mem ber variables degree and scale char scale;← a new(user-defined)type, a composite ty pe: Temperature! Remark: structure Temperature i In old C, this can be done using 'structure double degree similar to 'recordin Pascal char scale
OOP / Slide 8 A first simple ‘class’ or ‘object-oriented’ solution class Temperature { public: double degree; char scale; }; a new (user-defined) type, a composite type: Temperature! Two member variables: degree and scale In old C, this can be done using ‘structure’: structure Temperature { double degree; char scale; }; similar to ‘record’ in Pascal Remark:

OoP/ Slide 9 The dot operator for (public) members The modifier public' means that the mem ber variables can be accessed from the objects, e. g Temperature temp 1, temp2i templ degree=54.0; temp1.sca1e=NF′; temp2 degree=104.5 temp2. scale=C′ A C++ struct is a class in which all mem bers are by default public
OOP / Slide 9 temp1.degree=54.0; temp1.scale=‘F’; temp2.degree=104.5; temp2.scale=‘C’; The dot operator for (public) members Temperature temp1, temp2; The modifier ‘public’ means that the member variables can be accessed from the objects, e.g. A C++ struct is a class in which all members are by default public

OoP/ Slide 10 Manipulation of the new type Some basic operations: void print (Temperature temp out <<The temperature is degree < temp degree < with the scale M<< temp. scale < endli double celsius (Temperature temp) double cel if (temp. scale=='Fl) cel=(temp. degree-320)/1.8; else cel=temp. degree return cel double fahrenheit(Temperature temp) double fa f(temp.scale==C)fa= temp. degree *1.8+320i else fa=temp. degree return fa
OOP / Slide 10 void print(Temperature temp) { cout << “The temperature is degree “ << temp.degree << “with the scale “ << temp.scale << endl; } double celsius(Temperature temp) { double cel; if (temp.scale==‘F’) cel=(temp.degree-32.0)/1.8; else cel=temp.degree; return cel; } double fahrenheit(Temperature temp) { double fa; if(temp.scale==‘C’) fa= temp.degree *1.8+32.0; else fa=temp.degree; return fa; } Some basic operations: Manipulation of the new type:
按次数下载不扣除下载券;
注册用户24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
- 《计算机网络概述》教学资源(PPT课件讲稿).ppt
- 《计算机组成原理》课程PPT教学课件(讲稿)第三章 计算机核心部件及其工作原理.ppt
- 《大型机系统管理技术》课程教学资源(PPT课件讲稿)第2章 大型服务器外存管理.ppt
- 《ARM嵌入式软件开发》课程教学资源(PPT课件讲稿)第三章 ARM体系结构及编程模型.ppt
- 北京大学:基于信息利用的烟花算法研究(PPT讲稿)Research on Fireworks Algorithms from the Perspective of Information Utilization.pptx
- 系统编程工具REXX和CLIST.ppt
- 《软件测试 Software Testing》教学资源(PPT讲稿)Part 1 The Big Picture.ppt
- 西南民族大学:软件需求分析与总体设计(PPT讲稿,主讲:殷锋).ppt
- 中国地质大学(武汉):R语言入门教程(PPT讲稿).ppt
- 对外经济贸易大学:《大学计算机基础》课程电子教案(PPT课件)第5章 PowerPoint幻灯片制作(PowerPoint 2010).pptx
- 西安培华学院:《计算机网络工程》课程教学资源(PPT课件讲稿)第1章 网络工程知识(主讲:张伟).ppt
- 《计算机网络安全》课程教学资源(PPT课件讲稿)第四章 数据加密技术.ppt
- 计算机应用专业《计算机网络》教学大纲.doc
- 《计算机网络 COMPUTER NETWORKS》课程教学资源(PPT课件讲稿)Chapter 18 互联网协议 Internet Protocols(IP).ppt
- 淮阴工学院:《数据库原理》课程教学资源(PPT课件讲稿)第4章 结构化查询语言SQL.ppt
- 《C++语言程序设计》课程教学资源(PPT课件)第14讲 运算符重载.ppt
- 东南大学:《C++语言程序设计》课程教学资源(PPT课件讲稿)Chapter 13 Object-Oriented Programming - Polymorphism.ppt
- 山东大学:《微机原理及单片机接口技术》课程教学资源(PPT课件讲稿)第四章 指令系统及汇编语言程序设计(4.1-4.4).ppt
- 多媒体技术及应用(PPT讲稿)多媒体音频技术.ppt
- 《网络搜索和挖掘关键技术 Web Search and Mining》课程教学资源(PPT讲稿)Lecture 13 Matrix Factorization and Latent Semantic Indexing.ppt
- 同济大学:《大数据分析与数据挖掘 Big Data Analysis and Mining》课程教学资源(PPT课件讲稿)Evaluation & other classifiers.pptx
- 香港中文大学:Arm board tutorial Part 1 Using the ARM board And start working with C Tutorial 5 and 6.pptx
- 清华大学出版社:《JAVA程序设计实例教程》课程教材电子教案(PPT课件讲稿,共七章,主编:关忠).ppt
- 香港浸会大学:Community Search over Big Graphs:Models, Algorithms, and Opportunities.ppt
- 《数字图像处理》课程教学资源(PPT课件讲稿)第5章 图像编码与压缩.ppt
- 厦门理工学院:《网页设计》培训课件教学资源(PPT课件).ppt
- 西安电子科技大学:《计算机操作系统》课程PPT教学课件(讲稿)第六章 文件管理.ppt
- 机器翻译研讨会(PPT讲稿)神经机器翻译前沿进展(PPT讲稿).pptx
- 山东大学:《微机原理及单片机接口技术》课程教学资源(PPT课件讲稿)第三章 计算机系统的组成与工作原理 3.1 理解模型机的结构及工作过程 3.2 掌握单片机的结构.ppt
- 清华大学出版社:《计算机导论 Introduction to Computer Science》课程配套教材教学资源(PPT课件讲稿,第3版)第4章 操作系统与网络知识.ppt
- 《数据库系统原理》课程PPT教学课件(SQLServer)第7章 Transact-SQL程序设计.ppt
- 《Chemdraw 软件教程》教学资源(PPT讲稿)第一部分 ChemDraw简介.ppt
- 北京大学:计算智能实验室(PPT讲稿)烟花算法算子分析.pptx
- 上饶师范学院:《数据库系统原理 An Introduction to Database System》课程教学资源(PPT课件讲稿,共九章).ppt
- 清华大学:《数据中心网络 Data Center Networking》课程教学资源(PPT课件讲稿).pptx
- 人工神经网络(ANN)方法简介(PPT课件讲稿).ppt
- 合肥工业大学:使用大数据进行计算建模(PPT讲稿)Computing/Modeling with Big Data(主讲:吴信东).pptx
- 《模式识别》课程教学资源(PPT讲稿)Learning with information of features.ppt
- 烟台大学:《C语言程序设计》课程电子教案(PPT课件讲稿)第五章 数组、字符串、指针(主讲:荆蕾).ppt
- 《数据结构》课程教学资源(PPT课件讲稿)第六章 树与二叉树.ppt