上海交通大学:《程序设计基础》课程教学讲义(密西根学院)Lecture Notes_Start with C plusplus

上海交通大学交大密西根 ·联合学院一 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 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 main() { printf("hello, world"); }

上海交通大学交大密西根 联合学院·一 ◆ 81 UM-SJTU Joint Institute University of Michigan Shanghal Jiao Tong University Our First Program Our first #include 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

上海交通大学交大密西根 联合学院·一 ◆ 181 UM-SJTU Joint Institute University of Michigan Shanghal Jiao Tong University Composition of a Program Preprocessor those being included will be inserted into your program before #include compilation for Vg101class.lib specially #include“MsgConsoleT.h” designed for this course using namespace std; is defined for this prog. /display welcome msg * ● using namespace std /necessary int main (void) Enclosed in /*..*are comments Main function:every console program will have one and only one main function Start of the function body Body of the main function )end of the function body
Composition of a Program Composition of a Program #include #include “MsgConsoleT.h” using namespace std; /* display welcome msg */ int main (void) { …. } • Preprocessor : those being included will be inserted into your program before compilation • for Vg101class.lib specially designed for this course • is defined for this prog. • using namespace std // necessary • Enclosed in /* … */ are comments • Main function: every console program will have one and only one main function • ‘{‘ Start of the function body • Body of the main function • ‘}’ end of the function body

上海交通大学交大密西根 联合学院·一 ◆ ■ 181 UM-SJTU Joint Institute University of Michigan Shanghal Jiao Tong University Composition of a Function int main (void) main function declaration ‘'Function body start MsgConsoleT console; Variable declaration;here an object called console is declared to be of class MsgConsoleT console.printLine Method function printLine of ("welcome to the Vg101 class ConsoleT is called. class"); return 0; Return statement End of the function body
Composition of a Function Composition of a Function int main (void) { MsgConsoleT console; console.printLine ("welcome to the Vg101 class“); return 0; } • main function declaration • ‘{’ Function body start • Variable declaration; here an object called console is declared to be of class MsgConsoleT • Method function printLine () of class ConsoleT is called . • Return statement • ‘}’ End of the function body

上海交通大学交大密西根 联合学院 ■ UM-SJTU Joint Institute University of Michigan Shanghal Jiao Tong University A few More Details To use the member date and function defined in another class,you could declare that class to be the base class of your class using syntax like class :public In your later homework,your might need to define a particular class for the task you are required to accomplish.For the purpose of automatic program grading,you will be given some function like disp (so that you can focuses on algorithm design instead of the output format
A few More Details A few More Details • To use the member date and function defined in another class, you could declare that class to be the base class of your class using syntax like class : public • In your later homework, your might need to define a particular class for the task you are required to accomplish. For the purpose of automatic program grading, you will be given some function like disp () so that you can focuses on algorithm design instead of the output format

上海交通大学交大密西根 联合学院· 81 UM-SJTU Joint Institute University of Michigan Shanghal Jiao Tong University About ConsoleT If your class will be run in a console environment (text based window),your class should have a base class called ConsoleT defined by the class. There are a few usefule functions defined in ConsoleT like printLine O and readInt O as you will see in the later examples.You can use it to print multiple items as the“cout”used in your textbook. There is a count part of the printLine called readLine,which is equivalent to“cin
About ConsoleT ConsoleT • If your class will be run in a console environment (text based window), your class should have a base class called ConsoleT defined by the class. • There are a few usefule functions defined in ConsoleT like printLine () and readInt () as you will see in the later examples. You can use it to print multiple items as the “cout” used in your textbook. • There is a count part of the printLine () called readLine (), which is equivalent to “cin

functions defined in ConsoleT int readInt (string msg); double readDouble (string msg); string readString (string msg); void runTimeError (string msg); void printLine(.…); void readLine (...) ● To use method functions defined in ConsoleT,you first define an object which is an instance of ConsoleT
functions defined in functions defined in ConsoleT ConsoleT int readInt (string msg); double readDouble (string msg); string readString (string msg); void runTimeError (string msg); void printLine (…); void readLine (…); • To use method functions defined in ConsoleT, you first define an object which is an instance of ConsoleT ConsoleT console ;
按次数下载不扣除下载券;
注册用户24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
- 上海交通大学:《程序设计基础》课程教学讲义(密西根学院)Lecture Notes_Random Number_Graphics.pdf
- 上海交通大学:《程序设计基础》课程教学讲义(密西根学院)Lecture Notes_programming style guide for C plusplus.pdf
- 上海交通大学:《程序设计基础》课程教学讲义(密西根学院)Lecture Notes_objects and classes.pdf
- 上海交通大学:《程序设计基础》课程教学讲义(密西根学院)Lecture Notes_Introduction to Vg101.pdf
- 上海交通大学:《程序设计基础》课程教学讲义(密西根学院)Lecture Notes_Introduction to Computer and Programming.pdf
- 上海交通大学:《程序设计基础》课程教学讲义(密西根学院)Lecture Notes_Function.pdf
- 上海交通大学:《程序设计基础》课程教学讲义(密西根学院)Lecture Notes_files_DataBase Design.pdf
- 上海交通大学:《程序设计基础》课程教学讲义(密西根学院)Lecture Notes_Expressions and Statements.pdf
- 上海交通大学:《程序设计基础》课程教学讲义(密西根学院)Lecture Notes_examples on class design.pdf
- 上海交通大学:《程序设计基础》课程教学讲义(密西根学院)Lecture Notes_Array and its Applications.pdf
- 上海交通大学:《程序设计基础》课程教学讲义(密西根学院)Lecture Notes_20 Looking Ahead.pdf
- 上海交通大学:《程序设计基础》课程教学讲义(密西根学院)Lecture Notes_19 Recursion 1.pdf
- 上海交通大学:《程序设计基础》课程教学讲义(密西根学院)Lecture Notes_16 MATLAB environment short.pdf
- 上海交通大学:《程序设计基础》课程教学讲义(密西根学院)Lecture Notes_15 Introduction to matlab.pdf
- 上海交通大学:《数据库系统原理 The principle of Database System》教学资源_Chapter 1 Introduction.pdf
- 上海交通大学:《数据库系统原理 The principle of Database System》教学资源_第二章习题与答案(第三版).doc
- 上海交通大学:《数据库系统原理 The principle of Database System》教学资源_第三章习题与答案(第三版).doc
- 上海交通大学:《数据库系统原理 The principle of Database System》课程教学资源(课件讲稿)chapter8 Views, Indexes.pdf
- 上海交通大学:《数据库系统原理 The principle of Database System》课程教学资源(课件讲稿)Chapter7 Constraints and Triggers.pdf
- 上海交通大学:《数据库系统原理 The principle of Database System》课程教学资源(课件讲稿)Chapter6 The database Language SQL –as a tutorial.pdf
- 上海交通大学:《程序设计基础》课程教学讲义(密西根学院)Lecture Notes_vector_string.pdf
- 上海交通大学:《程序设计基础》课程教学讲义(密西根学院)Recitation Notes_Recitation 1.ppt
- 上海交通大学:《程序设计基础》课程教学讲义(密西根学院)Recitation Notes_recitation 13.pdf
- 上海交通大学:《程序设计基础》课程教学讲义(密西根学院)Recitation Notes_Recitation IX.ppt
- 上海交通大学:《程序设计基础》课程教学讲义(密西根学院)Recitation Notes_Recitation V.ppt
- 上海交通大学:《程序设计基础》课程教学讲义(密西根学院)Recitation Notes_Recitation VII.ppt
- 上海交通大学:《程序设计基础》课程教学讲义(密西根学院)Recitation Notes_Recitation VIII.ppt
- 上海交通大学:《程序设计基础》课程教学讲义(密西根学院)Recitation Notes_Recitation X.ppt
- 上海交通大学:《微机原理与接口技术》课程教学资源(课件讲稿)第十四章 MCS-51单片机(1/2).pdf
- 上海交通大学:《微机原理与接口技术》课程教学资源(课件讲稿)第十四章 MCS-51单片机(2/2).pdf
- 上海交通大学:《微机原理与接口技术》课程教学资源(课件讲稿)第一章 微机原理与接口技术绪论(朱兰娟).pdf
- 上海交通大学:《微机原理与接口技术》课程教学资源(课件讲稿)第二章 8086系统结构.pdf
- 上海交通大学:《数据库系统原理 The principle of Database System》课程教学资源(课件讲稿)chapter9 SQL in a server environment.pdf
- 上海交通大学:《程序设计基础》课程教学资源(习题集)05年期末习题_Pointer Review Solution.pdf
- 上海交通大学:《程序设计基础》课程教学资源(习题集)05年期末习题_Pointer Review.pdf
- 上海交通大学:《程序设计基础》课程教学资源(习题集)05年期末习题_Practice Final 1.pdf
- 上海交通大学:《程序设计基础》课程教学资源(习题集)05年期末习题_practice Final 2.pdf
- 上海交通大学:《程序设计基础》课程教学资源(习题集)05年期末习题_practice Final 3.pdf
- 上海交通大学:《程序设计基础》课程教学资源(习题集)05年期末习题_Solution for Practice Final 1.pdf
- 上海交通大学:《程序设计基础》课程教学资源(习题集)05年期末习题_Solution for Practice Final 2.pdf