PROGRAMMING METHODOLOGY AND SOFTWARE ENGINEERING

EE31331 PROGRAMMING METHODOLOGY AND SOFTWARE ENGINEERING PROGRAMMINGMETHDOLODGY AND SOFTWAREENGINEERING 港城市大 Copyrighto1998 Angus Wu
PROGRAMMING METHDOLODGY AND SOFTWARE ENGINEERING Copyright©1998 Angus Wu EE 31331 PROGRAMMING METHODOLOGY AND SOFTWARE ENGINEERING

Array PROGRAMMINGMETHDOLODGY AND SOFTWAREENGINEERING 港城市大 Copyrighto1998 Angus Wu
PROGRAMMING METHDOLODGY AND SOFTWARE ENGINEERING Copyright©1998 Angus Wu Array

Array Array and pointers are intertwined int t[100] t is defined as the address of the zeroth element t is equivalent to &t[o] regardless of what datatype declaration of t is t is a pointer to its element &t[o] t+1 points to &t[1] .. tti points to &tO in other words, t+iis the address of to (tt) is equⅳ alent to t[] PROGRAM MINGMETHDOLODGY AND SOFTWAREENGINEERING 港城市大 Copyrighto1998 Angus Wu
PROGRAMMING METHDOLODGY AND SOFTWARE ENGINEERING Copyright©1998 Angus Wu Array Array and pointers are intertwined int t [100]; t is defined as the address of the zeroth element. t is equivalent to &t[0]. regardless of what datatype declaration of t is, t is a pointer to its element &t[0]. t +1 points to &t[1]….t+i points to &t[i] in other words, t + i is the address of t[i] *(t+i) is equivalent to t[i]

/ Compute average and print interesting counts. Uses table fill -reads in table entries (same table fill as before table avg cnts -compute average statistics. * Include i define MAXVALS 100 int main o t int table fill(int a[] int max)i void table avg cnts(int a[l, int n, double avg) double table average(int a[l, int n)i Ln in t七 t [MAXVALS]; table fill(t, MAXVALS) double avg table average(t, n)i printf("There are %i values. \n", n) printf("The average is g.\n", avg)i table avg cnts(t, n, avg)i return 0 PROGRAM MINGMETHDOLODGY AND SOFTWAREENGINEERING 港城市大 Copyrighto1998 Angus Wu ol Hone Kone
PROGRAMMING METHDOLODGY AND SOFTWARE ENGINEERING Copyright©1998 Angus Wu /* Compute average and print interesting counts. Uses: * table_fill - reads in table entries (same table_fill as before). * table_avg_cnts - compute average statistics. */ #include #define MAXVALS 100 int main() { int table_fill(int a[], int max); void table_avg_cnts(int a[], int n, double avg); double table_average(int a[], int n); int t[MAXVALS]; int n = table_fill(t, MAXVALS); double avg = table_average(t, n); printf("There are %i values.\n", n); printf("The average is %g.\n", avg); table_avg_cnts(t, n, avg); return 0; }

int table fill(int all int max) fint count =0; for count max, count++) if ( scanf ("i" &a[count]!= 1) break; /*kick out on error * return count void table avg cnts(int a[], int n, double avg) int i /★ index*/ int above =0 ★ above average*/ int bel。w=0; / below average * for(立=0;主 avg) above++ else if (all]< avg) below++ printf(" There are %i values above average. \n", above) printf("There are i values below average. n below)i PROGRAM MINGMETHDOLODGY AND SOFTWAREENGINEERING 港城市大 Copyrighto1998 Angus Wu ol Hone Kone
PROGRAMMING METHDOLODGY AND SOFTWARE ENGINEERING Copyright©1998 Angus Wu int table_fill(int a[], int max) {int count = 0; for (; count avg) above++; else if (a[i] < avg) below++; printf("There are %i values above average.\n", above); printf("There are %i values below average.\n", below); }

/*Compute average of an array, array subscripting version. * double table average (int a[], int n double sum =0.0;/* running total in七 / count of items * for(主=0;i<n;i++) sum + a[ili return (n ! 0)? sum /n: 0.0; /* Compute average of an array, pointer version. * double table average(int a[], int n) double sum =0.0;/* running total in七 1; / count of items * in七 ptri /* traversing pointer * ptr for(主=0;i<n;i++) I sum + *ptri ptr++i return (n ! 0)? sum /n: 0.0; PROGRAM MINGMETHDOLODGY AND SOFTWAREENGINEERING 港城市大 Copyrighto1998 Angus Wu ol Hone Kone
PROGRAMMING METHDOLODGY AND SOFTWARE ENGINEERING Copyright©1998 Angus Wu /*Compute average of an array, array subscripting version.*/ double table_average(int a[], int n) { double sum = 0.0; /* running total */ int i; /* count of items */ for (i = 0; i < n; i++) sum += a[i]; return (n != 0) ? sum / n : 0.0; } /* Compute average of an array, pointer version. */ double table_average(int a[], int n) { double sum = 0.0; /* running total */ int i; /* count of items */ int *ptr; /* traversing pointer */ ptr = a; for (i = 0; i < n; i++) { sum += *ptr; ptr++; } return (n != 0) ? sum / n : 0.0; }

Pointer Arithmetic the only legal; arithmetic operators on pointers are adding and subtracting an integer, or subtracting one pointer from another p is &t[o], q is &t[3], then g-p is 3 how to find t[n/2 suppose, minptr points to the array' s first element maxptr points to the array s last element ((minptr+maxptr )/2)is illegal as adding to pointer is not allowed how about (minptr+(maxptr-minptr)/2) as(maxptr-minptr)/2 is an integer PROGRAM MINGMETHDOLODGY AND SOFTWAREENGINEERING 港城市大 Copyrighto1998 Angus Wu
PROGRAMMING METHDOLODGY AND SOFTWARE ENGINEERING Copyright©1998 Angus Wu Pointer Arithmetic • the only legal; arithmetic operators on pointers are adding and subtracting an integer, or subtracting one pointer from another p is &t[0], q is &t[3], then q-p is 3 how to find t[n/2] suppose, minptr points to the array’s first element maxptr points to the array’s last element *((minptr+maxptr)/2) is illegal as adding to pointer is not allowed. how about *(minptr + (maxptr-minptr)/2) as (maxptr-minptr)/2 is an integer

Pointer Comparison pointers can be compared with the logical operators p is &tU], q is &t[k], if j<k, then p<q Don't compare pointers that don't access the same array PROGRAMMINGMETHDOLODGY AND SOFTWAREENGINEERING 港城市大 Copyrighto1998 Angus Wu
PROGRAMMING METHDOLODGY AND SOFTWARE ENGINEERING Copyright©1998 Angus Wu Pointer Comparison • pointers can be compared with the logical operators (==, !=, , >=) p is &t[j], q is &t[k], if j < k, then p < q • Don’t compare pointers that don’t access the same array

/ Compute average of an array concise pointer version. * double table average(int a[], int n) double sum =0.0; /* running total * int ptri /* traversing pointer * int *endptr a n; / pointer to just past end * for (ptr ai ptr endptri ptr++) sum + *ptri return (n 0)? sum/n: 0.0 int *endptr atn it does not mean endptr +n; but endptr a+n 七 endptr a+ n; it assign a n to endptr PROGRAM MINGMETHDOLODGY AND SOFTWAREENGINEERING 港城市大 Copyrighto1998 Angus Wu ol Hone Kone
PROGRAMMING METHDOLODGY AND SOFTWARE ENGINEERING Copyright©1998 Angus Wu /* Compute average of an array, concise pointer version.*/ double table_average(int a[], int n) { double sum = 0.0; /* running total */ int *ptr; /* traversing pointer */ int *endptr = a + n; /* pointer to just past end */ for (ptr = a; ptr < endptr; ptr++) sum += *ptr; return (n != 0) ? sum / n : 0.0; } int *endptr = a + n; it does not mean *endptr = a + n; but endptr = a + n; int *endptr = a + n; it assign a + n to endptr

ptr +t Example while(ptr endptr) sum+=ptr++ /*it means obtaining the value of the pointer ptr points to and add to sum, then increment the pointer ptr by one it is equivalentto sum+=ptr ptr++, PROGRAMMINGMETHDOLODGY AND SOFTWAREENGINEERING 港城市大 Copyrighto1998 Angus Wu
PROGRAMMING METHDOLODGY AND SOFTWARE ENGINEERING Copyright©1998 Angus Wu *ptr ++ Example while (ptr < endptr) sum += *ptr++; /* it means obtaining the value of the pointer ptr points to and add to sum, then increment the pointer ptr by one. */ it is equivalent to sum += *ptr; ptr++;
按次数下载不扣除下载券;
注册用户24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
- 南京大学:移动Agent系统支撑(PPT讲稿)Mobile Agent Communication——Software Agent.pptx
- 《计算机组成原理》课程教学资源(PPT课件讲稿)第三章 CPU子系统.ppt
- 长春工业大学:《Javascript 程序设计》课程教学资源(PPT课件讲稿)第8章 网页特效 JavaScript.ppt
- 江苏海洋大学(淮海工学院):《Java面向对象程序设计》课程教学资源(PPT课件讲稿)全国二级Java考试的重点难点.pptx
- 交互式数据语言(PPT讲稿)Basic IDL knowledge.ppt
- 电子科技大学:《计算机操作系统》课程教学资源(PPT课件讲稿)第二章 进程与调度(Processes and Scheduling).ppt
- 北京航空航天大学:《数据挖掘——概念和技术(Data Mining - Concepts and Techniques)》课程教学资源(PPT课件讲稿)Chapter 05 Mining Frequent Patterns, Association and Correlations.ppt
- 计算机算法(PPT讲稿)禁忌搜索算法 Tabu Search.ppt
- 2019年《计算机网络》考试大纲.doc
- 四川大学:《数据结构》课程教学资源(PPT课件讲稿)第五章 树和二叉树 Tree & Binary Tree.ppt
- 佛山科学技术学院:《网络技术基础》课程教学资源(专业技能考试大纲).doc
- 《计算机操作系统》课程教学资源(PPT课件讲稿)第二章 进程描述与控制 Process Concept & Process Control.ppt
- 香港城市大学:PROGRAMMING METHODOLOGY AND SOFTWARE ENGINEERING.ppt
- 《计算机网络》课程教学资源(PPT课件讲稿)第8章 应用层.ppt
- 并行处理(PPT讲稿)Parallel Processing - Hypercubes and Their Algorithms.ppt
- 《计算机网络》课程电子教案(PPT课件讲稿)第2章 数据通信的基础知识.ppt
- 《Excel高级应用》课程教学资源:课程教学大纲.doc
- 新乡学院:《办公自动化》课程教学资源(教学大纲).pdf
- 《视频制作》课程教学资源:课程教学大纲.doc
- 上海师范大学:《R语言与统计分析》课程教学资源(PPT课件)R语言——介绍(主讲:汤银才).ppt
- 《SQL Server 2000数据库教程》教学资源(PPT课件讲稿)第11章 数据库安全性管理.ppt
- 白城师范学院:《数据库系统概论 An Introduction to Database System》课程教学资源(PPT课件讲稿)第五章 数据库完整性.pptx
- 香港城市大学:《计算机图形学》课程教学资源(PPT课件讲稿)图的算法 Graph Algorithms.ppt
- 《The C++ Programming Language》课程教学资源(PPT课件讲稿)Lecture 07 Exception Handling.ppt
- 《C语言程序设计》课程教学资源(PPT课件讲稿)第9章 用户自己建立数据类型.pptx
- 《计算机网络教程》课程PPT教学课件(第三版)第3章 网络体系结构与网络协议.ppt
- 西安交通大学:《物联网技术导论》课程教学资源(PPT课件)第一章 物联网技术概论(主讲:桂小林).ppt
- 电子科技大学:《计算机操作系统》课程教学资源(PPT课件讲稿)第二章 进程与调度 Processes and Scheduling.ppt
- 《Web网站设计与开发》课程教学资源(PPT课件讲稿)第10章 Java Web实用开发技术.ppt
- 可信计算 Trusted Computing(PPT讲稿)TSS - TCG Software Stack.ppt
- 西安电子科技大学:《现代密码学》课程教学资源(PPT课件讲稿)第一章 绪论(主讲:董庆宽).pptx
- 《VB程序设计》课程教学资源(PPT课件讲稿)第二章 VB语言基础.ppt
- 《计算机网络》课程教学大纲 Computer Networks.pdf
- 《Photoshop教程》教学资源(PPT课件)第6章 Photoshop的绘图工具.ppt
- 《高级语言程序设计》课程教学资源(试卷习题)试题二(无答案).doc
- 机械工业出版社:国家“十一五”规划教材《数据库原理与应用教程》教学资源(PPT课件,第3版)第4章 数据操作.ppt
- 厦门大学:Web技术(PPT课件讲稿)网站快速开发 & Web前端技术.ppt
- 《面向对象技术》课程教学大纲 Technology of Object-Oriented Programming.doc
- 《算法分析与设计》课程教学资源(PPT课件讲稿)第六章 基本检索与周游方法(一般方法).ppt
- 南京大学:《面向对象技术 OOT》课程教学资源(PPT课件讲稿)设计模式 Design Patterns(1).ppt