演示文稿课件精华版

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
Tokens are usually separated by "white space." White space can be one or more blanks, horizontal or vertical tabs, new lines, form feeds or comments.
Boolean type
bool 1byte
Character types
char 1byte
Integer types
int
2-4bytes(2) [-32768~32767]
short (2)& long(4)[-2147483648~2147483647]
Floating-point types
if return
while ,ETC.
9
Commenting
/********************************************* *name of program *information of author *function of program ********************************************* */ //a sample int main() { // /*this is in the comment
8
C++ Keywords
auto short break long typedef static
const struct break switch char union
double float
int
unsigned unsigned
continue else
for
void
case sizeof
do
double 8bytes
float
4bytes
1 byte (8 bits)
char bool
2 bytes (16 bits)
short
4 bytes (32 bits)
int float
8 bytes (64 bits)
long double
16 bytes (128 bits)
long double
cout<<“Hello, Tom!”;
<statements>
return 0;
}
int x=5;
int y=8;
int z=x+y;
cout<<x<<“+”<<y<<“=“<<z<<endl;
5
//2.1.cpp
#include <iostream> using namespace std;
/** * A simple program for demonstrating the basics of a C++ project. * * It does a good job of demonstrating C++ fundamentals, but a * terrible job with the poetry. */
Pseudo Code
A first idea:
int main() {
variables while (condition) {
analyze the expression evaluate the expression print the result } }
4
main Function
int main(void) {
(优选)课件Βιβλιοθήκη Baidu华版
How to write a program
Find the whole steps in the real model Use some graph or nature language
to describe Realize with computer language
workflow
this is also in the comment */ …. }
10
Constants
1,2,3 1.2, 4.50 “name”, “your_phonenumber” ture,false 0x12 ‘1’,’A’,’$’,’\xhh’,’\ddd’
#define PI 3.141592 #define PRICE 100 const int pi= 3.141592;
7
C++ Tokens
A token is the smallest element of a C++ program that is meaningful to the compiler.
Kinds of tokens: identifiers, keywords, literals, operators, punctuators, and other separators.
11
//2.2.cpp
#include <iostream> using namespace std;
int main() { int x; int y;
x = 3; y = 4;
cout << x+y << endl;
return 0; }
12
Variables Types
Built-in types
13
Variables Literals
Boolean literals: true, false
bool t;
Character literals: char c; 'a', 'x', '4', '\n', '$‘
Integer literals:
int main() { cout << "Don’t you just feel like a louse"; cout << endl;
cout << "To learn that your \"new\" theorem was proved by Gauss?"; cout << endl;
return 0; }
6
cout
cout << expressions
cout<< “hello, world!”; cout<< 5; cout << x; cout << x+5; cout << x<<“+5=”<<x+5;
”\n”, “\t”, “ “, endl ,setw(n) setw(n): #include <iomanip.h>
相关文档
最新文档