当前位置:高等教育资讯网  >  中国高校课件下载中心  >  大学文库  >  浏览文档

《C++程序设计》(英文版) Chapter 2 Topics

资源类别:文库,文档格式:PPT,文档页数:43,文件大小:2.11MB,团购合买
Chapter 2 Topics Syntax and Semantics Programs Composed of Several Functions s Syntax Templates Legal C++ Identifiers
点击下载完整版文档(PPT)

Programming in c++ C++ Syntax and Semantics and the Program Development Process Dale/eems/Headington

1 C++ Syntax and Semantics, and the Program Development Process

Programming in C++ Chapter 2 Topics Syntax and Semantics s Programs Composed of Several Functions Syntax Templates s Legal C++ Identifiers x Data and Data Types Assigning values to Variables s Declaring Named Constants s String Concatenation Output Statements C++ Program Comments

2 Chapter 2 Topics ❖Syntax and Semantics ❖Programs Composed of Several Functions ❖Syntax Templates ❖Legal C++ Identifiers ❖Data and Data Types ❖Assigning Values to Variables ❖Declaring Named Constants ❖String Concatenation ❖Output Statements ❖C++ Program Comments

Programming in C++ Syntax and Semantics a programming language is a set of rules, and special words used to construct a program. There are rules for both syntax (grammar) and semantics(meaning) Syntax The formal rules governing how valid instructions are written in a programming language Semantics The set of rules that determines the meaning of Instructions written in a programming language

3 Syntax and Semantics ❖A programming language is a set of rules,and special words used to construct a program.There are rules for both syntax (grammar) and semantics (meaning). ❖Syntax The formal rules governing how valid instructions are written in a programming language. ❖Semantics The set of rules that determines the meaning of instructions written in a programming language

Programming in C++ Syntax Templates Let's look at the syntax template for the C++ main function Main Function int main o Statement

4 Syntax Templates Let’s look at the syntax template for the C++ main function. Main Function int main () { Statement . . . }

Programming in C++ A C++ program is a collection of one or more functions o there must be a function called main() % execution always begins with the first statement in function main() o any other functions in your program are subprograms and are not executed until they are called

5 A C++ program is a collection of one or more functions ❖there must be a function called main( ) ❖execution always begins with the first statement in function main( ) ❖any other functions in your program are subprograms and are not executed until they are called

Programming in C+ Program With Several Functions main function square function cube function

6 Program With Several Functions main function square function cube function

Programming in C+ Program With Three Functions include int Square( int )i / declares these two int Cube( int )i // value-returning functions using namespace std int main() cout < wThe square of 27 is w < Square(27)<< endl y£ unction ca11 cout < uThe cube of 2 is 1 < Cube(27)<< endl / function call return 0 7

7 Program With Three Functions #include int Square( int ); // declares these two int Cube( int ); // value-returning functions using namespace std ; int main( ) { cout << “The square of 27 is “ << Square(27) << endl; // function call cout << “The cube of 27 is “ << Cube(27) << endl; // function call return 0; }

Programming in C++ Rest of Program int Square( int n) return n"n; int Cube( int n return n*n*n

8 Rest of Program int Square( int n ) { return n * n; } int Cube( int n ) { return n * n * n; }

Programming in C++ Output of program The square of 27 is 729 The cube of 27 is 19683

9 Output of program The square of 27 is 729 The cube of 27 is 19683

Programming in C+ Every C++ function has 2 parts int main() heading body block return o

Every C++ function has 2 parts int main ( ) heading { body block return 0; }

点击下载完整版文档(PPT)VIP每日下载上限内不扣除下载券和下载次数;
按次数下载不扣除下载券;
24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
共43页,可试读15页,点击继续阅读 ↓↓
相关文档

关于我们|帮助中心|下载说明|相关软件|意见反馈|联系我们

Copyright © 2008-现在 cucdc.com 高等教育资讯网 版权所有