香港浸会大学:C++ as a Better C; Introducing Object Technology

18 C++ as a Better C Introducing Object Technology o 2007 Pearson education nc. All rights reserved
© 2007 Pearson Education, Inc. All rights reserved. 1 18 C++ as a Better C; Introducing Object Technology

OBJECTIVES In this chapter you will learn Several C++ enhancements to c The header files of the C++ standard library To use inline functions To create and manipulate references To use default function arguments To use the unary scope resolution operator to access a global variable in a scope that contains a local variable of the same name To overload function definitions To create and use function templates that perform identical operations on many different types o 2007 Pearson education nc. All rights reserved
© 2007 Pearson Education, Inc. All rights reserved. 2 OBJECTIVES In this chapter you will learn: ▪ Several C++ enhancements to C. ▪ The header files of the C++ Standard Library. ▪ To use inline functions. ▪ To create and manipulate references. ▪ To use default function arguments. ▪ To use the unary scope resolution operator to access a global variable in a scope that contains a local variable of the same name. ▪ To overload function definitions. ▪ To create and use function templates that perform identical operations on many different types

0.1 Introduction 18.2C+ o 18.3 A Simple Program: Adding Two Integers 18.4 C++ Standard Library 18.5 Header files 18.6 nline Functions 18.7 References and Reference Parameters o 2007 Pearson Education, Inc. All rights reserved
© 2007 Pearson Education, Inc. All rights reserved. 3 18.1 Introduction 18.2 C++ 18.3 A Simple Program: Adding Two Integers 18.4 C++ Standard Library 18.5 Header Files 18.6 Inline Functions 18.7 References and Reference Parameters

4 g 18.8 Empty Parameter Lists 18.9 Default Arguments o 18.10 Unary Scope Resolution Operator 18.11 Function Overloading 18.12 Function Templates 18.13 Introduction to Object Technology and the UML 18.14 Wrap-Up o 2007 Pearson Education, Inc. All rights reserved
© 2007 Pearson Education, Inc. All rights reserved. 4 18.8 Empty Parameter Lists 18.9 Default Arguments 18.10 Unary Scope Resolution Operator 18.11 Function Overloading 18.12 Function Templates 18.13 Introduction to Object Technology and the UML 18.14 Wrap-Up

5 18.1 Introduction The c++ section introduces two additional programming paradigms Object-oriented programming With classes, encapsulation, objects, operator overloading. inheritance and polymorphism Generic programming With function templates and class templates Emphasize crafting valuable classes"'to create reusable software componentry o 2007 Pearson Education, Inc. All rights reserved
© 2007 Pearson Education, Inc. All rights reserved. 5 18.1 Introduction • The C++ section introduces two additional programming paradigms – Object-oriented programming • With classes, encapsulation, objects, operator overloading, inheritance and polymorphism – Generic programming • With function templates and class templates • Emphasize “crafting valuable classes” to create reusable software componentry

6 18.2C++ C++ improves on many of Cs features and provides object-oriented-programming(OoP) capabilities Increase software productivity, quality and reusability C++ was developed by bjarne stroustrup at bell Laboratories Originally called" C with classes The name C++ includes Cs increment operator(++) Indicate that C++ is an enhanced version of c C++ standardized in the United states through the American National Standards Institute(ANSD and worldwide through the international standards Organization(Iso) o 2007 Pearson Education, Inc. All rights reserved
© 2007 Pearson Education, Inc. All rights reserved. 6 18.2 C++ • C++ improves on many of C’s features and provides object-oriented-programming (OOP) capabilities – Increase software productivity, quality and reusability • C++ was developed by Bjarne Stroustrup at Bell Laboratories – Originally called “C with classes” – The name C++ includes C’s increment operator (++) • Indicate that C++ is an enhanced version of C • C++ standardized in the United States through the American National Standards Institute (ANSI) and worldwide through the International Standards Organization (ISO)

// Fig. 18.1: fig18_01. cpp 7 // Addition program that displays the sum of two numbers Outline 3 #include / allows program to perform input and output Include the contents 5 int maino of the iostream 6{ 7 int number1; / first integer to add fig18_01. cpp Declare integer variables 10 std: cin > number1;//read first integer from-user into number1 Use stream extraction 12 int number2; / second integer to add operator with standard input 13 int sum;// sum of number1 and numbe stream to obtain user input 15 std: cout s number2; / read second integer from user into number2 17 sum= number 1 number 2:// add the numbers: store result in sum 18 std: cout < sum is<< sum <<std::end i/ display sum; end line 19 Stream manipulator 20 return 0;// indicate that program ended successfully std: endl outputs a 213// end function main newline, then"flushes output Enter first integer: 45 buffer Enter second integer: 72 sum is 117 Concatenating, chaining or cascading stream insertion operations C 2007 Pearson Education Inc. All rights reserved
© 2007 Pearson Education, Inc. All rights reserved. 7 1 // Fig. 18.1: fig18_01.cpp 2 // Addition program that displays the sum of two numbers. 3 #include // allows program to perform input and output 4 5 int main() 6 { 7 int number1; // first integer to add 8 9 std::cout > number1; // read first integer from user into number1 11 12 int number2; // second integer to add 13 int sum; // sum of number1 and number2 14 15 std::cout > number2; // read second integer from user into number2 17 sum = number1 + number2; // add the numbers; store result in sum 18 std::cout << "Sum is " << sum << std::endl; // display sum; end line 19 20 return 0; // indicate that program ended successfully 21 } // end function main Enter first integer: 45 Enter second integer: 72 Sum is 117 Outline fig18_01.cpp Declare integer variables Use stream extraction operator with standard input stream to obtain user input Stream manipulator std::endl outputs a newline, then “flushes output buffer” Concatenating, chaining or cascading stream insertion operations Include the contents of the iostream

18. A Simple Program: Adding Two Integers C++ file names can have one of several extensions Such as: cpp,. cxx or C(uppercase) Commenting A//comment is a maximum of one line long A/... /C-style comments can be more than one line long ·1 ostream Must be included for any program that outputs data to the screen or inputs data from the keyboard using C++-style stream input/output C++ requires you to specify the return type, possibl void. for all functions Specifying a parameter list with empty parentheses is equivalent to specifying a void parameter list in C o 2007 Pearson Education, Inc. All rights reserved
© 2007 Pearson Education, Inc. All rights reserved. 8 18.3 A Simple Program: Adding Two Integers • C++ file names can have one of several extensions – Such as: .cpp, .cxx or .C (uppercase) • Commenting – A // comment is a maximum of one line long – A /*…*/ C-style comments can be more than one line long •iostream – Must be included for any program that outputs data to the screen or inputs data from the keyboard using C++-style stream input/output • C++ requires you to specify the return type, possibly void,for all functions – Specifying a parameter list with empty parentheses is equivalent to specifying a voidparameter list in C

9 18. A Simple Program: Adding Two Integers(Cont) Declarations can be placed almost anywhere in a C++ program They must appear before their corresponding variables are used in the program Input stream object std:: cin from Usually connected to keyboard Stream extraction operator >> Waits for user to input value, press Enter(Return) key Stores value in varia ble to the right of operator Converts value to variable data type · Example std: :cin > number 1: Reads an integer typed at the keyboard Stores the integer in variable number1 Just like scanf(%d",&number1) in C o 2007 Pearson Education, Inc. All rights reserved
© 2007 Pearson Education, Inc. All rights reserved. 9 18.3 A Simple Program: Adding Two Integers (Cont.) • Declarations can be placed almost anywhere in a C++ program – They must appear before their corresponding variables are used in the program • Input stream object – std::cin from • Usually connected to keyboard • Stream extraction operator >> - Waits for user to input value, press Enter (Return) key - Stores value in variable to the right of operator • Converts value to variable data type • Example - std::cin >> number1; • Reads an integer typed at the keyboard • Stores the integer in variable number1 - Just like scanf(“%d”, &number1) in C

10 18. A Simple Program: Adding Two Integers(Cont) Stream manipulator std: endT Outputs a newline Similar to“n?” Flushes the output buffer The notation std: cout specifies that we are using a name(cout) that belongs to a “ namespace”(std) o 2007 Pearson Education, Inc. All rights reserved
© 2007 Pearson Education, Inc. All rights reserved. 10 18.3 A Simple Program: Adding Two Integers (Cont.) • Stream manipulator std::endl – Outputs a newline • Similar to “\n” – Flushes the output buffer • The notation std::cout specifies that we are using a name (cout ) that belongs to a “namespace” (std)
按次数下载不扣除下载券;
注册用户24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
- 清华大学:《高级计算机网络 Advanced Computer Network》课程教学资源(PPT课件讲稿)Lecture 1 Introduction.pptx
- 《TCP/IP协议及其应用》课程教学资源(PPT课件)第1章 TCP/IP协议基础.ppt
- 香港理工大学:Artificial Neural Networks for Data Mining.ppt
- 安徽理工大学:《Linux开发基础 Development Foundation on Linux OS》课程资源(PPT课件讲稿)Section 4 Perl programming(赵宝).ppt
- 《网上开店实务》课程教学资源(PPT讲稿)学习情境1 网上开店创业策划.ppt
- 东南大学:《C++语言程序设计》课程教学资源(PPT课件讲稿)Chapter 10 Classes A Deeper Look(Part 2).ppt
- 广西医科大学:《计算机网络 Computer Networking》课程教学资源(PPT课件讲稿)Chapter 01 Introduction overview.pptx
- 《网络搜索和挖掘关键技术 Web Search and Mining》课程教学资源(PPT讲稿)Lecture 11 Probabilistic Information Retrieval.ppt
- 山东大学:《人机交互技术》课程教学资源(PPT课件讲稿)第3章 交互设备 3.5 显示设备 3.6 语音交互设备 3.7虚拟现实系统中的交互设备.ppt
- 东北大学:《可信计算基础》课程教学资源(PPT课件讲稿)第6章 TPM核心功能(主讲:周福才).pptx
- 媒体服务(PPT课件讲稿)Media Services.ppt
- 河南中医药大学(河南中医学院):《计算机网络》课程教学资源(PPT课件讲稿)第六章 应用层.pptx
- 中国科学技术大学:《计算机体系结构》课程教学资源(PPT课件讲稿)第6章 Data-Level Parallelism in Vector, SIMD, and GPU Architectures.ppt
- 南京大学:《编译原理》课程教学资源(PPT课件讲稿)第七章 运行时刻环境.ppt
- 《高级人工智能 Advanced Artificial Intelligence》教学资源(PPT讲稿)Lecture 7 Recurrent Neural Network.pptx
- 西安交通大学:《网络与信息安全》课程PPT教学课件(网络入侵与防范)第六章 网络入侵与防范——拒绝服务攻击与防御技术.ppt
- 西安电子科技大学:《计算机通信网》课程教学资源(PPT课件讲稿)第1章 概述(宋锐).ppt
- 中国科学技术大学:《嵌入式操作系统 Embedded Operating Systems》课程教学资源(PPT课件讲稿)第四讲 CPU调度(part II).ppt
- 大数据集成(PPT讲稿)Big Data Integration.pptx
- 《计算机文化基础》课程教学资源(PPT课件讲稿)第七章 计算机网络基础.ppt
- 大庆职业学院:《计算机网络技术基础》课程教学资源(PPT课件讲稿)第2章 数据通信的基础知识.ppt
- The Art of Function Design -Measure and RKHS.ppt
- 《计算机网络与因特网》课程教学资源(PPT课件)Part VII 广域网(简称WAN), 路由, 和最短路径.ppt
- 三维计算机视觉 3D computer vision(基于卡尔曼滤波的运动结构).pptx
- 河南中医药大学(河南中医学院):《计算机文化》课程教学资源(PPT课件讲稿)第七章 数据库技术(主讲:王哲).pptx
- 《单片机原理及应用》课程教学资源(PPT课件讲稿)第14章 单片机应用系统抗干扰与可靠性设计.ppt
- 北京航空航天大学:《数据挖掘——概念和技术(Data Mining - Concepts and Techniques)》课程教学资源(PPT课件讲稿)Chapter 01 Introduction.ppt
- 《单片机应用系统设计技术》课程教学资源(PPT课件讲稿)第7章 单片机外部扩展资源及应用.ppt
- 香港浸会大学:MPI - Communicators(PPT讲稿).ppt
- 电子工业出版社:《计算机网络》课程教学资源(第五版,PPT课件讲稿)第九章 无线网络.ppt
- 中国铁道出版社:《局域网技术与组网工程》课程教学资源(PPT课件讲稿)第2章 网络工程系统.ppt
- 自动语音识别(PPT讲稿)Automatic Speaker Recognition.pptx
- 南京大学:《编译原理》课程教学资源(PPT课件讲稿)第三章 词法分析.pptx
- 上海交通大学:人工智能的历史和启示——人机对弈作为案例.ppt
- 《计算机网络》课程教学资源(PPT课件讲稿)第三章 局域网与校园网设计(网络方案设计).ppt
- 广西外国语学院:《计算机网络》课程教学资源(PPT课件讲稿)第10章 应用层协议.ppt
- 《单片机原理及应用》课程教学资源_本科教学大纲汇编(电子信息工程专业).doc
- 上海交通大学:网络安全 Network Security(PPT讲稿,朱浩瑾).pptx
- 清华大学:Top-k String Similarity Search with Edit-Distance Constraints.pptx
- 普林斯顿大学:平衡查找树(PPT讲稿)New Balanced Search Trees.pptx