资源预览内容
第1页 / 共408页
第2页 / 共408页
第3页 / 共408页
第4页 / 共408页
第5页 / 共408页
第6页 / 共408页
第7页 / 共408页
第8页 / 共408页
第9页 / 共408页
第10页 / 共408页
亲,该文档总共408页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述
第1章 基本数据与表达式,1.1 概述,1.2 C+的字符集与词汇,1.3 C+的基本数据类型与存储形式,1.4 数据对象与访问,1.5 表达式,1.6 数据输入和输出,小结,程序设计语言 人指挥计算机工作的工具,是由字、词和语法规则构成的指令系统,程序设计 根据特定的问题,使用某种程序设计语言,设计出计算机执行的指令序列主要完成两方面工作: 数据描述 (2) 数据处理,1.1.1 程序设计与程序设计语言,1.1 概述,问题:输入圆的半径,求圆的周长和面积,数据描述: 半径,周长,面积均用实型数表示 数据处理: 输入半径 r; 计算周长 = 2*r ; 计算面积 = * r2 ; 输出半径,周长,面积;,1.1.2 一个简单的C+程序,1.1 概述,例1-1 方法一,用结构化方法编程,求圆的周长和面积,/ count the girth and area of circle #include void main () double r, girth, area ; const double PI = 3.1415 ; cout r ; girth = 2 * PI * r ; area = PI * r * r ; cout “radius = “ r endl ; cout “girth = “ girth endl ; cout “area = “ area endl ; ,例1-1 方法一,用结构化方法编程,求圆的周长和面积,/ count the girth and area of circle #include void main () double r, girth, area ; const double PI = 3.1415 ; cout r ; girth = 2 * PI * r ; area = PI * r * r ; cout “radius = “ r endl ; cout “girth = “ girth endl ; cout “area = “ area endl ; ,数据描述,例1-1 方法一,用结构化方法编程,求圆的周长和面积,/ count the girth and area of circle #include void main () double r, girth, area ; const double PI = 3.1415 ; cout r ; girth = 2 * PI * r ; area = PI * r * r ; cout “radius = “ r endl ; cout “girth = “ girth endl ; cout “area = “ area endl ; ,数据处理,例1-1 方法一,用结构化方法编程,求圆的周长和面积,/ count the girth and area of circle #include void main () double r, girth, area ; const double PI = 3.1415 ; cout r ; girth = 2 * PI * r ; area = PI * r * r ; cout “radius = “ r endl ; cout “girth = “ girth endl ; cout “area = “ area endl ; ,输入数据,例1-1 方法一,用结构化方法编程,求圆的周长和面积,/ count the girth and area of circle #include void main () double r, girth, area ; const double PI = 3.1415 ; cout r ; girth = 2 * PI * r ; area = PI * r * r ; cout “radius = “ r endl ; cout “girth = “ girth endl ; cout “area = “ area endl ; ,计算周长和面积,例1-1 方法一,用结构化方法编程,求圆的周长和面积,/ count the girth and area of circle #include void main () double r, girth, area ; const double PI = 3.1415 ; cout r ; girth = 2 * PI * r ; area = PI * r * r ; cout “radius = “ r endl ; cout “girth = “ girth endl ; cout “area = “ area endl ; ,输出计算结果,例1-1 方法一,用结构化方法编程,求圆的周长和面积,/ count the girth and area of circle #include void main () double r, girth, area ; const double PI = 3.1415 ; cout r ; girth = 2 * PI * r ; area = PI * r * r ; cout “radius = “ r endl ; cout “girth = “ girth endl ; cout “area = “ area endl ; ,注释行,例1-1 方法一,用结构化方法编程,求圆的周长和面积,#include void main () double r, girth, area ; const double PI = 3.1415 ; cout r ; girth = 2 * PI * r ; area = PI * r * r ; cout “radius = “ r endl ; cout “girth = “ girth endl ; cout “area = “ area endl ; ,/ count the girth and area of circle,/ this is a simple program,注释 第一种形式: 以 ” / ” 开始至行末,例1-1 方法一,用结构化方法编程,求圆的周长和面积,#include void main () double r, girth, area ; const double PI = 3.1415 ; cout r ; girth = 2 * PI * r ; area = PI * r * r ; cout “radius = “ r endl ; cout “girth = “ girth endl ; cout “area = “ area endl ; ,/* this is a simple program count the girth and area of circle */,注释 第一种形式: 以 ” / ” 开始至行末,第二种形式: /* 字符串 */,例1-1 方法一,用结构化方法编程,求圆的周长和面积,/ count the girth and area of circle #include void main () double r, girth, area ; const double PI = 3.1415 ; cout r ; girth = 2 * PI * r ; area = PI * r * r ; cout “radius = “ r endl ; cout “girth = “ girth endl ; cout “area = “ area endl ; ,预编译指令 在程序编译之前把指定文件内容复制到此处,例1-1 方法一,用结构化方法编程,求圆的周长和面积,/ count the girth and area of circle #include void main () double r, girth, area ; const double PI = 3.1415 ; cout r ; girth = 2 * PI * r ; area = PI * r * r ; cout “radius = “ r endl ; cout “girth = “ girth endl ; cout “area = “ area endl ; ,函数头,例1-1 方法一,用结构化方法编程,求圆的周长和面积,/ count the girth and area of circle #include void main () double r, girth, area ; const double PI = 3.1415 ; cout r ; girth = 2 * PI * r ; area = PI * r * r ; cout “radius = “ r endl ; cout “girth = “ girth endl ; cout “area = “ area endl ; ,函数返回值类型 void 空类型,例1-1 方法一,用结构化方法编程,求圆的周长和面积,/ count the girth and area of circle #include void main () double r, girth, area ; const double PI = 3.1415 ; cout r ; girth = 2 * PI * r ; area = PI * r * r ; cout “radius = “ r endl ; cout “girth = “ girth endl ; cout “area = “ area endl ; ,函数名 main 主函数名,系统预定义,例1-1 方法一,用结构化方法编程,求圆的周长和面积,/ count the girth and area of circle #include void main () double r, girth, area ; const double PI = 3.1415 ; cout r ; girth = 2 * PI * r ; area = PI * r * r ; cout “radius = “ r endl ; cout “girth = “ girth endl ; cout “area = “ area endl ; ,参数表 没有参数不能省略圆括号,例1-1 方法一,用结构化方法编程,求圆的周长和面积,/ count the girth and area of circle #include void main () double r, girth, area ; const double PI = 3.1415 ; cout r ; girth = 2 * PI * r ; area = PI * r * r ; cout “radius = “ r endl ; cout “girth = “ girth endl ; cout “area = “ area endl ; ,函数体 花括号相括的语句序列 各语句以分号结束 一行可以写多个语句 一个语句可以分多行书写,例1-1 方法一,用结构化方法编程,求圆的周长和面积,/ count the girth and area of circle #include void main () double r, girth, area ; const double PI = 3.1415 ; cout r ; girth = 2 * PI * r ; area = PI * r * r ; cout “radius = “ r endl ; cout “girth = “ girth endl ; cout “area =
收藏 下载该资源
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号