实验二 模块化程序设计
更新时间:2024-05-30 14:02:01 阅读量: 综合文库 文档下载
- 实验二小推荐度:
- 相关推荐
实验二 模块化程序设计 实验目的
(1) 体验结构化程序设计方法要点,理解模块化设计的思想,划分子模块的原则 (2) 掌握is函数的定义和调用
实验内容
任务一 输出m-n之间所有的素数(ex02_06.cpp)
改写( sample02_07.cpp )保存为ex02_06.cpp:输出m-n之间所有的素数,调用int isprime(int n)函数,每行输出10个素数。 sample02_07.cpp
/*求100以内的全部素数,每行输出10个。素数就是只能被1和自身整除的正整数,1不是素数,2是素数。*/
/* 使用嵌套循环求100以内的全部素数 */ #include
int count, i, m, n;
count = 0; /* count记录素数的个数,用于控制输出格式 */ for(m = 2; m <= 100; m++){ n = sqrt(m);
for(i = 2; i <= n; i++)
if(m % i == 0) break; if(i > n){ /* 如果m是素数 */ printf(\ /* 输出m */
count++; /* 累加已经输出的素数个数 */ if(count % 10 == 0) /* 如果count是10的倍数,换行 */ printf(\ } }
printf(\
return 0; }
学号: 姓名: 专业班级:( )( )班
1.源程序清单:ex02_06.cpp 3。实现算法(自然语言描述)
2.运行结果
学号:
姓名:
专业班级:(( )班
)任务二 打印表格ex02_07.cpp
改写ex02_03.cpp,保存为ex02_07.cpp
(1)增加函数void PrtLine(int bottom,int height),已知底长和高,输出一行表格数据。 (2)增加函数void PrtBody(void) 打印表格除表头和标题以外的主体内容部分,调用PrtLine实现。
(3)在main函数中输出表头和标题,调用PrtBody打印表格主体。 ex02_03.cpp
#include
{int bottom,height;
int CSarea; // 横截面积 double inertia; //惯性力矩 double modulus; //截面系数
printf(\ 木材工程特性表 printf(\木材尺寸 横截面积 惯性力矩 截面系数 \\n\ for(bottom=2;bottom<=10;bottom+=2) for(height=2;height<=12;height+=2) {CSarea=bottom*height;
inertia=(double)(bottom*height*height*height)/12; modulus=(double)(bottom*height*height)/6; printf(\ ? .2f %8.2f \\n\ bottom,height,CSarea,inertia,modulus); } }
1.源程序清单:ex02_07.cpp
2.运行结果截图
学号: 姓名: 专业班级:(
\\n\)( )班
任务三 改错 求PI值error02_02.cpp
打开程序文件error02_02.cpp改正程序中的错误。根据下式求PI值,直到某一项小于10-6 PI/2=1+1!/3 +2!/(3*5)+…… +n!/(3*5*…*(2n+1)) 正确运行结果 PI=3.14159
error02_02.cpp #include
printf(\ return 0; } int fact(int n) { int i;
学号: 姓名:
double res; res = 1; for(i = 0; i <= n; i++) res = res * i; return res; /* 调试时设置断点 */ } int multi(int n) { int i; double res;
res = 1; for(i = 3; i <= n; i = i+2) res = res * i; return res; /* 调试时设置断点 */ } 专业班级:( )( )班
任务四 天气统计 ex02_13.cpp
编写一个程序处理一组日最高气温。程序需要统计并打印出高温天数(最高温度为华氏85或更高),舒适天数(最高温度为华氏60~85),以及寒冷天数(最高温度小于华氏60),最后显示平均温度。从records.txt文件中读取最高气温数据进行分类统计。 测试数据如下:
55 62 68 74 59 45 41 58 60 67 65 78 82 88 91 92 90 93 87 80 78 79 72 68 61 59 源程序清单:
实验体会
实验过程评价:碰到什么问题?如何解决?
#include
void PrtLine(int bottom,int height); void main() {
printf(\ 木材工程特性表 printf(\木材尺寸 横截面积 惯性力矩 截面系数 \\n\PrtBody(); }
void PrtBody(void) {
int bottom,height; for(bottom=2;bottom<=10;bottom+=2) for(height=2;height<=12;height+=2) {
PrtLine(bottom,height); } }
void PrtLine(int bottom,int height) {
double inertia; //惯性力矩 double modulus; //截面系数
学号: 姓名: 专业班级:(
\\n\)( )班
int CSarea;// 横截面积 CSarea=bottom*height;
inertia=(double)(bottom*height*height*height)/12; modulus=(double)(bottom*height*height)/6; printf(\ ? .2f %8.2f \\n\ }
#include
int count, i, m, n;
count = 0; /* count记录素数的个数,用于控制输出格式 */ for(m = 2; m <= 100; m++){ if (isprime(m)) { /* 如果m是素数 */
printf(\ /* 输出m */
count++; /* 累加已经输出的素数个数 */ if(count % 10 == 0) /* 如果count是10的倍数,换行 */ printf(\ } }
return 0; }
int isprime(int n) {int i,m;
/* count记录素数的个数,用于控制输出格式 */ m= sqrt(n);
for(i = 2; i<=m; i++) if(n% i == 0) break; if(i > m) /* 如果m是素数 */
return 1; /* 累加已经输出的素数个数 */ else return 0; }
学号: 姓名: 专业班级:( )( )班
int CSarea;// 横截面积 CSarea=bottom*height;
inertia=(double)(bottom*height*height*height)/12; modulus=(double)(bottom*height*height)/6; printf(\ ? .2f %8.2f \\n\ }
#include
int count, i, m, n;
count = 0; /* count记录素数的个数,用于控制输出格式 */ for(m = 2; m <= 100; m++){ if (isprime(m)) { /* 如果m是素数 */
printf(\ /* 输出m */
count++; /* 累加已经输出的素数个数 */ if(count % 10 == 0) /* 如果count是10的倍数,换行 */ printf(\ } }
return 0; }
int isprime(int n) {int i,m;
/* count记录素数的个数,用于控制输出格式 */ m= sqrt(n);
for(i = 2; i<=m; i++) if(n% i == 0) break; if(i > m) /* 如果m是素数 */
return 1; /* 累加已经输出的素数个数 */ else return 0; }
学号: 姓名: 专业班级:( )( )班
正在阅读:
实验二 模块化程序设计05-30
跳蚤市场作文800字06-29
QQ群之歌02-14
探讨土木工程造价控制管理12-17
全国计算机等级考试 二级MS Office高级应用(Excel部分:第1-1003-22
2019-2020届高考英语学业水平测试一轮复习模拟测试卷(三)(含解析)03-14
大学语文c作业06-30
公司“党旗飘扬”主题活动方案06-06
2018-2019-关于国庆作文开头-优秀word范文(3页)02-29
物业服务企业监督考核评分标准 - 图文03-17
- 多层物业服务方案
- (审判实务)习惯法与少数民族地区民间纠纷解决问题(孙 潋)
- 人教版新课标六年级下册语文全册教案
- 词语打卡
- photoshop实习报告
- 钢结构设计原理综合测试2
- 2014年期末练习题
- 高中数学中的逆向思维解题方法探讨
- 名师原创 全国通用2014-2015学年高二寒假作业 政治(一)Word版
- 北航《建筑结构检测鉴定与加固》在线作业三
- XX县卫生监督所工程建设项目可行性研究报告
- 小学四年级观察作文经典评语
- 浅谈110KV变电站电气一次设计-程泉焱(1)
- 安全员考试题库
- 国家电网公司变电运维管理规定(试行)
- 义务教育课程标准稿征求意见提纲
- 教学秘书面试技巧
- 钢结构工程施工组织设计
- 水利工程概论论文
- 09届九年级数学第四次模拟试卷
- 模块化
- 程序设计
- 实验
- 我是从大三上学期开始准备考研的
- 四川省国家税务局关于加强农产品收购发票增值税进项税额抵扣管理
- 电子商务示范企业申报
- 《民法思维—请求权基础理论体系》——读书笔记
- 中共湖南历史名人
- 教学含义
- 无机结合料配合比作业指导书(2015新版)
- 2018-2019学年苏教版数学八年级上册期末复习7及答案解
- 部编本人教版二年级语文下册《雷雨》教学设计2
- 防静电安全管理制度
- GRE作文我是如何拿到5的
- 高新技术企业如何搭建能力素质模型?
- 中继器、集线器、网桥、交换机和路由器之间的区别 - 图文
- 班会 青春畅想曲
- 新概念第一册自学导读
- 嘉贝母液缔造品牌、传递真爱
- 超星尔雅中国古代礼仪文明答案
- 2012学年第一学期上海崇明高三地理一模卷(含答案) - 图文
- 从保罗事奉生命的榜样看当代牧养的处境与策略
- 篮球理论课教案 - 图文