高级语言C++程序设计 (第二版) 刘景、周玉龙編
高级语言C++程序设计 (第二版) 刘景、周玉龙编
第二章C++语言初步 21初识C++程序 211程序实例 个简单的C++程序(P21) //program2-1cpp #include <iostream. h> void main( void) cout < Let' s learn to write a C++ program 百钱买百鸡问题: //program2-2 cpp #indlude <iostream.h> void main( void
第二章 C++语言初步 ◼ 2.1 初识C++程序 2.1.1 程序实例 一个简单的C++程序(P.21.): //program2-1.cpp #include<iostream.h> void main(void) { cout<<“Let’s learn to write a C++ Program.”; } 百钱买百鸡问题: //program2-2.cpp #include<iostream.h> void main(void)
第二章C++语言初步 百钱买百鸡问题(P22~23): //program2-2 cpp #indlude <iostream h> void main(void) int chicken hen, cock cout <<chicken hen cock"'<<endl; for(chicken=0; chicken< 100 chicken+=3) for (hen=0, hen<=33; hen++) if(cock=100-chicken-hen)>-1) if(chicken/3+hen*3+cock*5==100) cout<<<< chicken<<“<<hen<<“<<Cock<<end;
第二章 C++语言初步 百钱买百鸡问题(P.22~23.): //program2-2.cpp #include<iostream.h> void main(void) { int chicken,hen,cock; cout<<“chicken hen cock”<<endl; for(chicken=0;chicken<100;chicken+=3) for(hen=0;hen<=33;hen++) if((cock=100-chicken-hen)>-1) if(chicken/3+hen*3+cock*5==100) cout<<“ ”<<chicken<<“ “<<hen<<“ “<<cock<<endl; }
第二章C++语言初步 212I/o语句 1、标准输出语句 插入操作:cout<<表达式 2、标准输入语句(P24) 提取操作:cin>>变量; //program2-3 cpp #include <iostream. h> void main(void〕 int myage cout< My age is: 7 cIn>>myage; cout< <endl
第二章 C++语言初步 2.1.2 I/O语句 1、标准输出语句 插入操作:cout<<表达式; 2、标准输入语句(P.24.) 提取操作:cin>>变量; //program2-3.cpp #include<iostream.h> void main(void) { int myage; cout<<“My age is:”; cin>>myage; cout<<endl; }
第二章C++语言初步 3、标准流类 # include< iostream. h>: cout, cin<<>>等。 # include< stdio h>: printf(, scanf(等。 22C++语言的基本符号 2.2.1基本符号分类 字母、数字、特殊符号。(P.26.) 222基本符号的ASCI编码 表2.1(P27.)
第二章 C++语言初步 3、标准流类 #include<iostream.h>:cout,cin,<<,>>等。 #include<stdio.h>:printf(),scanf()等。 ◼ 2.2 C++语言的基本符号 2.2.1 基本符号分类 字母、数字、特殊符号。(P.26.) 2.2.2 基本符号的ASCII编码 表2.1 (P.27.)