函数、作用域2

来源:互联网 发布:mac邮箱 imap无法连接 编辑:程序博客网 时间:2024/06/12 02:53

使用多文件结构编写并调试程序,计算y=(5!+7!)/8! 和s=1!+2!+3!....+10! 的值

要求:     ①把求阶乘的函数存放在文件file1.cpp中;     ②把求 y=(5!+7!)/8! 的函数存放在文件file2.cpp中;     ③求s=1!+2!+3!....+10! 的函数存放在文件file3.cpp中;     ④函数原型在头文件headf.h中声明;     ⑤主函数存放在文件mainf.cpp中。

//head.h

double file1(double);double file2(double,double,double);long double file3(double);

//file1.cpp

#include"headf.h"double file1(double n1){int n;if(n1==0||n1==1)n=1;else  n=n1*file1(n1-1);return n;}

//file2.cpp

#include"headf.h"double file2(double a,double b,double c){double y;y=(file1(a)+file1(b))/file1(c);return y;}

//file3.cpp


#include"headf.h"long double file3(double n){int sum=0;for(n;n!=0;n--)sum=sum+file1(n);return sum;}

//mainf.cpp

#include<iostream>#include"headf.h"using namespace std;int main(){double y,s;y=file2(5,7,8);s=file3(10);cout<<"y=(5!+7!)/8!="<<y<<endl;cout<<"s=1!+2!+......+10!="<<s<<endl;return 0;}



0 0
原创粉丝点击