Exercise 6-1
已给程序:
• statistics.h
• my_pointerFun.h
需要完成并提交的程序:
• statistics.c
• my_pointerFun.c
• my_pointerFun.h
• main.c
•
1. 完成函数my_pointerFun(顾名思义,指针函数),该函数需有两个整型参数(x and y )且没有返回值. 要求完成的功能在my_pointerFun.h有详细描述。注意在文件头需进行正确的函数声明。
2.按照statistics.h 中的要求完成statistics.c文件
3. 写出测试程序main.c以测试你的程序是否正确。
注意:
• my_pointerFun部分占成绩的20%,main 部分占%10, statistics 部分占70%。
• 这里考察的是将指针作为函数参数问题。
• my_pointerFun.h
#ifndef _POINTERFUN_H
#define _POINTERFUN_H
/** Set values by pointers
If param x and y point to the same variable, output value 1 + 2 to it, otherwise:
param x pass-by-pointer: output value 1
param y pass-by-pointer: output value 2
**/
//注意此处的output并不是输出到屏幕上, 而是对函数而言,函数通过形参可以进行输入, 也可以通过形参返回值(输出)
void my_pointerFun( double* x, double* y);
#endif
• statistics.h
#ifndef C_STATISTICS_H
#define C_STATISTICS_H
#include
/** Read doubles from stdin and calculate statistics of them.
Reading terminates after enough values have been read or when reading a value fails.
If no values are read, nothing is returned via min/max.
param count pass-by-pointer: input max amount of values to read, output actual count of values read, cannot be NULL
param min pass-by-pointer: input none, output min value, nothing if NULL
param max pass-by-pointer: input none, output max value, nothing if NULL
param sum pass-by-pointer: input old sum, output updated sum, nothing if NULL
return the last value read successfully (0.0 if no values were read)
**/
double statistics(size_t* count, double* min, double* max, double* sum);
#endif