上海交通大学交大密西根 ·联合学院一 181 UM-SJTU Joint Institute ■ University of Michigan Shanghal Jiao Tong University Vg101:Introduction to Computer and Programming Data Types and Expressions The McGraw-Hill Companies,Inc.,2000
Vg101:Introduction to Vg101:Introduction to Computer and Programming Computer and Programming Data Types and Expressions © The McGraw-Hill Companies, Inc., 2000
Objectives To write C++programs to perform simple calculations (2.2). To read input from the keyboard using the cin object($2.3). To simplify programming by omitting the std::prefix (2.4). To use identifiers to name variables,constants,functions,and classes (2.5). To use variables to store data(§§2.6-2.7). To program with assignment statements and assignment expressions (2.7) To use constants to store permanent data($2.8). To declare variables using numeric data types($2.9). To use operators to write numeric expressions (2.9). To convert numbers to a different type using casting (2.10). To represent character using the char type (2.11). To become familiar with C++documentation,programming style,and naming conventions(§2.l3). To distinguish syntax errors,runtime errors,and logic errors($2.14) 。 To debug logic errors (2.15)
Objectives Objectives • To write C++ programs to perform simple calculations (§2.2). • To read input from the keyboard using the cin object (§2.3). • To simplify programming by omitting the std:: prefix (§2.4). • To use identifiers to name variables, constants, functions, and classes (§2.5). • To use variables to store data (§§2.6-2.7). • To program with assignment statements and assignment expressions (§2.7). • To use constants to store permanent data (§2.8). • To declare variables using numeric data types (§2.9). • To use operators to write numeric expressions (§2.9). • To convert numbers to a different type using casting (§2.10). • To represent character using the char type (§2.11). • To become familiar with C++ documentation, programming style, and naming conventions (§2.13). • To distinguish syntax errors, runtime errors, and logic errors (§2.14). • To debug logic errors (§2.15)
上海交通大学交大密西根 联合学院·一 ◆ 18 UM-SJTU Joint Institute University of Michigan Shanghal Jiao Tong University Parts of a Program Comments Preprocessor Commands Words:Keywords and other common concepts Declarations (classes objects,constants, variables,and functions) Statements (simple assignments,compound, loop,conditional,and branching statements)
Parts of a Program Parts of a Program • Comments • Preprocessor Commands • Words: Keywords and other common concepts • Declarations (classes & objects, constants, variables, and functions) • Statements (simple assignments, compound, loop, conditional, and branching statements)
The "Hello World"Program One of the important 1.1 Getting Started influences on the design of The only way to learn a new C++was the C,which was programming language is to write programs in it.The first program developed at Bell Labs in the to write is the same for all early 1970s.The primary languages: reference manual for C was Print the words written by Brian Kernighan hello,world and Dennis Ritchie. This is the big hurdle;to leap over it you have to be able to create the On the first page of their program text somewhere,compile book,the authors suggest that it,load it,run it,and find out where your output went.With the first step in learning any these mechanical details language is to write a simple mastered,everything else is program that prints the comparatively easy.In C,the program to print "hello,world"is message“hello,.world”on the #include <stdio.h> display.That advice remains main(){ sound today. printf("hello,world");
The “Hello World Hello World ” Program Program • One of the important influences on the design of C++ was the C, which was developed at Bell Labs in the early 1970s. The primary reference manual for C was written by Brian Kernighan and Dennis Ritchie. • On the first page of their book, the authors suggest that the first step in learning any language is to write a simple program that prints the message “hello, world” on the display. That advice remains sound today. 1.1 Getting Started The only way to learn a new programming language is to write programs in it. The first program to write is the same for all languages: Print the words hello, world This is the big hurdle; to leap over it you have to be able to create the program text somewhere, compile it, load it, run it, and find out where your output went. With these mechanical details mastered, everything else is comparatively easy. In C, the program to print “hello, world” is #include <stdio.h> main() { printf("hello, world"); }
上海交通大学交大密西根 联合学院·一 ◆ 81 UM-SJTU Joint Institute University of Michigan Shanghal Jiao Tong University Our First Program Our first #include <vg101class.h> C++ #include "MsgConsoleT.h" using namespace std; program will This is the first C++program It will display a welcome message for you displays a message int main (void) “Welcome to 9 the Vg101class' MsgConsoleT consolej on the console.printLine (Welsome to the Vg101 class!n) console. return 0;
Our First Program Our First Program • Our first C++ program will displays a message “Welcome to the Vg101class ” on the console